Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes
jabberbot.xmlrpcbot.XMLRPCServer Class Reference
Inheritance diagram for jabberbot.xmlrpcbot.XMLRPCServer:
Inheritance graph
[legend]
Collaboration diagram for jabberbot.xmlrpcbot.XMLRPCServer:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def run
def secret_check
def send_notification
def addJIDToRoster
def removeJIDFromRoster

Public Attributes

 commands
 verbose
 log
 config
 secret
 server

Detailed Description

XMLRPC Server

It waits for notifications requests coming from wiki,
creates command objects and puts them on a queue for
later processing by the XMPP component

@param commands: an input command queue

Definition at line 298 of file xmlrpcbot.py.


Constructor & Destructor Documentation

def jabberbot.xmlrpcbot.XMLRPCServer.__init__ (   self,
  config,
  commands 
)

Definition at line 308 of file xmlrpcbot.py.

00308 
00309     def __init__(self, config, commands):
00310         Thread.__init__(self)
00311         self.commands = commands
00312         self.verbose = config.verbose
00313         self.log = logging.getLogger(__name__)
00314         self.config = config
00315 
00316         if config.secret:
00317             self.secret = config.secret
00318         else:
00319             error = "You must set a (long) secret string"
00320             self.log.critical(error)
00321             raise ConfigurationError(error)
00322 
00323         self.server = None


Member Function Documentation

Instructs the XMPP component to add a new JID to its roster

@param jid: a jid to add, this must be a bare jid
@type jid: str or unicode,

Definition at line 374 of file xmlrpcbot.py.

00374 
00375     def addJIDToRoster(self, jid):
00376         """Instructs the XMPP component to add a new JID to its roster
00377 
00378         @param jid: a jid to add, this must be a bare jid
00379         @type jid: str or unicode,
00380 
00381         """
00382         command = cmd.AddJIDToRosterCommand(jid)
00383         self.commands.put_nowait(command)
        return True
Instructs the XMPP component to remove a JID from its roster

@param jid: a jid to remove, this must be a bare jid
@type jid: str or unicode

Definition at line 386 of file xmlrpcbot.py.

00386 
00387     def removeJIDFromRoster(self, jid):
00388         """Instructs the XMPP component to remove a JID from its roster
00389 
00390         @param jid: a jid to remove, this must be a bare jid
00391         @type jid: str or unicode
00392 
00393         """
00394         command = cmd.RemoveJIDFromRosterCommand(jid)
00395         self.commands.put_nowait(command)
        return True
Starts the server / thread

Definition at line 324 of file xmlrpcbot.py.

00324 
00325     def run(self):
00326         """Starts the server / thread"""
00327 
00328         self.server = SimpleXMLRPCServer((self.config.xmlrpc_host, self.config.xmlrpc_port))
00329 
00330         # Register methods having an "export" attribute as XML RPC functions and
00331         # decorate them with a check for a shared (wiki-bot) secret.
00332         items = self.__class__.__dict__.items()
00333         methods = [(name, func) for (name, func) in items if callable(func)
00334                    and "export" in func.__dict__]
00335 
00336         for name, func in methods:
00337             self.server.register_function(self.secret_check(func), name)
00338 
00339         self.server.serve_forever()

Here is the call graph for this function:

def jabberbot.xmlrpcbot.XMLRPCServer.secret_check (   self,
  function 
)
Adds a check for a secret to a given function

Using this one does not have to worry about checking for the secret
in every XML RPC function.

Definition at line 340 of file xmlrpcbot.py.

00340 
00341     def secret_check(self, function):
00342         """Adds a check for a secret to a given function
00343 
00344         Using this one does not have to worry about checking for the secret
00345         in every XML RPC function.
00346         """
00347         def protected_func(secret, *args):
00348             if secret != self.secret:
00349                 raise xmlrpclib.Fault(1, "You are not allowed to use this bot!")
00350             else:
00351                 return function(self, *args)
00352 
00353         return protected_func
00354 

Here is the caller graph for this function:

def jabberbot.xmlrpcbot.XMLRPCServer.send_notification (   self,
  jids,
  notification 
)
Instructs the XMPP component to send a notification

The notification dict has following entries:
'text' - notification text (REQUIRED)
'subject' - notification subject
'url_list' - a list of dicts describing attached URLs

@param jids: a list of JIDs to send a message to (bare JIDs)
@type jids: a list of str or unicode
@param notification: dictionary with notification data
@type notification: dict

Definition at line 355 of file xmlrpcbot.py.

00355 
00356     def send_notification(self, jids, notification):
00357         """Instructs the XMPP component to send a notification
00358 
00359         The notification dict has following entries:
00360         'text' - notification text (REQUIRED)
00361         'subject' - notification subject
00362         'url_list' - a list of dicts describing attached URLs
00363 
00364         @param jids: a list of JIDs to send a message to (bare JIDs)
00365         @type jids: a list of str or unicode
00366         @param notification: dictionary with notification data
00367         @type notification: dict
00368 
00369         """
00370         command = cmd.NotificationCommand(jids, notification, async=True)
00371         self.commands.put_nowait(command)
        return True

Member Data Documentation

Definition at line 310 of file xmlrpcbot.py.

Definition at line 313 of file xmlrpcbot.py.

Definition at line 312 of file xmlrpcbot.py.

Definition at line 316 of file xmlrpcbot.py.

Definition at line 322 of file xmlrpcbot.py.

Definition at line 311 of file xmlrpcbot.py.


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