Back to index

system-config-printer  1.3.9+20120706
Public Member Functions | Private Member Functions | Private Attributes
dnssdresolve.DNSSDHostNamesResolver Class Reference

List of all members.

Public Member Functions

def __init__
def __del__
def resolve

Private Member Functions

def _resolved
def _reply
def _error

Private Attributes

 _devices
 _unresolved
 _device_uri_by_name
 _reply_handler

Detailed Description

Definition at line 24 of file dnssdresolve.py.


Constructor & Destructor Documentation

def dnssdresolve.DNSSDHostNamesResolver.__init__ (   self,
  devices 
)

Definition at line 25 of file dnssdresolve.py.

00025 
00026     def __init__ (self, devices):
00027         self._devices = devices
00028         self._unresolved = len (devices)
00029         self._device_uri_by_name = {}
00030         debugprint ("+%s" % self)

Definition at line 31 of file dnssdresolve.py.

00031 
00032     def __del__ (self):
00033         debugprint ("-%s" % self)


Member Function Documentation

def dnssdresolve.DNSSDHostNamesResolver._error (   self,
  uri,
  error 
) [private]

Definition at line 109 of file dnssdresolve.py.

00109 
00110     def _error (self, uri, error):
00111         debugprint ("Error resolving %s: %s" % (uri, error))
00112         self._resolved ()

Here is the call graph for this function:

def dnssdresolve.DNSSDHostNamesResolver._reply (   self,
  interface,
  protocol,
  name,
  stype,
  domain,
  host,
  aprotocol,
  address,
  port,
  txt,
  flags 
) [private]

Definition at line 98 of file dnssdresolve.py.

00098 
00099                 host, aprotocol, address, port, txt, flags):
00100         uri = self._device_uri_by_name[(name.encode ('utf-8'), stype, domain)]
00101         self._devices[uri].address = address
00102         hostname = host
00103         p = hostname.find(".")
00104         if p != -1:
00105             hostname = hostname[:p]
00106         debugprint ("%s is at %s (%s)" % (uri, address, hostname))
00107         self._devices[uri].hostname = hostname
00108         self._resolved ()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 89 of file dnssdresolve.py.

00089 
00090     def _resolved (self):
00091         self._unresolved -= 1
00092         if self._unresolved == 0:
00093             debugprint ("All addresses resolved")
00094             self._reply_handler (self._devices)
00095             del self._devices
00096             del self._reply_handler

Here is the call graph for this function:

Here is the caller graph for this function:

def dnssdresolve.DNSSDHostNamesResolver.resolve (   self,
  reply_handler 
)

Definition at line 34 of file dnssdresolve.py.

00034 
00035     def resolve (self, reply_handler):
00036 
00037         def expandhex (searchres):
00038             expr = searchres.group(0)
00039             return chr(int(expr[1:], 16))
00040 
00041         self._reply_handler = reply_handler
00042 
00043         bus = dbus.SystemBus ()
00044         if not bus:
00045             reply_handler ([])
00046             del self._devices
00047             del self._reply_handler
00048             return
00049 
00050         for uri, device in self._devices.iteritems ():
00051             if not uri.startswith ("dnssd://"):
00052                 self._unresolved -= 1
00053                 continue
00054 
00055             # We need to resolve the DNS-SD hostname in order to
00056             # compare with other network devices.
00057             p = uri[8:].find ("/")
00058             if p == -1:
00059                 hostname = uri[8:]
00060             else:
00061                 hostname = uri[8:8+p]
00062 
00063             hostname = hostname.encode('utf-8')
00064             hostname = re.sub("%(?i)[\dabcdef]{2}", expandhex, hostname)
00065 
00066             elements = hostname.rsplit (".", 3)
00067             if len (elements) != 4:
00068                 self._resolved ()
00069                 continue
00070 
00071             name, stype, protocol, domain = elements
00072             stype += "." + protocol #  e.g. _printer._tcp
00073 
00074             try:
00075                 obj = bus.get_object ("org.freedesktop.Avahi", "/")
00076                 server = dbus.Interface (obj,
00077                                          "org.freedesktop.Avahi.Server")
00078                 self._device_uri_by_name[(name, stype, domain)] = uri
00079                 debugprint ("Resolving address for %s" % hostname)
00080                 server.ResolveService (-1, -1,
00081                                         name, stype, domain,
00082                                         -1, 0,
00083                                         reply_handler=self._reply,
00084                                         error_handler=lambda e:
00085                                             self._error (uri, e))
00086             except dbus.DBusException, e:
00087                 debugprint ("Failed to resolve address: %s" % e)
00088                 self._resolved ()


Member Data Documentation

Definition at line 28 of file dnssdresolve.py.

Definition at line 26 of file dnssdresolve.py.

Definition at line 40 of file dnssdresolve.py.

Definition at line 27 of file dnssdresolve.py.


The documentation for this class was generated from the following file: