Merge lp:~stefanor/ibid/factoid-330901 into lp:~ibid-core/ibid/old-trunk-pack-0.92

Proposed by Stefano Rivera
Status: Merged
Approved by: Stefano Rivera
Approved revision: 573
Merged at revision: 569
Proposed branch: lp:~stefanor/ibid/factoid-330901
Merge into: lp:~ibid-core/ibid/old-trunk-pack-0.92
Diff against target: None lines
To merge this branch: bzr merge lp:~stefanor/ibid/factoid-330901
Reviewer Review Type Date Requested Status
Jonathan Hitchcock Approve
Michael Gorven Approve
Review via email: mp+4255@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Stefano Rivera (stefanor) wrote :

This one took an hour longer than I expected. Bedtime...

lp:~stefanor/ibid/factoid-330901 updated
564. By Stefano Rivera

Regex splitting couldn't handle every quoting case. More procedural splitter

565. By Stefano Rivera

Remove leftover debugging

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

I don't like the AuthExceptions. We already have a mechanism for handling auth
failures which works fine with factoids. Modify stuff seems fine, although I
had an issue with a pattern matching multiple values even though it should
only match one. The SQLAlchemy stuff in factoids is still a bit dodgy... :-/
 review needs_fixing

review: Needs Fixing
lp:~stefanor/ibid/factoid-330901 updated
566. By Stefano Rivera

Mea culpa - misunderstood the auth mechanisms

Revision history for this message
Stefano Rivera (stefanor) wrote :

"I don't like the AuthExceptions."

Try r566

lp:~stefanor/ibid/factoid-330901 updated
567. By Stefano Rivera

Don't use real regexs by default in ~=

568. By Stefano Rivera

Don't use real regexes by default in //

569. By Stefano Rivera

Better errors for += and ~=

570. By Stefano Rivera

Make the perl-mongers happy (support for =~)

571. By Stefano Rivera

Missing bit of help string

572. By Stefano Rivera

New syntax for search operation

Revision history for this message
Michael Gorven (mgorven) :
review: Approve
lp:~stefanor/ibid/factoid-330901 updated
573. By Stefano Rivera

Merge from trunk

