Back to index

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

List of all members.

Public Member Functions

def __init__
def run
def stop
def create_connection
def execute_command
def report_error
def get_auth_token
def warn_no_credentials
def get_page
def get_page_html
def get_page_list
def get_page_info
def do_search
def do_revert
def get_language_by_jid

Public Attributes

 log
 commands_in
 commands_out
 config
 url
 connection
 token
 multicall
 stopping

Static Public Attributes

tuple get_page = _xmlrpc_decorator(get_page)
tuple get_page_html = _xmlrpc_decorator(get_page_html)
tuple get_page_list = _xmlrpc_decorator(get_page_list)
tuple get_page_info = _xmlrpc_decorator(get_page_info)
tuple do_search = _xmlrpc_decorator(do_search)
tuple do_revert = _xmlrpc_decorator(do_revert)

Private Member Functions

def _get_multicall_result

Private Attributes

 _cmd_handlers

Detailed Description

XMLRPC Client

It's responsible for performing XMLRPC operations on
a wiki, as inctructed by command objects received from
the XMPP component

Definition at line 68 of file xmlrpcbot.py.


Constructor & Destructor Documentation

def jabberbot.xmlrpcbot.XMLRPCClient.__init__ (   self,
  config,
  commands_in,
  commands_out 
)
A constructor

@param commands_out: an output command queue (to xmpp)
@param commands_in: an input command queue (from xmpp)

Definition at line 75 of file xmlrpcbot.py.

00075 
00076     def __init__(self, config, commands_in, commands_out):
00077         """A constructor
00078 
00079         @param commands_out: an output command queue (to xmpp)
00080         @param commands_in: an input command queue (from xmpp)
00081 
00082         """
00083         Thread.__init__(self)
00084         self.log = logging.getLogger(__name__)
00085 
00086         if not config.secret:
00087             error = "You must set a (long) secret string!"
00088             self.log.critical(error)
00089             raise ConfigurationError(error)
00090 
00091         self.commands_in = commands_in
00092         self.commands_out = commands_out
00093         self.config = config
00094         self.url = config.wiki_url + "?action=xmlrpc2"
00095         self.connection = self.create_connection()
00096         self.token = None
00097         self.multicall = None
00098         self.stopping = False
00099 
00100         self._cmd_handlers = {cmd.GetPage: self.get_page,
00101                               cmd.GetPageHTML: self.get_page_html,
00102                               cmd.GetPageList: self.get_page_list,
00103                               cmd.GetPageInfo: self.get_page_info,
00104                               cmd.GetUserLanguage: self.get_language_by_jid,
00105                               cmd.Search: self.do_search,
00106                               cmd.RevertPage: self.do_revert}


Member Function Documentation

def jabberbot.xmlrpcbot.XMLRPCClient._get_multicall_result (   self,
  jid 
) [private]
Returns multicall results and issues a warning if there's an auth error

@param jid: a full JID to use if there's an error
@type jid: str

Definition at line 180 of file xmlrpcbot.py.

00180 
00181     def _get_multicall_result(self, jid):
00182         """Returns multicall results and issues a warning if there's an auth error
00183 
00184         @param jid: a full JID to use if there's an error
00185         @type jid: str
00186 
00187         """
00188 
00189         if not self.token:
00190             result = self.multicall()[0]
00191             token_result = u"FAILURE"
00192         else:
00193             token_result, result = self.multicall()
00194 
00195         if token_result != u"SUCCESS":
00196             self.warn_no_credentials(jid)
00197 
00198         return result
00199 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 123 of file xmlrpcbot.py.

00123 
00124     def create_connection(self):
00125         return xmlrpclib.ServerProxy(self.url, allow_none=True, verbose=self.config.verbose)

def jabberbot.xmlrpcbot.XMLRPCClient.do_revert (   self,
  command 
)
Performs a page revert

Definition at line 258 of file xmlrpcbot.py.

