annotate jabberbot/xmlrpcbot.py @ 4701:d8049de69c4f

release edit lock if someone saves an unchanged page
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 18 Apr 2009 21:08:35 +0200
parents 6f06c7d051a4
children afc6264a134f
rev   line source
2068
7e2a9b7d2bc6 XML RPC functionality for the notification bot - the beginning
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
7e2a9b7d2bc6 XML RPC functionality for the notification bot - the beginning
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
2 """
7e2a9b7d2bc6 XML RPC functionality for the notification bot - the beginning
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
3 MoinMoin - a xmlrpc server and client for the notification bot
7e2a9b7d2bc6 XML RPC functionality for the notification bot - the beginning
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
4
7e2a9b7d2bc6 XML RPC functionality for the notification bot - the beginning
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
5 @copyright: 2007 by Karol Nowak <grywacz@gmail.com>
7e2a9b7d2bc6 XML RPC functionality for the notification bot - the beginning
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
6 @license: GNU GPL, see COPYING for details.
7e2a9b7d2bc6 XML RPC functionality for the notification bot - the beginning
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
7 """
7e2a9b7d2bc6 XML RPC functionality for the notification bot - the beginning
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
8
2504
c27ee67397f0 Make pylint happy where it made sense, fix a few minor bugs.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2502
diff changeset
9 import logging, xmlrpclib, Queue
2413
61380308535d Added a dummy _ function so that string for translations can be gathered.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2402
diff changeset
10 from SimpleXMLRPCServer import SimpleXMLRPCServer
2391
ddb4c626062d Big checkpoint commit. Details below:
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
11 from threading import Thread
2088
a99ed13fec1e Introduce a shared secret for wiki-bot communication + some code style fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2084
diff changeset
12
2118
805d56ccbea7 Don't import each command by hand, rather used a shortened module name.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2116
diff changeset
13 import jabberbot.commands as cmd
2121
ae2134211ac1 XMPP -> wiki XML RPC, the beginning...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2118
diff changeset
14 from jabberbot.multicall import MultiCall
2635
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
15
2413
61380308535d Added a dummy _ function so that string for translations can be gathered.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2402
diff changeset
16
2319
10ec0e8d35e1 Make send_notification accept a list of JIDs, instead of one.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2167
diff changeset
17 class ConfigurationError(Exception):
2957
bc85e5200dd3 GHOP: refactor hardcoded if...elif...else code to use dispatching.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2691
diff changeset
18
2319
10ec0e8d35e1 Make send_notification accept a list of JIDs, instead of one.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2167
diff changeset
19 def __init__(self, message):
2632
584e1714aa05 Fix a missing __init__ argument in ConfigurationError exception.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2629
diff changeset
20 Exception.__init__(self)
2319
10ec0e8d35e1 Make send_notification accept a list of JIDs, instead of one.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2167
diff changeset
21 self.message = message
2088
a99ed13fec1e Introduce a shared secret for wiki-bot communication + some code style fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2084
diff changeset
22
2957
bc85e5200dd3 GHOP: refactor hardcoded if...elif...else code to use dispatching.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2691
diff changeset
23
2635
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
24 def _xmlrpc_decorator(function):
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
25 """A decorator function, which adds some maintenance code
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
26
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
27 This function takes care of preparing a MultiCall object and
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
28 an authentication token, and deleting them at the end.
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
29
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
30 """
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
31 def wrapped_func(self, command):
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
32 # Dummy function, so that the string appears in a .po file
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
33 _ = lambda x: x
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
34
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
35 self.token = None
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
36 self.multicall = MultiCall(self.connection)
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
37 jid = command.jid
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
38 if type(jid) is not list:
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
39 jid = [jid]
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
40
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
41 try:
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
42 try:
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
43 self.get_auth_token(command.jid)
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
44 if self.token:
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
45 self.multicall.applyAuthToken(self.token)
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
46
2653
11447cada25e Fix layering violation in xmlrpcbot code, as mentioned in TODO.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2650
diff changeset
47 function(self, command)
2635
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
48 self.commands_out.put_nowait(command)
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
49
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
50 except xmlrpclib.Fault, fault:
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
51 msg = _("Your request has failed. The reason is:\n%(error)s")
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
52 self.log.error(str(fault))
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
53 self.report_error(jid, msg, {'error': fault.faultString})
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
54 except xmlrpclib.Error, err:
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
55 msg = _("A serious error occured while processing your request:\n%(error)s")
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
56 self.log.error(str(err))
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
57 self.report_error(jid, msg, {'error': str(err)})
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
58 except Exception, exc:
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
59 msg = _("An internal error has occured, please contact the administrator.")
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
60 self.log.critical(str(exc))
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
61 self.report_error(jid, msg)
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
62
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
63 finally:
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
64 del self.token
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
65 del self.multicall
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
66
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
67 return wrapped_func
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
68
2068
7e2a9b7d2bc6 XML RPC functionality for the notification bot - the beginning
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
69 class XMLRPCClient(Thread):
7e2a9b7d2bc6 XML RPC functionality for the notification bot - the beginning
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
70 """XMLRPC Client
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2167
diff changeset
71
2068
7e2a9b7d2bc6 XML RPC functionality for the notification bot - the beginning
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
72 It's responsible for performing XMLRPC operations on
7e2a9b7d2bc6 XML RPC functionality for the notification bot - the beginning
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
73 a wiki, as inctructed by command objects received from
7e2a9b7d2bc6 XML RPC functionality for the notification bot - the beginning
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
74 the XMPP component"""
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2167
diff changeset
75
2121
ae2134211ac1 XMPP -> wiki XML RPC, the beginning...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2118
diff changeset
76 def __init__(self, config, commands_in, commands_out):
2391
ddb4c626062d Big checkpoint commit. Details below:
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
77 """A constructor
ddb4c626062d Big checkpoint commit. Details below:
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
78
ddb4c626062d Big checkpoint commit. Details below:
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
79 @param commands_out: an output command queue (to xmpp)
2402
9c0c2b782737 Typo fix.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2391
diff changeset
80 @param commands_in: an input command queue (from xmpp)
2391
ddb4c626062d Big checkpoint commit. Details below:
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
81
2071
aa761813d7bd Silly changes to test CIA.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2070
diff changeset
82 """
2068
7e2a9b7d2bc6 XML RPC functionality for the notification bot - the beginning
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
83 Thread.__init__(self)
3612
6f06c7d051a4 Setting a more meaningful logger name.
Karol 'grzywacz' Nowak <grywacz@gmail.com>
parents: 2957
diff changeset
84 self.log = logging.getLogger(__name__)
2336
10be78f1fa97 Merge main.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2332 2286
diff changeset
85
2319
10ec0e8d35e1 Make send_notification accept a list of JIDs, instead of one.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2167
diff changeset
86 if not config.secret:
2626
a791fc964e09 Attempt to move i18n from xmlrpc to xmpp thread.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2504
diff changeset
87 error = "You must set a (long) secret string!"
2322
4b4868ae88f0 Replace prints with stdlib's logging features.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2319
diff changeset
88 self.log.critical(error)
4b4868ae88f0 Replace prints with stdlib's logging features.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2319
diff changeset
89 raise ConfigurationError(error)
2336
10be78f1fa97 Merge main.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2332 2286
diff changeset
90
2121
ae2134211ac1 XMPP -> wiki XML RPC, the beginning...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2118
diff changeset
91 self.commands_in = commands_in
ae2134211ac1 XMPP -> wiki XML RPC, the beginning...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2118
diff changeset
92 self.commands_out = commands_out
2083
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2071
diff changeset
93 self.config = config
2121
ae2134211ac1 XMPP -> wiki XML RPC, the beginning...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2118
diff changeset
94 self.url = config.wiki_url + "?action=xmlrpc2"
ae2134211ac1 XMPP -> wiki XML RPC, the beginning...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2118
diff changeset
95 self.connection = self.create_connection()
ae2134211ac1 XMPP -> wiki XML RPC, the beginning...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2118
diff changeset
96 self.token = None
ae2134211ac1 XMPP -> wiki XML RPC, the beginning...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2118
diff changeset
97 self.multicall = None
2659
892055d122fb Handle process/thread termination gracefully.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2653
diff changeset
98 self.stopping = False
2121
ae2134211ac1 XMPP -> wiki XML RPC, the beginning...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2118
diff changeset
99
2957
bc85e5200dd3 GHOP: refactor hardcoded if...elif...else code to use dispatching.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2691
diff changeset
100 self._cmd_handlers = {cmd.GetPage: self.get_page,
bc85e5200dd3 GHOP: refactor hardcoded if...elif...else code to use dispatching.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2691
diff changeset
101 cmd.GetPageHTML: self.get_page_html,
bc85e5200dd3 GHOP: refactor hardcoded if...elif...else code to use dispatching.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2691
diff changeset
102 cmd.GetPageList: self.get_page_list,
bc85e5200dd3 GHOP: refactor hardcoded if...elif...else code to use dispatching.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2691
diff changeset
103 cmd.GetPageInfo: self.get_page_info,
bc85e5200dd3 GHOP: refactor hardcoded if...elif...else code to use dispatching.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2691
diff changeset
104 cmd.GetUserLanguage: self.get_language_by_jid,
bc85e5200dd3 GHOP: refactor hardcoded if...elif...else code to use dispatching.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2691
diff changeset
105 cmd.Search: self.do_search,
bc85e5200dd3 GHOP: refactor hardcoded if...elif...else code to use dispatching.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2691
diff changeset
106 cmd.RevertPage: self.do_revert}
bc85e5200dd3 GHOP: refactor hardcoded if...elif...else code to use dispatching.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2691
diff changeset
107
2070
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2068
diff changeset
108 def run(self):
2083
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2071
diff changeset
109 """Starts the server / thread"""
2121
ae2134211ac1 XMPP -> wiki XML RPC, the beginning...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2118
diff changeset
110 while True:
2659
892055d122fb Handle process/thread termination gracefully.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2653
diff changeset
111 if self.stopping:
892055d122fb Handle process/thread termination gracefully.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2653
diff changeset
112 break
892055d122fb Handle process/thread termination gracefully.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2653
diff changeset
113
2121
ae2134211ac1 XMPP -> wiki XML RPC, the beginning...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2118
diff changeset
114 try:
ae2134211ac1 XMPP -> wiki XML RPC, the beginning...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2118
diff changeset
115 command = self.commands_in.get(True, 2)
ae2134211ac1 XMPP -> wiki XML RPC, the beginning...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2118
diff changeset
116 self.execute_command(command)
ae2134211ac1 XMPP -> wiki XML RPC, the beginning...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2118
diff changeset
117 except Queue.Empty:
ae2134211ac1 XMPP -> wiki XML RPC, the beginning...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2118
diff changeset
118 pass
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
119
2659
892055d122fb Handle process/thread termination gracefully.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2653
diff changeset
120 def stop(self):
892055d122fb Handle process/thread termination gracefully.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2653
diff changeset
121 """Stop the thread"""
892055d122fb Handle process/thread termination gracefully.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2653
diff changeset
122 self.stopping = True
892055d122fb Handle process/thread termination gracefully.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2653
diff changeset
123
2121
ae2134211ac1 XMPP -> wiki XML RPC, the beginning...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2118
diff changeset
124 def create_connection(self):
ae2134211ac1 XMPP -> wiki XML RPC, the beginning...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2118
diff changeset
125 return xmlrpclib.ServerProxy(self.url, allow_none=True, verbose=self.config.verbose)
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
126
2121
ae2134211ac1 XMPP -> wiki XML RPC, the beginning...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2118
diff changeset
127 def execute_command(self, command):
ae2134211ac1 XMPP -> wiki XML RPC, the beginning...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2118
diff changeset
128 """Execute commands coming from the XMPP component"""
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
129
2957
bc85e5200dd3 GHOP: refactor hardcoded if...elif...else code to use dispatching.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2691
diff changeset
130 cmd_name = command.__class__
bc85e5200dd3 GHOP: refactor hardcoded if...elif...else code to use dispatching.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2691
diff changeset
131
bc85e5200dd3 GHOP: refactor hardcoded if...elif...else code to use dispatching.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2691
diff changeset
132 try:
bc85e5200dd3 GHOP: refactor hardcoded if...elif...else code to use dispatching.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2691
diff changeset
133 handler = self._cmd_handlers[cmd_name]
bc85e5200dd3 GHOP: refactor hardcoded if...elif...else code to use dispatching.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2691
diff changeset
134 except KeyError:
bc85e5200dd3 GHOP: refactor hardcoded if...elif...else code to use dispatching.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2691
diff changeset
135 self.log.debug("No such command: " + cmd_name.__name__)
bc85e5200dd3 GHOP: refactor hardcoded if...elif...else code to use dispatching.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2691
diff changeset
136 return
bc85e5200dd3 GHOP: refactor hardcoded if...elif...else code to use dispatching.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2691
diff changeset
137
bc85e5200dd3 GHOP: refactor hardcoded if...elif...else code to use dispatching.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2691
diff changeset
138 handler(command)
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
139
2626
a791fc964e09 Attempt to move i18n from xmlrpc to xmpp thread.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2504
diff changeset
140 def report_error(self, jid, text, data={}):
2691
64eae2cfb6dc Improve comment.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2678
diff changeset
141 """Reports an internal error
64eae2cfb6dc Improve comment.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2678
diff changeset
142
64eae2cfb6dc Improve comment.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2678
diff changeset
143 @param jid: Jabber ID that should be informed about the error condition
64eae2cfb6dc Improve comment.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2678
diff changeset
144 @param text: description of the error
64eae2cfb6dc Improve comment.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2678
diff changeset
145 @param data: dictionary used to substitute strings in translated message
64eae2cfb6dc Improve comment.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2678
diff changeset
146 @type data: dict
64eae2cfb6dc Improve comment.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2678
diff changeset
147
64eae2cfb6dc Improve comment.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2678
diff changeset
148 """
2626
a791fc964e09 Attempt to move i18n from xmlrpc to xmpp thread.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2504
diff changeset
149 # Dummy function, so that the string appears in a .po file
a791fc964e09 Attempt to move i18n from xmlrpc to xmpp thread.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2504
diff changeset
150 _ = lambda x: x
2629
5dac44252ca6 Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2626
diff changeset
151
2650
2b4be3be9835 First implementation of search, will be changed later to optionally use oob.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2647
diff changeset
152 cmddata = {'text': text, 'data': data}
2b4be3be9835 First implementation of search, will be changed later to optionally use oob.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2647
diff changeset
153 report = cmd.NotificationCommandI18n(jid, cmddata, msg_type=u"chat", async=False)
2391
ddb4c626062d Big checkpoint commit. Details below:
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
154 self.commands_out.put_nowait(report)
ddb4c626062d Big checkpoint commit. Details below:
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
155
2123
184975c4b86f Fix GetPage, make it use the token obtained using jid and shared secret.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2121
diff changeset
156 def get_auth_token(self, jid):
2502
d9aef892fda8 Fix xmlrpc commands. How come I've never noticed how b0rked it was?!
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2483
diff changeset
157 """Get an auth token using user's Jabber ID
d9aef892fda8 Fix xmlrpc commands. How come I've never noticed how b0rked it was?!
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2483
diff changeset
158
d9aef892fda8 Fix xmlrpc commands. How come I've never noticed how b0rked it was?!
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2483
diff changeset
159 @type jid: unicode
d9aef892fda8 Fix xmlrpc commands. How come I've never noticed how b0rked it was?!
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2483
diff changeset
160 """
d9aef892fda8 Fix xmlrpc commands. How come I've never noticed how b0rked it was?!
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2483
diff changeset
161 # We have to use a bare JID
d9aef892fda8 Fix xmlrpc commands. How come I've never noticed how b0rked it was?!
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2483
diff changeset
162 jid = jid.split('/')[0]
d9aef892fda8 Fix xmlrpc commands. How come I've never noticed how b0rked it was?!
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2483
diff changeset
163 token = self.connection.getJabberAuthToken(jid, self.config.secret)
2121
ae2134211ac1 XMPP -> wiki XML RPC, the beginning...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2118
diff changeset
164 if token:
ae2134211ac1 XMPP -> wiki XML RPC, the beginning...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2118
diff changeset
165 self.token = token
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
166
2342
24242585fd70 Warn user if we failed to get a token using his credentials.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2337
diff changeset
167 def warn_no_credentials(self, jid):
2626
a791fc964e09 Attempt to move i18n from xmlrpc to xmpp thread.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2504
diff changeset
168 """Warn a given JID that credentials check failed
2629
5dac44252ca6 Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2626
diff changeset
169
2626
a791fc964e09 Attempt to move i18n from xmlrpc to xmpp thread.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2504
diff changeset
170 @param jid: full JID to notify about failure
a791fc964e09 Attempt to move i18n from xmlrpc to xmpp thread.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2504
diff changeset
171 @type jid: str
2629
5dac44252ca6 Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2626
diff changeset
172
2626
a791fc964e09 Attempt to move i18n from xmlrpc to xmpp thread.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2504
diff changeset
173 """
a791fc964e09 Attempt to move i18n from xmlrpc to xmpp thread.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2504
diff changeset
174 # Dummy function, so that the string appears in a .po file
a791fc964e09 Attempt to move i18n from xmlrpc to xmpp thread.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2504
diff changeset
175 _ = lambda x: x
2629
5dac44252ca6 Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2626
diff changeset
176
2650
2b4be3be9835 First implementation of search, will be changed later to optionally use oob.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2647
diff changeset
177 cmddata = {'text': _("Credentials check failed, you might be unable to see all information.")}
2635
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
178 warning = cmd.NotificationCommandI18n([jid], cmddata, async=False)
2342
24242585fd70 Warn user if we failed to get a token using his credentials.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2337
diff changeset
179 self.commands_out.put_nowait(warning)
2350
61829d040c63 Don't send html-formatted notifications.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2342
diff changeset
180
2653
11447cada25e Fix layering violation in xmlrpcbot code, as mentioned in TODO.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2650
diff changeset
181 def _get_multicall_result(self, jid):
11447cada25e Fix layering violation in xmlrpcbot code, as mentioned in TODO.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2650
diff changeset
182 """Returns multicall results and issues a warning if there's an auth error
2659
892055d122fb Handle process/thread termination gracefully.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2653
diff changeset
183
2653
11447cada25e Fix layering violation in xmlrpcbot code, as mentioned in TODO.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2650
diff changeset
184 @param jid: a full JID to use if there's an error
11447cada25e Fix layering violation in xmlrpcbot code, as mentioned in TODO.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2650
diff changeset
185 @type jid: str
2659
892055d122fb Handle process/thread termination gracefully.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2653
diff changeset
186
2653
11447cada25e Fix layering violation in xmlrpcbot code, as mentioned in TODO.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2650
diff changeset
187 """
11447cada25e Fix layering violation in xmlrpcbot code, as mentioned in TODO.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2650
diff changeset
188
11447cada25e Fix layering violation in xmlrpcbot code, as mentioned in TODO.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2650
diff changeset
189 if not self.token:
11447cada25e Fix layering violation in xmlrpcbot code, as mentioned in TODO.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2650
diff changeset
190 result = self.multicall()[0]
11447cada25e Fix layering violation in xmlrpcbot code, as mentioned in TODO.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2650
diff changeset
191 token_result = u"FAILURE"
11447cada25e Fix layering violation in xmlrpcbot code, as mentioned in TODO.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2650
diff changeset
192 else:
11447cada25e Fix layering violation in xmlrpcbot code, as mentioned in TODO.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2650
diff changeset
193 token_result, result = self.multicall()
11447cada25e Fix layering violation in xmlrpcbot code, as mentioned in TODO.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2650
diff changeset
194
11447cada25e Fix layering violation in xmlrpcbot code, as mentioned in TODO.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2650
diff changeset
195 if token_result != u"SUCCESS":
11447cada25e Fix layering violation in xmlrpcbot code, as mentioned in TODO.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2650
diff changeset
196 self.warn_no_credentials(jid)
11447cada25e Fix layering violation in xmlrpcbot code, as mentioned in TODO.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2650
diff changeset
197
11447cada25e Fix layering violation in xmlrpcbot code, as mentioned in TODO.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2650
diff changeset
198 return result
11447cada25e Fix layering violation in xmlrpcbot code, as mentioned in TODO.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2650
diff changeset
199
11447cada25e Fix layering violation in xmlrpcbot code, as mentioned in TODO.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2650
diff changeset
200
2121
ae2134211ac1 XMPP -> wiki XML RPC, the beginning...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2118
diff changeset
201 def get_page(self, command):
2127
42232c6ac004 Remove code duplication in xmlrpcbot, initial support for getPageInfo()
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2125
diff changeset
202 """Returns a raw page"""
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
203
2127
42232c6ac004 Remove code duplication in xmlrpcbot, initial support for getPageInfo()
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2125
diff changeset
204 self.multicall.getPage(command.pagename)
2653
11447cada25e Fix layering violation in xmlrpcbot code, as mentioned in TODO.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2650
diff changeset
205 command.data = self._get_multicall_result(command.jid)
2629
5dac44252ca6 Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2626
diff changeset
206
2127
42232c6ac004 Remove code duplication in xmlrpcbot, initial support for getPageInfo()
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2125
diff changeset
207 get_page = _xmlrpc_decorator(get_page)
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
208
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
209
2121
ae2134211ac1 XMPP -> wiki XML RPC, the beginning...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2118
diff changeset
210 def get_page_html(self, command):
2127
42232c6ac004 Remove code duplication in xmlrpcbot, initial support for getPageInfo()
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2125
diff changeset
211 """Returns a html-formatted page"""
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
212
2127
42232c6ac004 Remove code duplication in xmlrpcbot, initial support for getPageInfo()
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2125
diff changeset
213 self.multicall.getPageHTML(command.pagename)
2653
11447cada25e Fix layering violation in xmlrpcbot code, as mentioned in TODO.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2650
diff changeset
214 command.data = self._get_multicall_result(command.jid)
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
215
2127
42232c6ac004 Remove code duplication in xmlrpcbot, initial support for getPageInfo()
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2125
diff changeset
216 get_page_html = _xmlrpc_decorator(get_page_html)
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
217
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
218
2125
9d5f4ba23a54 Add a GetPageList command. Some code duplication to be refactored later.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2123
diff changeset
219 def get_page_list(self, command):
2127
42232c6ac004 Remove code duplication in xmlrpcbot, initial support for getPageInfo()
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2125
diff changeset
220 """Returns a list of all accesible pages"""
2629
5dac44252ca6 Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2626
diff changeset
221
2626
a791fc964e09 Attempt to move i18n from xmlrpc to xmpp thread.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2504
diff changeset
222 # Dummy function, so that the string appears in a .po file
a791fc964e09 Attempt to move i18n from xmlrpc to xmpp thread.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2504
diff changeset
223 _ = lambda x: x
2629
5dac44252ca6 Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2626
diff changeset
224
2635
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
225 cmd_data = {'text': _("This command may take a while to complete, please be patient...")}
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
226 info = cmd.NotificationCommandI18n([command.jid], cmd_data, async=False, msg_type=u"chat")
2125
9d5f4ba23a54 Add a GetPageList command. Some code duplication to be refactored later.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2123
diff changeset
227 self.commands_out.put_nowait(info)
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
228
2127
42232c6ac004 Remove code duplication in xmlrpcbot, initial support for getPageInfo()
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2125
diff changeset
229 self.multicall.getAllPages()
2653
11447cada25e Fix layering violation in xmlrpcbot code, as mentioned in TODO.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2650
diff changeset
230 command.data = self._get_multicall_result(command.jid)
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
231
2127
42232c6ac004 Remove code duplication in xmlrpcbot, initial support for getPageInfo()
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2125
diff changeset
232 get_page_list = _xmlrpc_decorator(get_page_list)
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
233
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
234
2127
42232c6ac004 Remove code duplication in xmlrpcbot, initial support for getPageInfo()
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2125
diff changeset
235 def get_page_info(self, command):
42232c6ac004 Remove code duplication in xmlrpcbot, initial support for getPageInfo()
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2125
diff changeset
236 """Returns detailed information about a given page"""
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
237
2127
42232c6ac004 Remove code duplication in xmlrpcbot, initial support for getPageInfo()
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2125
diff changeset
238 self.multicall.getPageInfo(command.pagename)
2653
11447cada25e Fix layering violation in xmlrpcbot code, as mentioned in TODO.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2650
diff changeset
239 command.data = self._get_multicall_result(command.jid)
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
240
2127
42232c6ac004 Remove code duplication in xmlrpcbot, initial support for getPageInfo()
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2125
diff changeset
241 get_page_info = _xmlrpc_decorator(get_page_info)
2068
7e2a9b7d2bc6 XML RPC functionality for the notification bot - the beginning
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
242
2650
2b4be3be9835 First implementation of search, will be changed later to optionally use oob.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2647
diff changeset
243 def do_search(self, command):
2b4be3be9835 First implementation of search, will be changed later to optionally use oob.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2647
diff changeset
244 """Performs a search"""
2b4be3be9835 First implementation of search, will be changed later to optionally use oob.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2647
diff changeset
245
2653
11447cada25e Fix layering violation in xmlrpcbot code, as mentioned in TODO.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2650
diff changeset
246 # Dummy function, so that the string appears in a .po file
2650
2b4be3be9835 First implementation of search, will be changed later to optionally use oob.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2647
diff changeset
247 _ = lambda x: x
2b4be3be9835 First implementation of search, will be changed later to optionally use oob.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2647
diff changeset
248
2b4be3be9835 First implementation of search, will be changed later to optionally use oob.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2647
diff changeset
249 cmd_data = {'text': _("This command may take a while to complete, please be patient...")}
2b4be3be9835 First implementation of search, will be changed later to optionally use oob.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2647
diff changeset
250 info = cmd.NotificationCommandI18n([command.jid], cmd_data, async=False, msg_type=u"chat")
2b4be3be9835 First implementation of search, will be changed later to optionally use oob.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2647
diff changeset
251 self.commands_out.put_nowait(info)
2b4be3be9835 First implementation of search, will be changed later to optionally use oob.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2647
diff changeset
252
2b4be3be9835 First implementation of search, will be changed later to optionally use oob.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2647
diff changeset
253 c = command
2b4be3be9835 First implementation of search, will be changed later to optionally use oob.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2647
diff changeset
254 self.multicall.searchPagesEx(c.term, c.search_type, 30, c.case, c.mtime, c.regexp)
2653
11447cada25e Fix layering violation in xmlrpcbot code, as mentioned in TODO.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2650
diff changeset
255 command.data = self._get_multicall_result(command.jid)
2650
2b4be3be9835 First implementation of search, will be changed later to optionally use oob.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2647
diff changeset
256
2b4be3be9835 First implementation of search, will be changed later to optionally use oob.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2647
diff changeset
257 do_search = _xmlrpc_decorator(do_search)
2b4be3be9835 First implementation of search, will be changed later to optionally use oob.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2647
diff changeset
258
2671
9bc7d2c14e1f Add suport for reverting pages (text-only for now).
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2659
diff changeset
259 def do_revert(self, command):
9bc7d2c14e1f Add suport for reverting pages (text-only for now).
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2659
diff changeset
260 """Performs a page revert"""
9bc7d2c14e1f Add suport for reverting pages (text-only for now).
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2659
diff changeset
261
9bc7d2c14e1f Add suport for reverting pages (text-only for now).
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2659
diff changeset
262 # Dummy function, so that the string appears in a .po file
9bc7d2c14e1f Add suport for reverting pages (text-only for now).
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2659
diff changeset
263 _ = lambda x: x
9bc7d2c14e1f Add suport for reverting pages (text-only for now).
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2659
diff changeset
264
9bc7d2c14e1f Add suport for reverting pages (text-only for now).
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2659
diff changeset
265 self.multicall.revertPage(command.pagename, command.revision)
9bc7d2c14e1f Add suport for reverting pages (text-only for now).
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2659
diff changeset
266 data = self._get_multicall_result(command.jid)
9bc7d2c14e1f Add suport for reverting pages (text-only for now).
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2659
diff changeset
267
9bc7d2c14e1f Add suport for reverting pages (text-only for now).
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2659
diff changeset
268 if type(data) == bool and data:
9bc7d2c14e1f Add suport for reverting pages (text-only for now).
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2659
diff changeset
269 cmd_data = {'text': _("Page has been reverted.")}
9bc7d2c14e1f Add suport for reverting pages (text-only for now).
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2659
diff changeset
270 elif isinstance(str, data) or isinstance(unicode, data):
9bc7d2c14e1f Add suport for reverting pages (text-only for now).
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2659
diff changeset
271 cmd_data = {'text': _("Revert failed: %(reason)s" % {'reason': data})}
9bc7d2c14e1f Add suport for reverting pages (text-only for now).
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2659
diff changeset
272 else:
9bc7d2c14e1f Add suport for reverting pages (text-only for now).
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2659
diff changeset
273 cmd_data = {'text': _("Revert failed.")}
9bc7d2c14e1f Add suport for reverting pages (text-only for now).
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2659
diff changeset
274
2678
00b746e6be07 Translate revert notifications.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2671
diff changeset
275 info = cmd.NotificationCommandI18n([command.jid], cmd_data, async=False, msg_type=u"chat")
2671
9bc7d2c14e1f Add suport for reverting pages (text-only for now).
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2659
diff changeset
276 self.commands_out.put_nowait(info)
9bc7d2c14e1f Add suport for reverting pages (text-only for now).
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2659
diff changeset
277
9bc7d2c14e1f Add suport for reverting pages (text-only for now).
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2659
diff changeset
278 do_revert = _xmlrpc_decorator(do_revert)
9bc7d2c14e1f Add suport for reverting pages (text-only for now).
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2659
diff changeset
279
2461
f456dc2048d1 i18n should now work. First step, no caching yet.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2413
diff changeset
280 def get_language_by_jid(self, command):
f456dc2048d1 i18n should now work. First step, no caching yet.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2413
diff changeset
281 """Returns language of the a user identified by the given JID"""
f456dc2048d1 i18n should now work. First step, no caching yet.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2413
diff changeset
282
f456dc2048d1 i18n should now work. First step, no caching yet.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2413
diff changeset
283 server = xmlrpclib.ServerProxy(self.config.wiki_url + "?action=xmlrpc2")
2481
4030f9321319 Fix local variable reference prior to assignment.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2480
diff changeset
284 language = "en"
2483
41e79a4df6b6 Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2481
diff changeset
285
2480
b0185066e802 Handle exceptions in get_language_by_jid
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2461
diff changeset
286 try:
b0185066e802 Handle exceptions in get_language_by_jid
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2461
diff changeset
287 language = server.getUserLanguageByJID(command.jid)
b0185066e802 Handle exceptions in get_language_by_jid
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2461
diff changeset
288 except xmlrpclib.Fault, fault:
b0185066e802 Handle exceptions in get_language_by_jid
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2461
diff changeset
289 self.log.error(str(fault))
b0185066e802 Handle exceptions in get_language_by_jid
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2461
diff changeset
290 except xmlrpclib.Error, err:
b0185066e802 Handle exceptions in get_language_by_jid
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2461
diff changeset
291 self.log.error(str(err))
b0185066e802 Handle exceptions in get_language_by_jid
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2461
diff changeset
292 except Exception, exc:
b0185066e802 Handle exceptions in get_language_by_jid
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2461
diff changeset
293 self.log.critical(str(exc))
2461
f456dc2048d1 i18n should now work. First step, no caching yet.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2413
diff changeset
294
2481
4030f9321319 Fix local variable reference prior to assignment.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2480
diff changeset
295 command.language = language
2461
f456dc2048d1 i18n should now work. First step, no caching yet.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2413
diff changeset
296 self.commands_out.put_nowait(command)
f456dc2048d1 i18n should now work. First step, no caching yet.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2413
diff changeset
297
2088
a99ed13fec1e Introduce a shared secret for wiki-bot communication + some code style fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2084
diff changeset
298
2084
5e0c667c79cb Don't inherit SimpleXMLRPCServer, it's dangerous.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2083
diff changeset
299 class XMLRPCServer(Thread):
2068
7e2a9b7d2bc6 XML RPC functionality for the notification bot - the beginning
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
300 """XMLRPC Server
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
301
2068
7e2a9b7d2bc6 XML RPC functionality for the notification bot - the beginning
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
302 It waits for notifications requests coming from wiki,
7e2a9b7d2bc6 XML RPC functionality for the notification bot - the beginning
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
303 creates command objects and puts them on a queue for
2071
aa761813d7bd Silly changes to test CIA.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2070
diff changeset
304 later processing by the XMPP component
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
305
2071
aa761813d7bd Silly changes to test CIA.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2070
diff changeset
306 @param commands: an input command queue
aa761813d7bd Silly changes to test CIA.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2070
diff changeset
307 """
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
308
2070
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2068
diff changeset
309 def __init__(self, config, commands):
2068
7e2a9b7d2bc6 XML RPC functionality for the notification bot - the beginning
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
310 Thread.__init__(self)
2070
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2068
diff changeset
311 self.commands = commands
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2068
diff changeset
312 self.verbose = config.verbose
3612
6f06c7d051a4 Setting a more meaningful logger name.
Karol 'grzywacz' Nowak <grywacz@gmail.com>
parents: 2957
diff changeset
313 self.log = logging.getLogger(__name__)
2647
6e323cf20c64 Fix initialisation of xmlrpcbot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2645
diff changeset
314 self.config = config
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
315
2319
10ec0e8d35e1 Make send_notification accept a list of JIDs, instead of one.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2167
diff changeset
316 if config.secret:
10ec0e8d35e1 Make send_notification accept a list of JIDs, instead of one.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2167
diff changeset
317 self.secret = config.secret
10ec0e8d35e1 Make send_notification accept a list of JIDs, instead of one.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2167
diff changeset
318 else:
2635
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
319 error = "You must set a (long) secret string"
2322
4b4868ae88f0 Replace prints with stdlib's logging features.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2319
diff changeset
320 self.log.critical(error)
4b4868ae88f0 Replace prints with stdlib's logging features.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2319
diff changeset
321 raise ConfigurationError(error)
2645
3f499601e702 Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2641
diff changeset
322
2641
b0a8154e8874 Create SimpleXMLRPCServer when the thread is actually started.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2638
diff changeset
323 self.server = None
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
324
2070
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2068
diff changeset
325 def run(self):
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2068
diff changeset
326 """Starts the server / thread"""
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
327
2647
6e323cf20c64 Fix initialisation of xmlrpcbot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2645
diff changeset
328 self.server = SimpleXMLRPCServer((self.config.xmlrpc_host, self.config.xmlrpc_port))
2645
3f499601e702 Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2641
diff changeset
329
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
330 # Register methods having an "export" attribute as XML RPC functions and
2096
b37dd51e566e Use decorators to assure that shared secret is always checked. Add 2 commands.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2089
diff changeset
331 # decorate them with a check for a shared (wiki-bot) secret.
b37dd51e566e Use decorators to assure that shared secret is always checked. Add 2 commands.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2089
diff changeset
332 items = self.__class__.__dict__.items()
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
333 methods = [(name, func) for (name, func) in items if callable(func)
2096
b37dd51e566e Use decorators to assure that shared secret is always checked. Add 2 commands.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2089
diff changeset
334 and "export" in func.__dict__]
b37dd51e566e Use decorators to assure that shared secret is always checked. Add 2 commands.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2089
diff changeset
335
b37dd51e566e Use decorators to assure that shared secret is always checked. Add 2 commands.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2089
diff changeset
336 for name, func in methods:
b37dd51e566e Use decorators to assure that shared secret is always checked. Add 2 commands.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2089
diff changeset
337 self.server.register_function(self.secret_check(func), name)
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
338
2084
5e0c667c79cb Don't inherit SimpleXMLRPCServer, it's dangerous.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2083
diff changeset
339 self.server.serve_forever()
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2167
diff changeset
340
2096
b37dd51e566e Use decorators to assure that shared secret is always checked. Add 2 commands.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2089
diff changeset
341 def secret_check(self, function):
b37dd51e566e Use decorators to assure that shared secret is always checked. Add 2 commands.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2089
diff changeset
342 """Adds a check for a secret to a given function
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
343
2096
b37dd51e566e Use decorators to assure that shared secret is always checked. Add 2 commands.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2089
diff changeset
344 Using this one does not have to worry about checking for the secret
b37dd51e566e Use decorators to assure that shared secret is always checked. Add 2 commands.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2089
diff changeset
345 in every XML RPC function.
b37dd51e566e Use decorators to assure that shared secret is always checked. Add 2 commands.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2089
diff changeset
346 """
b37dd51e566e Use decorators to assure that shared secret is always checked. Add 2 commands.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2089
diff changeset
347 def protected_func(secret, *args):
b37dd51e566e Use decorators to assure that shared secret is always checked. Add 2 commands.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2089
diff changeset
348 if secret != self.secret:
2626
a791fc964e09 Attempt to move i18n from xmlrpc to xmpp thread.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2504
diff changeset
349 raise xmlrpclib.Fault(1, "You are not allowed to use this bot!")
2096
b37dd51e566e Use decorators to assure that shared secret is always checked. Add 2 commands.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2089
diff changeset
350 else:
b37dd51e566e Use decorators to assure that shared secret is always checked. Add 2 commands.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2089
diff changeset
351 return function(self, *args)
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
352
2096
b37dd51e566e Use decorators to assure that shared secret is always checked. Add 2 commands.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2089
diff changeset
353 return protected_func
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
354
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
355
2635
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
356 def send_notification(self, jids, notification):
2116
7f579f5fd44b Improve docstrings. s/type/msgtype/ to avoid name conflict with builtin.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2110
diff changeset
357 """Instructs the XMPP component to send a notification
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
358
2638
6e84127a1860 Finally all known bugs fixed, OOB is used to send links with jabber. More...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2635
diff changeset
359 The notification dict has following entries:
6e84127a1860 Finally all known bugs fixed, OOB is used to send links with jabber. More...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2635
diff changeset
360 'text' - notification text (REQUIRED)
6e84127a1860 Finally all known bugs fixed, OOB is used to send links with jabber. More...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2635
diff changeset
361 'subject' - notification subject
6e84127a1860 Finally all known bugs fixed, OOB is used to send links with jabber. More...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2635
diff changeset
362 'url_list' - a list of dicts describing attached URLs
6e84127a1860 Finally all known bugs fixed, OOB is used to send links with jabber. More...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2635
diff changeset
363
2332
456545b5acfe Handle errors in get_auth_token() gracefully, fix a comment.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2322
diff changeset
364 @param jids: a list of JIDs to send a message to (bare JIDs)
456545b5acfe Handle errors in get_auth_token() gracefully, fix a comment.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2322
diff changeset
365 @type jids: a list of str or unicode
2638
6e84127a1860 Finally all known bugs fixed, OOB is used to send links with jabber. More...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2635
diff changeset
366 @param notification: dictionary with notification data
6e84127a1860 Finally all known bugs fixed, OOB is used to send links with jabber. More...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2635
diff changeset
367 @type notification: dict
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
368
2116
7f579f5fd44b Improve docstrings. s/type/msgtype/ to avoid name conflict with builtin.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2110
diff changeset
369 """
2635
8ec6cc1a909f Change argument passing in notifications; some pylint and event.name fixes too
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2632
diff changeset
370 command = cmd.NotificationCommand(jids, notification, async=True)
2131
ea879bd7935d Fix some names as pointed out by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2128
diff changeset
371 self.commands.put_nowait(command)
2070
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2068
diff changeset
372 return True
2096
b37dd51e566e Use decorators to assure that shared secret is always checked. Add 2 commands.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2089
diff changeset
373 send_notification.export = True
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
374
2096
b37dd51e566e Use decorators to assure that shared secret is always checked. Add 2 commands.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2089
diff changeset
375 def addJIDToRoster(self, jid):
2116
7f579f5fd44b Improve docstrings. s/type/msgtype/ to avoid name conflict with builtin.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2110
diff changeset
376 """Instructs the XMPP component to add a new JID to its roster
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
377
2116
7f579f5fd44b Improve docstrings. s/type/msgtype/ to avoid name conflict with builtin.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2110
diff changeset
378 @param jid: a jid to add, this must be a bare jid
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
379 @type jid: str or unicode,
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
380
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
381 """
2131
ea879bd7935d Fix some names as pointed out by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2128
diff changeset
382 command = cmd.AddJIDToRosterCommand(jid)
ea879bd7935d Fix some names as pointed out by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2128
diff changeset
383 self.commands.put_nowait(command)
2096
b37dd51e566e Use decorators to assure that shared secret is always checked. Add 2 commands.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2089
diff changeset
384 return True
b37dd51e566e Use decorators to assure that shared secret is always checked. Add 2 commands.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2089
diff changeset
385 addJIDToRoster.export = True
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
386
2096
b37dd51e566e Use decorators to assure that shared secret is always checked. Add 2 commands.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2089
diff changeset
387 def removeJIDFromRoster(self, jid):
2116
7f579f5fd44b Improve docstrings. s/type/msgtype/ to avoid name conflict with builtin.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2110
diff changeset
388 """Instructs the XMPP component to remove a JID from its roster
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
389
2116
7f579f5fd44b Improve docstrings. s/type/msgtype/ to avoid name conflict with builtin.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2110
diff changeset
390 @param jid: a jid to remove, this must be a bare jid
7f579f5fd44b Improve docstrings. s/type/msgtype/ to avoid name conflict with builtin.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2110
diff changeset
391 @type jid: str or unicode
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
392
2116
7f579f5fd44b Improve docstrings. s/type/msgtype/ to avoid name conflict with builtin.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2110
diff changeset
393 """
2131
ea879bd7935d Fix some names as pointed out by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2128
diff changeset
394 command = cmd.RemoveJIDFromRosterCommand(jid)
ea879bd7935d Fix some names as pointed out by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2128
diff changeset
395 self.commands.put_nowait(command)
2096
b37dd51e566e Use decorators to assure that shared secret is always checked. Add 2 commands.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2089
diff changeset
396 return True
b37dd51e566e Use decorators to assure that shared secret is always checked. Add 2 commands.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2089
diff changeset
397 removeJIDFromRoster.export = True