Revision history for this message
Jonathan Hitchcock (vhata) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ibid/core.py'
2--- ibid/core.py 2009-03-01 14:29:51 +0000
3+++ ibid/core.py 2009-03-06 21:37:36 +0000
4@@ -191,7 +191,7 @@
5 self.log.info(u"Notified all processors of config reload")
6
7 def regexp(pattern, item):
8- return re.search(pattern, item) and True or False
9+ return re.search(pattern, item, re.I) and True or False
10
11 def sqlite_creator(database):
12 from pysqlite2 import dbapi2 as sqlite
13
14=== modified file 'ibid/plugins/factoid.py'
15--- ibid/plugins/factoid.py 2009-03-01 23:01:30 +0000
16+++ ibid/plugins/factoid.py 2009-03-06 23:17:10 +0000
17@@ -101,7 +101,7 @@
18 session.close()
19
20 class Forget(Processor):
21- u"""forget <name>
22+ u"""forget <name> [( #<number> | /<pattern>/ )]
23 <name> is the same as <other name>"""
24 feature = 'factoids'
25
26@@ -124,10 +124,12 @@
27 return
28
29 if factoids[0][2].identity_id not in identities and not factoidadmin:
30+ raise ibid.AuthException(u"You are not permitted to do that")
31 return
32
33 if session.query(FactoidValue).filter_by(factoid_id=factoid.id).count() == 1:
34 if len(filter(lambda x: x.identity_id not in identities, factoid.names)) > 0 and not factoidadmin:
35+ raise ibid.AuthException(u"You are not permitted to do that")
36 return
37 log.info(u"Deleting factoid %s (%s) by %s/%s (%s)", factoid.id, name, event.account, event.identity, event.sender['connection'])
38 session.delete(factoid)
39@@ -137,10 +139,12 @@
40
41 else:
42 if factoids[0][1].identity_id not in identities and not factoidadmin:
43+ raise ibid.AuthException(u"You are not permitted to do that")
44 return
45
46 if session.query(FactoidName).filter_by(factoid_id=factoid.id).count() == 1:
47 if len(filter(lambda x: x.identity_id not in identities, factoid.values)) > 0 and not factoidadmin:
48+ raise ibid.AuthException(u"You are not permitted to do that")
49 return
50 log.info(u"Deleting factoid %s (%s) by %s/%s (%s)", factoid.id, name, event.account, event.identity, event.sender['connection'])
51 session.delete(factoid)
52@@ -159,6 +163,7 @@
53 def alias(self, event, target, source):
54
55 if target.lower() == source.lower():
56+ event.addresponse(u"That makes no sense, they *are* the same")
57 return
58
59 session = ibid.databases.ibid()
60@@ -289,6 +294,7 @@
61 if correction:
62 identities = get_identities(event, session)
63 if not auth_responses(event, u'factoidadmin') and len(filter(lambda x: x.identity_id not in identities, factoid.values)) > 0:
64+ raise ibid.AuthException(u"You are not permitted to do that")
65 return
66 for fvalue in factoid.values:
67 session.delete(fvalue)
68@@ -312,4 +318,92 @@
69 session.close()
70 event.addresponse(True)
71
72+class Modify(Processor):
73+ u"""<name> [( #<number> | /<pattern>/ )] += <suffix>
74+ <name> [( #<number> | /<pattern>/ )] ~= ( s/<regex>/<replacement>/[g][i] | y/<source>/<dest>/ )"""
75+ feature = 'factoids'
76+
77+ permission = u'factoid'
78+ permissions = (u'factoidadmin',)
79+ priority = 890
80+
81+ @match(r'^(.+?)(?:\s+#(\d+)|\s+/(.+?)/)?\s*\+=\s?(.+)$')
82+ @authorise
83+ def append(self, event, name, number, pattern, suffix):
84+ session = ibid.databases.ibid()
85+ factoids = get_factoid(session, name, number, pattern, True)
86+ if len(factoids) == 0:
87+ event.addresponse(u"I didn't know about %s anyway" % name)
88+ elif len(factoids) > 1:
89+ event.addresponse(u"Pattern matches multiple factoids, please be more specific")
90+ else:
91+ factoidadmin = auth_responses(event, u'factoidadmin')
92+ identities = get_identities(event, session)
93+ factoid = factoids[0]
94+
95+ if factoid[2].identity_id not in identities and not factoidadmin:
96+ raise ibid.AuthException(u"You are not permitted to do that")
97+ return
98+
99+ log.info(u"Appending '%s' to value %s of factoid %s (%s) by %s/%s (%s)",
100+ suffix, factoid[2].id, factoid[0].id, factoid[2].value, event.account, event.identity, event.sender['connection'])
101+ factoid[2].value += suffix
102+
103+ session.flush()
104+ session.close()
105+ event.addresponse(True)
106+
107+ @match(r'^(.+?)(?:\s+#(\d+)|\s+/(.+?)/)?\s*~=\s*([sy](?P<sep>.).+(?P=sep).+(?P=sep)[g]?[i]?)$')
108+ @authorise
109+ def modify(self, event, name, number, pattern, operation, separator):
110+ session = ibid.databases.ibid()
111+ factoids = get_factoid(session, name, number, pattern, True)
112+ if len(factoids) == 0:
113+ event.addresponse(u"I didn't know about %s anyway" % name)
114+ elif len(factoids) > 1:
115+ event.addresponse(u"Pattern matches multiple factoids, please be more specific")
116+ else:
117+ factoidadmin = auth_responses(event, u'factoidadmin')
118+ identities = get_identities(event, session)
119+ factoid = factoids[0]
120+
121+ if factoid[2].identity_id not in identities and not factoidadmin:
122+ raise ibid.AuthException(u"You are not permitted to do that")
123+ return
124+
125+ if separator in ("^", "]"):
126+ separator = '\\' + separator
127+ parts = re.split(r"(?<=[^\\])[%s]" % separator, operation)
128+ if len(parts) != 4:
129+ event.addresponse(u"That operation makes no sense. Work on your regex-fu.")
130+ return
131+
132+ op, search, replace, flags = parts
133+ if op == "s":
134+ if "i" in flags.lower():
135+ search += "(?i)"
136+ try:
137+ factoid[2].value, subs = re.subn(search, replace, factoid[2].value, int("g" not in flags))
138+ except:
139+ event.addresponse(u"That operation makes no sense. Try something like s/foo/bar/")
140+ return
141+
142+ elif op == "y":
143+ if len(search) != len(replace):
144+ event.addresponse(u"That operation makes no sense. The source and destination must be the same length.")
145+ return
146+ try:
147+ table = dict((ord(x), ord(y)) for x, y in zip(search, replace))
148+ factoid[2].value = factoid[2].value.translate(table)
149+
150+ except:
151+ event.addresponse(u"That operation makes no sense. Try something like y/abcdef/ABCDEF/")
152+ return
153+
154+ log.info(u"Applying '%s' to value %s of factoid %s (%s) by %s/%s (%s)",
155+ operation, factoid[2].id, factoid[0].id, factoid[2].value, event.account, event.identity, event.sender['connection'])
156+
157+ session.flush()
158+ session.close()
159+ event.addresponse(True)
160 # vi: set et sta sw=4 ts=4:

Subscribers

People subscribed via source and target branches