00258 
00259     def do_revert(self, command):
00260         """Performs a page revert"""
00261 
00262         # Dummy function, so that the string appears in a .po file
00263         _ = lambda x: x
00264 
00265         self.multicall.revertPage(command.pagename, command.revision)
00266         data = self._get_multicall_result(command.jid)
00267 
00268         if type(data) == bool and data:
00269             cmd_data = {'text': _("Page has been reverted.")}
00270         elif isinstance(str, data) or isinstance(unicode, data):
00271             cmd_data = {'text': _("Revert failed: %(reason)s" % {'reason': data})}
00272         else:
00273             cmd_data = {'text': _("Revert failed.")}
00274 
00275         info = cmd.NotificationCommandI18n([command.jid], cmd_data, async=False, msg_type=u"chat")
00276         self.commands_out.put_nowait(info)

Here is the call graph for this function:

def jabberbot.xmlrpcbot.XMLRPCClient.do_search (   self,
  command 
)
Performs a search

Definition at line 242 of file xmlrpcbot.py.

00242 
00243     def do_search(self, command):
00244         """Performs a search"""
00245 
00246         # Dummy function, so that the string appears in a .po file
00247         _ = lambda x: x
00248 
00249         cmd_data = {'text': _("This command may take a while to complete, please be patient...")}
00250         info = cmd.NotificationCommandI18n([command.jid], cmd_data, async=False, msg_type=u"chat")
00251         self.commands_out.put_nowait(info)
00252 
00253         c = command
00254         self.multicall.searchPagesEx(c.term, c.search_type, 30, c.case, c.mtime, c.regexp)
00255         command.data = self._get_multicall_result(command.jid)

Here is the call graph for this function:

def jabberbot.xmlrpcbot.XMLRPCClient.execute_command (   self,
  command 
)
Execute commands coming from the XMPP component

Definition at line 126 of file xmlrpcbot.py.

00126 
00127     def execute_command(self, command):
00128         """Execute commands coming from the XMPP component"""
00129 
00130         cmd_name = command.__class__
00131 
00132         try:
00133             handler = self._cmd_handlers[cmd_name]
00134         except KeyError:
00135             self.log.debug("No such command: " + cmd_name.__name__)
00136             return
00137 
00138         handler(command)

Here is the caller graph for this function:

Get an auth token using user's Jabber ID

@type jid: unicode

Definition at line 155 of file xmlrpcbot.py.

00155 
00156     def get_auth_token(self, jid):
00157         """Get an auth token using user's Jabber ID
00158 
00159         @type jid: unicode
00160         """
00161         # We have to use a bare JID
00162         jid = jid.split('/')[0]
00163         token = self.connection.getJabberAuthToken(jid, self.config.secret)
00164         if token:
00165             self.token = token

Returns language of the a user identified by the given JID

Definition at line 279 of file xmlrpcbot.py.

00279 
00280     def get_language_by_jid(self, command):
00281         """Returns language of the a user identified by the given JID"""
00282 
00283         server = xmlrpclib.ServerProxy(self.config.wiki_url + "?action=xmlrpc2")
00284         language = "en"
00285 
00286         try:
00287             language = server.getUserLanguageByJID(command.jid)
00288         except xmlrpclib.Fault, fault:
00289             self.log.error(str(fault))
00290         except xmlrpclib.Error, err:
00291             self.log.error(str(err))
00292         except Exception, exc:
00293             self.log.critical(str(exc))
00294 
00295         command.language = language
00296         self.commands_out.put_nowait(command)
00297 

def jabberbot.xmlrpcbot.XMLRPCClient.get_page (   self,
  command 
)
Returns a raw page

Definition at line 200 of file xmlrpcbot.py.

00200 
00201     def get_page(self, command):
00202         """Returns a raw page"""
00203 
00204         self.multicall.getPage(command.pagename)
00205         command.data = self._get_multicall_result(command.jid)

Here is the call graph for this function:

def jabberbot.xmlrpcbot.XMLRPCClient.get_page_html (   self,
  command 
)
Returns a html-formatted page

Definition at line 209 of file xmlrpcbot.py.

00209 
00210     def get_page_html(self, command):
00211         """Returns a html-formatted page"""
00212 
00213         self.multicall.getPageHTML(command.pagename)
00214         command.data = self._get_multicall_result(command.jid)

Here is the call graph for this function:

def jabberbot.xmlrpcbot.XMLRPCClient.get_page_info (   self,
  command 
)
Returns detailed information about a given page

Definition at line 234 of file xmlrpcbot.py.

