def __init__(self, reply_handler=None, error_handler=None, host=None, port=None, encryption=None, parent=None): self._conn = asyncipp.IPPAuthConnection (reply_handler=reply_handler, error_handler=error_handler, host=host, port=port, encryption=encryption, parent=parent) try: self._system_bus = dbus.SystemBus() except (dbus.exceptions.DBusException, AttributeError): # No system D-Bus. self._system_bus = None global _DevicesGet_uses_new_api if _DevicesGet_uses_new_api == None and self._system_bus: try: obj = self._system_bus.get_object(CUPS_PK_NAME, CUPS_PK_PATH) proxy = dbus.Interface (obj, dbus.INTROSPECTABLE_IFACE) api = proxy.Introspect () top = xml.etree.ElementTree.XML (api) for interface in top.findall ("interface"): if interface.attrib.get ("name") != CUPS_PK_IFACE: continue for method in interface.findall ("method"): if method.attrib.get ("name") != "DevicesGet": continue num_args = 0 for arg in method.findall ("arg"): direction = arg.attrib.get ("direction") if direction != "in": continue num_args += 1 _DevicesGet_uses_new_api = num_args == 4 debugprint ("DevicesGet new API: %s" % (num_args == 4)) break break except Exception as e: debugprint ("Exception assessing DevicesGet API: %s" % repr (e)) methodtype = type (self._conn.getPrinters) bindings = [] for fname in dir (self._conn): if fname.startswith ('_'): continue fn = getattr (self._conn, fname) if type (fn) != methodtype: continue if not hasattr (self, fname): setattr (self, fname, self._make_binding (fn)) bindings.append (fname) self._bindings = bindings debugprint ("+%s" % self)
def __init__(self, reply_handler=None, error_handler=None, auth_handler=None, host=None, port=None, encryption=None, parent=None, try_as_root=True, prompt_allowed=True): super(Connection, self).__init__() self._destroyed = False # Decide whether to use direct IPP or PolicyKit. if host is None: host = cups.getServer() use_pk = ((host.startswith('/') or host == 'localhost') and os.getuid() != 0) def subst_reply_handler(conn, reply): self._subst_reply_handler(None, reply_handler, reply) def subst_error_handler(conn, exc): self._subst_error_handler(None, error_handler, exc) def subst_auth_handler(prompt, conn, method, resource): self._subst_auth_handler(None, auth_handler, prompt, method, resource) if use_pk and try_as_root: debugprint("Using polkit-1 connection class") import asyncpk1 c = asyncpk1.PK1Connection(reply_handler=subst_reply_handler, error_handler=subst_error_handler, host=host, port=port, encryption=encryption, parent=parent) self._conn = c else: debugprint("Using IPP connection class") import asyncipp c = asyncipp.IPPAuthConnection(reply_handler=subst_reply_handler, error_handler=subst_error_handler, auth_handler=subst_auth_handler, host=host, port=port, encryption=encryption, parent=parent, try_as_root=try_as_root, prompt_allowed=prompt_allowed, semantic=self) self._conn = c methodtype = type(self._conn.getPrinters) instancemethodtype = type(self._conn.getDevices) bindings = [] for fname in dir(self._conn): if fname.startswith('_'): continue fn = getattr(self._conn, fname) if type(fn) != methodtype and type(fn) != instancemethodtype: continue if not hasattr(self, fname): setattr(self, fname, self._make_binding(fn)) bindings.append(fname) self._bindings = bindings self._methodcalls = [] debugprint("+%s" % self)