From aac6f58ae96faab86e6080702d2dac2bd3a69d66 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 31 Aug 2006 18:05:57 +0100 Subject: [PATCH] Rename dbus_bindings (sometimes a.k.a. dbus.dbus_bindings) to _dbus_bindings. Ditto for dbus_glib_bindings. Remove dbus.pth - should no longer be needed after this change. --- dbus/_dbus.py | 24 +++++++------- ...{dbus_bindings.pxd.in => _dbus_bindings.pxd.in} | 0 dbus/{dbus_bindings.pyx => _dbus_bindings.pyx} | 0 ...s_glib_bindings.pyx => _dbus_glib_bindings.pyx} | 8 ++--- dbus/dbus.pth | 1 - dbus/decorators.py | 35 +++++++++++++++++--- dbus/exceptions.py | 6 ++-- dbus/glib.py | 6 ++-- dbus/matchrules.py | 2 +- dbus/proxies.py | 8 ++--- dbus/service.py | 38 +++++++++++----------- dbus/types.py | 38 +++++++++++----------- setup.py | 14 ++++---- 13 files changed, 102 insertions(+), 78 deletions(-) rename dbus/{dbus_bindings.pxd.in => _dbus_bindings.pxd.in} (100%) rename dbus/{dbus_bindings.pyx => _dbus_bindings.pyx} (100%) rename dbus/{dbus_glib_bindings.pyx => _dbus_glib_bindings.pyx} (68%) delete mode 100644 dbus/dbus.pth rewrite dbus/types.py (99%) diff --git a/dbus/_dbus.py b/dbus/_dbus.py index 7b72cfb..2c3aafe 100644 --- a/dbus/_dbus.py +++ b/dbus/_dbus.py @@ -43,7 +43,7 @@ For example, the dbus-daemon itself provides a service and some objects:: __docformat__ = 'reStructuredText' import dbus -import dbus_bindings +import _dbus_bindings import weakref from proxies import * @@ -56,17 +56,17 @@ class Bus(object): One of three possible standard buses, the SESSION, SYSTEM, or STARTER bus """ - TYPE_SESSION = dbus_bindings.BUS_SESSION - TYPE_SYSTEM = dbus_bindings.BUS_SYSTEM - TYPE_STARTER = dbus_bindings.BUS_STARTER + TYPE_SESSION = _dbus_bindings.BUS_SESSION + TYPE_SYSTEM = _dbus_bindings.BUS_SYSTEM + TYPE_STARTER = _dbus_bindings.BUS_STARTER """bus_type=[Bus.TYPE_SESSION | Bus.TYPE_SYSTEM | Bus.TYPE_STARTER] """ ProxyObjectClass = ProxyObject - START_REPLY_SUCCESS = dbus_bindings.DBUS_START_REPLY_SUCCESS - START_REPLY_ALREADY_RUNNING = dbus_bindings.DBUS_START_REPLY_ALREADY_RUNNING + START_REPLY_SUCCESS = _dbus_bindings.DBUS_START_REPLY_SUCCESS + START_REPLY_ALREADY_RUNNING = _dbus_bindings.DBUS_START_REPLY_ALREADY_RUNNING _shared_instances = weakref.WeakValueDictionary() @@ -97,7 +97,7 @@ class Bus(object): # FIXME: if you get a starter and a system/session bus connection # in the same process, it's the same underlying connection that # is returned by bus_get, but we initialise it twice - bus._connection = dbus_bindings.bus_get(bus_type, private) + bus._connection = _dbus_bindings.bus_get(bus_type, private) bus._connection.add_filter(bus._signal_func) if use_default_mainloop: @@ -194,7 +194,7 @@ class Bus(object): self._match_rule_tree.add(match_rule) - dbus_bindings.bus_add_match(self._connection, repr(match_rule)) + _dbus_bindings.bus_add_match(self._connection, repr(match_rule)) def remove_signal_receiver(self, handler_function, signal_name=None, @@ -223,11 +223,11 @@ class Bus(object): def get_unix_user(self, named_service): """Get the unix user for the given named_service on this Bus""" - return dbus_bindings.bus_get_unix_user(self._connection, named_service) + return _dbus_bindings.bus_get_unix_user(self._connection, named_service) def _signal_func(self, connection, message): - if (message.get_type() != dbus_bindings.MESSAGE_TYPE_SIGNAL): - return dbus_bindings.HANDLER_RESULT_NOT_YET_HANDLED + if (message.get_type() != _dbus_bindings.MESSAGE_TYPE_SIGNAL): + return _dbus_bindings.HANDLER_RESULT_NOT_YET_HANDLED dbus_interface = message.get_interface() named_service = message.get_sender() @@ -239,7 +239,7 @@ class Bus(object): self._match_rule_tree.exec_matches(match_rule, message) def start_service_by_name(self, named_service): - return dbus_bindings.bus_start_service_by_name(self._connection, named_service) + return _dbus_bindings.bus_start_service_by_name(self._connection, named_service) def __repr__(self): if self._bus_type == self.TYPE_SESSION: diff --git a/dbus/dbus_bindings.pxd.in b/dbus/_dbus_bindings.pxd.in similarity index 100% rename from dbus/dbus_bindings.pxd.in rename to dbus/_dbus_bindings.pxd.in diff --git a/dbus/dbus_bindings.pyx b/dbus/_dbus_bindings.pyx similarity index 100% rename from dbus/dbus_bindings.pyx rename to dbus/_dbus_bindings.pyx diff --git a/dbus/dbus_glib_bindings.pyx b/dbus/_dbus_glib_bindings.pyx similarity index 68% rename from dbus/dbus_glib_bindings.pyx rename to dbus/_dbus_glib_bindings.pyx index fa86e91..3c66941 100644 --- a/dbus/dbus_glib_bindings.pyx +++ b/dbus/_dbus_glib_bindings.pyx @@ -1,15 +1,15 @@ -cimport dbus_bindings -import dbus_bindings +cimport _dbus_bindings +import _dbus_bindings cdef extern from "dbus/dbus-glib.h": ctypedef struct GMainContext cdef void dbus_g_thread_init () cdef extern from "dbus/dbus-glib-lowlevel.h": - cdef void dbus_connection_setup_with_g_main (dbus_bindings.DBusConnection *connection, + cdef void dbus_connection_setup_with_g_main (_dbus_bindings.DBusConnection *connection, GMainContext *context) def setup_with_g_main(conn): - cdef dbus_bindings.Connection connection + cdef _dbus_bindings.Connection connection connection = conn dbus_connection_setup_with_g_main(connection._get_conn(), NULL) diff --git a/dbus/dbus.pth b/dbus/dbus.pth deleted file mode 100644 index e2182f1..0000000 --- a/dbus/dbus.pth +++ /dev/null @@ -1 +0,0 @@ -dbus diff --git a/dbus/decorators.py b/dbus/decorators.py index 0949100..6dc2176 100644 --- a/dbus/decorators.py +++ b/dbus/decorators.py @@ -5,12 +5,15 @@ __docformat__ = 'restructuredtext' import _util import inspect -import dbus_bindings +import _dbus_bindings def method(dbus_interface, in_signature=None, out_signature=None, async_callbacks=None, sender_keyword=None): """Factory for decorators used to mark methods of a `dbus.service.Object` to be exported on the D-Bus. + The decorated method will be exported over D-Bus as the method of the + same name on the given D-Bus interface. + :Parameters: `dbus_interface` : str Name of a D-Bus interface @@ -65,7 +68,7 @@ def method(dbus_interface, in_signature=None, out_signature=None, async_callback args.remove(sender_keyword) if in_signature: - in_sig = tuple(dbus_bindings.Signature(in_signature)) + in_sig = tuple(_dbus_bindings.Signature(in_signature)) if len(in_sig) > len(args): raise ValueError, 'input signature is longer than the number of arguments taken' @@ -84,15 +87,28 @@ def method(dbus_interface, in_signature=None, out_signature=None, async_callback return decorator def signal(dbus_interface, signature=None): + """Factory for decorators used to mark methods of a `dbus.service.Object` + to emit signals on the D-Bus. + + Whenever the decorated method is called in Python, after the method + body is executed, a signal with the same name as the decorated method, + from the given D-Bus interface, will be emitted. + + :Parameters: + `dbus_interface` : str + The D-Bus interface whose signal is emitted + `signature` : str + The signature of the signal in the usual D-Bus notation + """ _util._validate_interface_or_name(dbus_interface) def decorator(func): def emit_signal(self, *args, **keywords): func(self, *args, **keywords) - message = dbus_bindings.Signal(self._object_path, dbus_interface, func.__name__) + message = _dbus_bindings.Signal(self._object_path, dbus_interface, func.__name__) iter = message.get_iter(True) if emit_signal._dbus_signature: - signature = tuple(dbus_bindings.Signature(emit_signal._dbus_signature)) + signature = tuple(_dbus_bindings.Signature(emit_signal._dbus_signature)) for (arg, sig) in zip(args, signature): iter.append_strict(arg, sig) else: @@ -105,7 +121,7 @@ def signal(dbus_interface, signature=None): args.pop(0) if signature: - sig = tuple(dbus_bindings.Signature(signature)) + sig = tuple(_dbus_bindings.Signature(signature)) if len(sig) > len(args): raise ValueError, 'signal signature is longer than the number of arguments provided' @@ -123,5 +139,14 @@ def signal(dbus_interface, signature=None): return decorator def explicitly_pass_message(func): + """Decorator which marks the given function such that, if it is called + as a D-Bus signal recipient, then the Signal message will be passed + to it as a keyword parameter named ``dbus_message``. + + Deprecated? Should Messages really be exposed to client code? + + FIXME: this alters the namespace of the decorated function without + using the ``__magic__`` naming convention. + """ func._dbus_pass_message = True return func diff --git a/dbus/exceptions.py b/dbus/exceptions.py index ab43ce1..60ba3fd 100644 --- a/dbus/exceptions.py +++ b/dbus/exceptions.py @@ -5,10 +5,10 @@ __all__ = ('DBusException', 'ConnectionError', 'MissingErrorHandlerException', 'IntrospectionParserException', 'UnknownMethodException', 'NameExistsException') -import dbus_bindings +import _dbus_bindings -DBusException = dbus_bindings.DBusException -ConnectionError = dbus_bindings.ConnectionError +DBusException = _dbus_bindings.DBusException +ConnectionError = _dbus_bindings.ConnectionError class MissingErrorHandlerException(DBusException): def __init__(self): diff --git a/dbus/glib.py b/dbus/glib.py index e1c3d9c..45ff93c 100644 --- a/dbus/glib.py +++ b/dbus/glib.py @@ -1,14 +1,14 @@ import dbus -import dbus_glib_bindings +import _dbus_glib_bindings def _setup_with_g_main(conn): - dbus_glib_bindings.setup_with_g_main(conn._connection) + _dbus_glib_bindings.setup_with_g_main(conn._connection) _dbus_gthreads_initialized = False def threads_init(): global _dbus_gthreads_initialized if not _dbus_gthreads_initialized: - dbus_glib_bindings.gthreads_init() + _dbus_glib_bindings.gthreads_init() _dbus_gthreads_initialized = True def init_threads(): diff --git a/dbus/matchrules.py b/dbus/matchrules.py index 023a5b7..6e05265 100644 --- a/dbus/matchrules.py +++ b/dbus/matchrules.py @@ -208,7 +208,7 @@ class SignalMatchRule: def __repr__(self): """Returns a custom representation of this DBusMatchRule that can - be used with dbus_bindings + be used with _dbus_bindings """ repr = "type='signal'" if (self.dbus_interface): diff --git a/dbus/proxies.py b/dbus/proxies.py index 80e9ac2..babbcd5 100644 --- a/dbus/proxies.py +++ b/dbus/proxies.py @@ -1,4 +1,4 @@ -import dbus_bindings +import _dbus_bindings import introspect_parser import sys from exceptions import MissingReplyHandlerException, MissingErrorHandlerException, IntrospectionParserException @@ -79,14 +79,14 @@ class ProxyMethod: if self._proxy._introspect_method_map.has_key (key): introspect_sig = self._proxy._introspect_method_map[key] - message = dbus_bindings.MethodCall(self._object_path, dbus_interface, self._method_name) + message = _dbus_bindings.MethodCall(self._object_path, dbus_interface, self._method_name) message.set_destination(self._named_service) # Add the arguments to the function iter = message.get_iter(True) if introspect_sig: - for (arg, sig) in zip(args, dbus_bindings.Signature(introspect_sig)): + for (arg, sig) in zip(args, _dbus_bindings.Signature(introspect_sig)): iter.append_strict(arg, sig) else: for arg in args: @@ -152,7 +152,7 @@ class ProxyObject: **keywords) def _Introspect(self): - message = dbus_bindings.MethodCall(self._object_path, 'org.freedesktop.DBus.Introspectable', 'Introspect') + message = _dbus_bindings.MethodCall(self._object_path, 'org.freedesktop.DBus.Introspectable', 'Introspect') message.set_destination(self._named_service) result = self._bus.get_connection().send_with_reply_handlers(message, -1, diff --git a/dbus/service.py b/dbus/service.py index f839a48..e0b784d 100644 --- a/dbus/service.py +++ b/dbus/service.py @@ -1,7 +1,7 @@ __all__ = ('BusName', 'Object', 'method', 'signal') __docformat__ = 'restructuredtext' -import dbus_bindings +import _dbus_bindings import _dbus import operator import traceback @@ -59,23 +59,23 @@ class BusName(object): # otherwise register the name name_flags = \ - dbus_bindings.NAME_FLAG_ALLOW_REPLACEMENT * allow_replacement + \ - dbus_bindings.NAME_FLAG_REPLACE_EXISTING * replace_existing + \ - dbus_bindings.NAME_FLAG_DO_NOT_QUEUE * do_not_queue + _dbus_bindings.NAME_FLAG_ALLOW_REPLACEMENT * allow_replacement + \ + _dbus_bindings.NAME_FLAG_REPLACE_EXISTING * replace_existing + \ + _dbus_bindings.NAME_FLAG_DO_NOT_QUEUE * do_not_queue - retval = dbus_bindings.bus_request_name(bus.get_connection(), name, name_flags) + retval = _dbus_bindings.bus_request_name(bus.get_connection(), name, name_flags) # TODO: more intelligent tracking of bus name states? - if retval == dbus_bindings.REQUEST_NAME_REPLY_PRIMARY_OWNER: + if retval == _dbus_bindings.REQUEST_NAME_REPLY_PRIMARY_OWNER: pass - elif retval == dbus_bindings.REQUEST_NAME_REPLY_IN_QUEUE: + elif retval == _dbus_bindings.REQUEST_NAME_REPLY_IN_QUEUE: # queueing can happen by default, maybe we should # track this better or let the user know if they're # queued or not? pass - elif retval == dbus_bindings.REQUEST_NAME_REPLY_EXISTS: + elif retval == _dbus_bindings.REQUEST_NAME_REPLY_EXISTS: raise NameExistsException(name) - elif retval == dbus_bindings.REQUEST_NAME_REPLY_ALREADY_OWNER: + elif retval == _dbus_bindings.REQUEST_NAME_REPLY_ALREADY_OWNER: # if this is a shared bus which is being used by someone # else in this process, this can happen legitimately pass @@ -101,7 +101,7 @@ class BusName(object): # we can delete the low-level name here because these objects # are guaranteed to exist only once for each bus name def __del__(self): - dbus_bindings.bus_release_name(self._bus.get_connection(), self._name) + _dbus_bindings.bus_release_name(self._bus.get_connection(), self._name) pass def get_bus(self): @@ -184,7 +184,7 @@ def _method_lookup(self, method_name, dbus_interface): def _method_reply_return(connection, message, method_name, signature, *retval): - reply = dbus_bindings.MethodReturn(message) + reply = _dbus_bindings.MethodReturn(message) iter = reply.get_iter(append=True) # do strict adding if an output signature was provided @@ -216,7 +216,7 @@ def _method_reply_error(connection, message, exception): name = 'org.freedesktop.DBus.Python.%s.%s' % (exception.__module__, exception.__class__.__name__) contents = traceback.format_exc() - reply = dbus_bindings.Error(message, name, contents) + reply = _dbus_bindings.Error(message, name, contents) connection.send(reply) @@ -255,15 +255,15 @@ class InterfaceType(type): # convert signature into a tuple so length refers to number of # types, not number of characters. the length is checked by # the decorator to make sure it matches the length of args. - in_sig = tuple(dbus_bindings.Signature(func._dbus_in_signature)) + in_sig = tuple(_dbus_bindings.Signature(func._dbus_in_signature)) else: # magic iterator which returns as many v's as we need - in_sig = dbus_bindings.VariantSignature() + in_sig = _dbus_bindings.VariantSignature() if func._dbus_out_signature: - out_sig = dbus_bindings.Signature(func._dbus_out_signature) + out_sig = _dbus_bindings.Signature(func._dbus_out_signature) else: - # its tempting to default to dbus_bindings.Signature('v'), but + # its tempting to default to _dbus_bindings.Signature('v'), but # for methods that return nothing, providing incorrect # introspection data is worse than providing none at all out_sig = [] @@ -283,10 +283,10 @@ class InterfaceType(type): if func._dbus_signature: # convert signature into a tuple so length refers to number of # types, not number of characters - sig = tuple(dbus_bindings.Signature(func._dbus_signature)) + sig = tuple(_dbus_bindings.Signature(func._dbus_signature)) else: # magic iterator which returns as many v's as we need - sig = dbus_bindings.VariantSignature() + sig = _dbus_bindings.VariantSignature() reflection_data = ' \n' % (func.__name__) for pair in zip(sig, args): @@ -346,7 +346,7 @@ class Object(Interface): # iterate signature into list of complete types if parent_method._dbus_out_signature: - signature = tuple(dbus_bindings.Signature(parent_method._dbus_out_signature)) + signature = tuple(_dbus_bindings.Signature(parent_method._dbus_out_signature)) else: signature = None diff --git a/dbus/types.py b/dbus/types.py dissimilarity index 99% index f3d348c..b876b41 100644 --- a/dbus/types.py +++ b/dbus/types.py @@ -1,19 +1,19 @@ -import dbus_bindings - -ObjectPath = dbus_bindings.ObjectPath -ByteArray = dbus_bindings.ByteArray -Signature = dbus_bindings.Signature -Byte = dbus_bindings.Byte -Boolean = dbus_bindings.Boolean -Int16 = dbus_bindings.Int16 -UInt16 = dbus_bindings.UInt16 -Int32 = dbus_bindings.Int32 -UInt32 = dbus_bindings.UInt32 -Int64 = dbus_bindings.Int64 -UInt64 = dbus_bindings.UInt64 -Double = dbus_bindings.Double -String = dbus_bindings.String -Array = dbus_bindings.Array -Struct = dbus_bindings.Struct -Dictionary = dbus_bindings.Dictionary -Variant = dbus_bindings.Variant +import _dbus_bindings + +ObjectPath = _dbus_bindings.ObjectPath +ByteArray = _dbus_bindings.ByteArray +Signature = _dbus_bindings.Signature +Byte = _dbus_bindings.Byte +Boolean = _dbus_bindings.Boolean +Int16 = _dbus_bindings.Int16 +UInt16 = _dbus_bindings.UInt16 +Int32 = _dbus_bindings.Int32 +UInt32 = _dbus_bindings.UInt32 +Int64 = _dbus_bindings.Int64 +UInt64 = _dbus_bindings.UInt64 +Double = _dbus_bindings.Double +String = _dbus_bindings.String +Array = _dbus_bindings.Array +Struct = _dbus_bindings.Struct +Dictionary = _dbus_bindings.Dictionary +Variant = _dbus_bindings.Variant diff --git a/setup.py b/setup.py index 0d0a90d..a295c6a 100644 --- a/setup.py +++ b/setup.py @@ -21,9 +21,9 @@ class full_clean(clean): def run(self): clean.run(self) remove("dbus/extract.pyo") - remove("dbus/dbus_bindings.pxd") - remove("dbus/dbus_bindings.c") - remove("dbus/dbus_glib_bindings.c") + remove("dbus/_dbus_bindings.pxd") + remove("dbus/_dbus_bindings.c") + remove("dbus/_dbus_glib_bindings.c") remove("ChangeLog") includedirs_flag = ['-I.'] @@ -102,9 +102,9 @@ if error: raise SystemExit dbus_glib_libs.extend([ x.replace("-L", "") for x in output.split() ]) -output = open("dbus/dbus_bindings.pxd", 'w') +output = open("dbus/_dbus_bindings.pxd", 'w') includedirs_flag.append('-Idbus/') -extract.main("dbus/dbus_bindings.pxd.in", includedirs_flag, output) +extract.main("dbus/_dbus_bindings.pxd.in", includedirs_flag, output) output.close() long_desc = '''D-BUS is a message bus system, a simple way for applications to @@ -143,13 +143,13 @@ setup( "dbus/_util", ], ext_modules=[ - Extension("dbus/dbus_bindings", ["dbus/dbus_bindings.pyx"], + Extension("_dbus_bindings", ["dbus/_dbus_bindings.pyx"], include_dirs=dbus_includes, library_dirs=dbus_libs, libraries=["dbus-1"], ), - Extension("dbus/dbus_glib_bindings", ["dbus/dbus_glib_bindings.pyx"], + Extension("_dbus_glib_bindings", ["dbus/_dbus_glib_bindings.pyx"], include_dirs=dbus_glib_includes, library_dirs=dbus_glib_libs, libraries=["dbus-glib-1", "dbus-1", "glib-2.0"], -- 2.11.4.GIT