00234 
00235     def get_page_info(self, command):
00236         """Returns detailed information about a given page"""
00237 
00238         self.multicall.getPageInfo(command.pagename)
00239         command.data = self._get_multicall_result(command.jid)

Here is the call graph for this function:

def jabberbot.xmlrpcbot.XMLRPCClient.get_page_list (   self,
  command 
)
Returns a list of all accesible pages

Definition at line 218 of file xmlrpcbot.py.

00218 
00219     def get_page_list(self, command):
00220         """Returns a list of all accesible pages"""
00221 
00222         # Dummy function, so that the string appears in a .po file
00223         _ = lambda x: x
00224 
00225         cmd_data = {'text': _("This command may take a while to complete, please be patient...")}
00226         info = cmd.NotificationCommandI18n([command.jid], cmd_data, async=False, msg_type=u"chat")
00227         self.commands_out.put_nowait(info)
00228 
00229         self.multicall.getAllPages()
00230         command.data = self._get_multicall_result(command.jid)

Here is the call graph for this function:

def jabberbot.xmlrpcbot.XMLRPCClient.report_error (   self,
  jid,
  text,
  data = {} 
)
Reports an internal error

@param jid: Jabber ID that should be informed about the error condition
@param text: description of the error
@param data: dictionary used to substitute strings in translated message
@type data: dict

Definition at line 139 of file xmlrpcbot.py.

00139 
00140     def report_error(self, jid, text, data={}):
00141         """Reports an internal error
00142 
00143         @param jid: Jabber ID that should be informed about the error condition
00144         @param text: description of the error
00145         @param data: dictionary used to substitute strings in translated message
00146         @type data: dict
00147 
00148         """
00149         # Dummy function, so that the string appears in a .po file
00150         _ = lambda x: x
00151 
00152         cmddata = {'text': text, 'data': data}
00153         report = cmd.NotificationCommandI18n(jid, cmddata, msg_type=u"chat", async=False)
00154         self.commands_out.put_nowait(report)

Starts the server / thread

Definition at line 107 of file xmlrpcbot.py.

00107 
00108     def run(self):
00109         """Starts the server / thread"""
00110         while True:
00111             if self.stopping:
00112                 break
00113 
00114             try:
00115                 command = self.commands_in.get(True, 2)
00116                 self.execute_command(command)
00117             except Queue.Empty:
00118                 pass

Here is the call graph for this function:

Stop the thread

Definition at line 119 of file xmlrpcbot.py.

00119 
00120     def stop(self):
00121         """Stop the thread"""
00122         self.stopping = True

Warn a given JID that credentials check failed

@param jid: full JID to notify about failure
@type jid: str

Definition at line 166 of file xmlrpcbot.py.

00166 
00167     def warn_no_credentials(self, jid):
00168         """Warn a given JID that credentials check failed
00169 
00170         @param jid: full JID to notify about failure
00171         @type jid: str
00172 
00173         """
00174         # Dummy function, so that the string appears in a .po file
00175         _ = lambda x: x
00176 
00177         cmddata = {'text': _("Credentials check failed, you might be unable to see all information.")}
00178         warning = cmd.NotificationCommandI18n([jid], cmddata, async=False)
00179         self.commands_out.put_nowait(warning)

Here is the caller graph for this function:


Member Data Documentation

Definition at line 99 of file xmlrpcbot.py.

Definition at line 90 of file xmlrpcbot.py.

Definition at line 91 of file xmlrpcbot.py.

Definition at line 92 of file xmlrpcbot.py.

Definition at line 94 of file xmlrpcbot.py.

Definition at line 277 of file xmlrpcbot.py.

Definition at line 256 of file xmlrpcbot.py.

Definition at line 206 of file xmlrpcbot.py.

Definition at line 215 of file xmlrpcbot.py.

Definition at line 240 of file xmlrpcbot.py.

Definition at line 231 of file xmlrpcbot.py.

Definition at line 83 of file xmlrpcbot.py.

Definition at line 96 of file xmlrpcbot.py.

Definition at line 97 of file xmlrpcbot.py.

Definition at line 95 of file xmlrpcbot.py.

Definition at line 93 of file xmlrpcbot.py.


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