Documentation improvements in client.py
This commit is contained in:
parent
ad7c64998a
commit
6b5e9ea7ce
|
@ -16,23 +16,30 @@
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Provides PlugIn class functionality to develop extentions for xmpppy.
|
Provides PlugIn class functionality to develop extentions for xmpppy.
|
||||||
Also provides Client and Component classes implementations as the
|
|
||||||
examples of xmpppy structures usage.
|
|
||||||
These classes can be used for simple applications "AS IS" though.
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
log = logging.getLogger('gajim.c.x.plugin')
|
log = logging.getLogger('gajim.c.x.plugin')
|
||||||
|
|
||||||
class PlugIn:
|
class PlugIn:
|
||||||
''' Common xmpppy plugins infrastructure: plugging in/out, debugging. '''
|
'''
|
||||||
|
Abstract xmpppy plugin infrastructure code, providing plugging in/out and
|
||||||
|
debugging functionality.
|
||||||
|
|
||||||
|
Inherit to develop pluggable objects. No code change on the owner class
|
||||||
|
required (the object where we plug into)
|
||||||
|
'''
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._exported_methods=[]
|
self._exported_methods=[]
|
||||||
|
|
||||||
def PlugIn(self,owner):
|
def PlugIn(self, owner):
|
||||||
''' Attach to main instance and register ourself and all our staff in it. '''
|
'''
|
||||||
|
Attach to owner and register ourself and our _exported_methods in it.
|
||||||
|
If defined by a subclass, call self.plugin(owner) to execute hook
|
||||||
|
code after plugging.
|
||||||
|
'''
|
||||||
self._owner=owner
|
self._owner=owner
|
||||||
log.info('Plugging %s __INTO__ %s' % (self,self._owner))
|
log.info('Plugging %s __INTO__ %s' % (self, self._owner))
|
||||||
if self.__class__.__name__ in owner.__dict__:
|
if self.__class__.__name__ in owner.__dict__:
|
||||||
log.debug('Plugging ignored: another instance already plugged.')
|
log.debug('Plugging ignored: another instance already plugged.')
|
||||||
return
|
return
|
||||||
|
@ -48,21 +55,29 @@ class PlugIn:
|
||||||
else:
|
else:
|
||||||
owner.__dict__[self.__class__.__name__]=self
|
owner.__dict__[self.__class__.__name__]=self
|
||||||
|
|
||||||
# following commented line will not work for classes inheriting plugin()
|
# Execute hook
|
||||||
#if self.__class__.__dict__.has_key('plugin'): return self.plugin(owner)
|
if hasattr(self,'plugin'):
|
||||||
if hasattr(self,'plugin'): return self.plugin(owner)
|
return self.plugin(owner)
|
||||||
|
|
||||||
def PlugOut(self):
|
def PlugOut(self):
|
||||||
''' Unregister all our staff from main instance and detach from it. '''
|
'''
|
||||||
|
Unregister our _exported_methods from owner and detach from it.
|
||||||
|
If defined by a subclass, call self.plugout() after unplugging to execute
|
||||||
|
hook code.
|
||||||
|
'''
|
||||||
log.info('Plugging %s __OUT__ of %s.' % (self, self._owner))
|
log.info('Plugging %s __OUT__ of %s.' % (self, self._owner))
|
||||||
for method in self._exported_methods: del self._owner.__dict__[method.__name__]
|
for method in self._exported_methods:
|
||||||
for method in self._old_owners_methods: self._owner.__dict__[method.__name__]=method
|
del self._owner.__dict__[method.__name__]
|
||||||
|
for method in self._old_owners_methods:
|
||||||
|
self._owner.__dict__[method.__name__]=method
|
||||||
|
# FIXME: Dispatcher workaround
|
||||||
if self.__class__.__name__.endswith('Dispatcher'):
|
if self.__class__.__name__.endswith('Dispatcher'):
|
||||||
del self._owner.__dict__['Dispatcher']
|
del self._owner.__dict__['Dispatcher']
|
||||||
else:
|
else:
|
||||||
del self._owner.__dict__[self.__class__.__name__]
|
del self._owner.__dict__[self.__class__.__name__]
|
||||||
#if self.__class__.__dict__.has_key('plugout'): return self.plugout()
|
# Execute hook
|
||||||
if hasattr(self,'plugout'): return self.plugout()
|
if hasattr(self,'plugout'):
|
||||||
|
return self.plugout()
|
||||||
del self._owner
|
del self._owner
|
||||||
|
|
||||||
# vim: se ts=3:
|
# vim: se ts=3:
|
||||||
|
|
Loading…
Reference in New Issue