Merge lp:~stefanor/ibid/calc-525439 into lp:~ibid-core/ibid/old-trunk-1.6

Proposed by Stefano Rivera
Status: Superseded
Proposed branch: lp:~stefanor/ibid/calc-525439
Merge into: lp:~ibid-core/ibid/old-trunk-1.6
Diff against target: 86 lines (+23/-15)
2 files modified
ibid/plugins/__init__.py (+13/-12)
ibid/plugins/calc.py (+10/-3)
To merge this branch: bzr merge lp:~stefanor/ibid/calc-525439
Reviewer Review Type Date Requested Status
Michael Gorven Approve
Review via email: mp+19951@code.launchpad.net

This proposal supersedes a proposal from 2010-02-21.

This proposal has been superseded by a proposal from 2010-02-23.

To post a comment you must log in.
Revision history for this message
Michael Gorven (mgorven) wrote : Posted in a previous version of this proposal

 review approve

review: Approve
Revision history for this message
Michael Gorven (mgorven) wrote :

Hackity hack...
 review approve

review: Approve
lp:~stefanor/ibid/calc-525439 updated
894. By Stefano Rivera

Allow subclassing Processors

895. By Stefano Rivera

Subclass Clac cleanly

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ibid/plugins/__init__.py'
2--- ibid/plugins/__init__.py 2010-02-03 15:04:43 +0000
3+++ ibid/plugins/__init__.py 2010-02-23 11:47:13 +0000
4@@ -62,16 +62,17 @@
5 new.default = getattr(cls, name)
6 setattr(cls, name, new)
7
8- if getattr(cls, '_event_handlers', None) is None:
9- cls._event_handlers = []
10- for name, item in cls.__dict__.iteritems():
11- if getattr(item, 'handler', False):
12- cls._event_handlers.append(name)
13- if getattr(cls, '_periodic_handlers', None) is None:
14- cls._periodic_handlers = []
15- for name, item in cls.__dict__.iteritems():
16- if getattr(item, 'periodic', False):
17- cls._periodic_handlers.append(name)
18+ for attr, listname in (
19+ ('handler', 'event'),
20+ ('periodic', 'periodic')):
21+ listname = '_Processor__%s_handlers' % listname
22+ if not hasattr(cls, listname):
23+ setattr(cls, listname, [])
24+ handlers = getattr(cls, listname)
25+
26+ for name, item in cls.__dict__.iteritems():
27+ if getattr(item, attr, False) and name not in handlers:
28+ handlers.append(name)
29
30 return super(Processor, cls).__new__(cls)
31
32@@ -127,12 +128,12 @@
33
34 def _get_event_handlers(self):
35 "Find all the handlers (regex matching and blind)"
36- for handler in self._event_handlers:
37+ for handler in self._event_handlers or self.__event_handlers:
38 yield getattr(self, handler)
39
40 def _get_periodic_handlers(self):
41 "Find all the periodic handlers"
42- for handler in self._periodic_handlers:
43+ for handler in self._periodic_handlers or self.__periodic_handlers:
44 yield getattr(self, handler)
45
46 def _run_periodic_handler(self, method, event):
47
48=== modified file 'ibid/plugins/calc.py'
49--- ibid/plugins/calc.py 2010-01-18 23:20:33 +0000
50+++ ibid/plugins/calc.py 2010-02-23 11:47:13 +0000
51@@ -2,10 +2,9 @@
52 # Released under terms of the MIT/X/Expat Licence. See COPYING for details.
53
54 from __future__ import division
55-from random import random, randint
56-
57 import logging
58 from os import kill
59+from random import random, randint
60 from signal import SIGTERM
61 from subprocess import Popen, PIPE
62 from time import time, sleep
63@@ -151,7 +150,7 @@
64 safe['pow'] = limited_pow
65 safe['factorial'] = limited_factorial
66
67- @match(r'^(?:calc\s+)?(.+?)$')
68+ @match(r'^(.+)$')
69 def calculate(self, event, expression):
70 for term in self.banned:
71 if term in expression:
72@@ -193,6 +192,14 @@
73 if isinstance(result, (int, long, float, complex)):
74 event.addresponse(unicode(result))
75
76+
77+class ExplicitCalc(Calc):
78+ priority = 0
79+
80+ @match(r'^calc(?:ulate)?\s+(.+)$')
81+ def calculate(self, event, expression):
82+ super(ExplicitCalc, self).calculate(event, expression)
83+
84 help['random'] = u'Generates random numbers.'
85 class Random(Processor):
86 u"""random [ <max> | <min> <max> ]"""

Subscribers

People subscribed via source and target branches