home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / var / lib / python-support / python2.6 / dbus / server.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  3.7 KB  |  93 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __all__ = ('Server',)
  5. __docformat__ = 'reStructuredText'
  6. from _dbus_bindings import _Server
  7. from dbus.connection import Connection
  8.  
  9. class Server(_Server):
  10.     '''An opaque object representing a server that listens for connections from
  11.     other applications.
  12.  
  13.     This class is not useful to instantiate directly: you must subclass it and
  14.     either extend the method connection_added, or append to the
  15.     list on_connection_added.
  16.  
  17.     :Since: 0.83
  18.     '''
  19.     
  20.     def __new__(cls, address, connection_class = Connection, mainloop = None, auth_mechanisms = None):
  21.         '''Construct a new Server.
  22.  
  23.         :Parameters:
  24.             `address` : str
  25.                 Listen on this address.
  26.             `connection_class` : type
  27.                 When new connections come in, instantiate this subclass
  28.                 of dbus.connection.Connection to represent them.
  29.                 The default is Connection.
  30.             `mainloop` : dbus.mainloop.NativeMainLoop or None
  31.                 The main loop with which to associate the new connections.
  32.             `auth_mechanisms` : sequence of str
  33.                 Authentication mechanisms to allow. The default is to allow
  34.                 any authentication mechanism supported by ``libdbus``.
  35.         '''
  36.         return super(Server, cls).__new__(cls, address, connection_class, mainloop, auth_mechanisms)
  37.  
  38.     
  39.     def __init__(self, *args, **kwargs):
  40.         self._Server__connections = { }
  41.         self.on_connection_added = []
  42.         self.on_connection_removed = []
  43.  
  44.     
  45.     def _on_new_connection(self, conn):
  46.         conn.call_on_disconnection(self.connection_removed)
  47.         self.connection_added(conn)
  48.  
  49.     
  50.     def connection_added(self, conn):
  51.         '''Respond to the creation of a new Connection.
  52.  
  53.         This base-class implementation just invokes the callbacks in
  54.         the on_connection_added attribute.
  55.  
  56.         :Parameters:
  57.             `conn` : dbus.connection.Connection
  58.                 A D-Bus connection which has just been added.
  59.  
  60.                 The type of this parameter is whatever was passed
  61.                 to the Server constructor as the ``connection_class``.
  62.         '''
  63.         if self.on_connection_added:
  64.             for cb in self.on_connection_added:
  65.                 cb(conn)
  66.             
  67.         
  68.  
  69.     
  70.     def connection_removed(self, conn):
  71.         '''Respond to the disconnection of a Connection.
  72.  
  73.         This base-class implementation just invokes the callbacks in
  74.         the on_connection_removed attribute.
  75.  
  76.         :Parameters:
  77.             `conn` : dbus.connection.Connection
  78.                 A D-Bus connection which has just become disconnected.
  79.  
  80.                 The type of this parameter is whatever was passed
  81.                 to the Server constructor as the ``connection_class``.
  82.         '''
  83.         if self.on_connection_removed:
  84.             for cb in self.on_connection_removed:
  85.                 cb(conn)
  86.             
  87.         
  88.  
  89.     address = property(_Server.get_address)
  90.     id = property(_Server.get_id)
  91.     is_connected = property(_Server.get_is_connected)
  92.  
  93.