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
=== modified file 'ibid/core.py'
--- ibid/core.py 2009-03-01 14:29:51 +0000
+++ ibid/core.py 2009-03-06 21:37:36 +0000
@@ -191,7 +191,7 @@
191 self.log.info(u"Notified all processors of config reload")191 self.log.info(u"Notified all processors of config reload")
192192
193def regexp(pattern, item):193def regexp(pattern, item):
194 return re.search(pattern, item) and True or False194 return re.search(pattern, item, re.I) and True or False
195195
196def sqlite_creator(database):196def sqlite_creator(database):
197 from pysqlite2 import dbapi2 as sqlite197 from pysqlite2 import dbapi2 as sqlite
198198
=== modified file 'ibid/plugins/factoid.py'
--- ibid/plugins/factoid.py 2009-03-01 23:01:30 +0000
+++ ibid/plugins/factoid.py 2009-03-06 23:17:10 +0000
@@ -101,7 +101,7 @@
101 session.close()101 session.close()
102102
103class Forget(Processor):103class Forget(Processor):
104 u"""forget <name>104 u"""forget <name> [( #<number> | /<pattern>/ )]
105 <name> is the same as <other name>"""105 <name> is the same as <other name>"""
106 feature = 'factoids'106 feature = 'factoids'
107107
@@ -124,10 +124,12 @@
124 return124 return
125125
126 if factoids[0][2].identity_id not in identities and not factoidadmin:126 if factoids[0][2].identity_id not in identities and not factoidadmin:
127 raise ibid.AuthException(u"You are not permitted to do that")
127 return128 return
128129
129 if session.query(FactoidValue).filter_by(factoid_id=factoid.id).count() == 1:130 if session.query(FactoidValue).filter_by(factoid_id=factoid.id).count() == 1:
130 if len(filter(lambda x: x.identity_id not in identities, factoid.names)) > 0 and not factoidadmin:131 if len(filter(lambda x: x.identity_id not in identities, factoid.names)) > 0 and not factoidadmin:
132 raise ibid.AuthException(u"You are not permitted to do that")
131 return133 return
132 log.info(u"Deleting factoid %s (%s) by %s/%s (%s)", factoid.id, name, event.account, event.identity, event.sender['connection'])134 log.info(u"Deleting factoid %s (%s) by %s/%s (%s)", factoid.id, name, event.account, event.identity, event.sender['connection'])
133 session.delete(factoid)135 session.delete(factoid)
@@ -137,10 +139,12 @@
137139
138 else:140 else:
139 if factoids[0][1].identity_id not in identities and not factoidadmin:141 if factoids[0][1].identity_id not in identities and not factoidadmin:
142 raise ibid.AuthException(u"You are not permitted to do that")
140 return143 return
141144
142 if session.query(FactoidName).filter_by(factoid_id=factoid.id).count() == 1:145 if session.query(FactoidName).filter_by(factoid_id=factoid.id).count() == 1:
143 if len(filter(lambda x: x.identity_id not in identities, factoid.values)) > 0 and not factoidadmin:146 if len(filter(lambda x: x.identity_id not in identities, factoid.values)) > 0 and not factoidadmin:
147 raise ibid.AuthException(u"You are not permitted to do that")
144 return148 return
145 log.info(u"Deleting factoid %s (%s) by %s/%s (%s)", factoid.id, name, event.account, event.identity, event.sender['connection'])149 log.info(u"Deleting factoid %s (%s) by %s/%s (%s)", factoid.id, name, event.account, event.identity, event.sender['connection'])
146 session.delete(factoid)150 session.delete(factoid)
@@ -159,6 +163,7 @@
159 def alias(self, event, target, source):163 def alias(self, event, target, source):
160164
161 if target.lower() == source.lower():165 if target.lower() == source.lower():
166 event.addresponse(u"That makes no sense, they *are* the same")
162 return167 return
163168
164 session = ibid.databases.ibid()169 session = ibid.databases.ibid()
@@ -289,6 +294,7 @@
289 if correction:294 if correction:
290 identities = get_identities(event, session)295 identities = get_identities(event, session)
291 if not auth_responses(event, u'factoidadmin') and len(filter(lambda x: x.identity_id not in identities, factoid.values)) > 0:296 if not auth_responses(event, u'factoidadmin') and len(filter(lambda x: x.identity_id not in identities, factoid.values)) > 0:
297 raise ibid.AuthException(u"You are not permitted to do that")
292 return298 return
293 for fvalue in factoid.values:299 for fvalue in factoid.values:
294 session.delete(fvalue)300 session.delete(fvalue)
@@ -312,4 +318,92 @@
312 session.close()318 session.close()
313 event.addresponse(True)319 event.addresponse(True)
314320
321class Modify(Processor):
322 u"""<name> [( #<number> | /<pattern>/ )] += <suffix>
323 <name> [( #<number> | /<pattern>/ )] ~= ( s/<regex>/<replacement>/[g][i] | y/<source>/<dest>/ )"""
324 feature = 'factoids'
325
326 permission = u'factoid'
327 permissions = (u'factoidadmin',)
328 priority = 890
329
330 @match(r'^(.+?)(?:\s+#(\d+)|\s+/(.+?)/)?\s*\+=\s?(.+)$')
331 @authorise
332 def append(self, event, name, number, pattern, suffix):
333 session = ibid.databases.ibid()
334 factoids = get_factoid(session, name, number, pattern, True)
335 if len(factoids) == 0:
336 event.addresponse(u"I didn't know about %s anyway" % name)
337 elif len(factoids) > 1:
338 event.addresponse(u"Pattern matches multiple factoids, please be more specific")
339 else:
340 factoidadmin = auth_responses(event, u'factoidadmin')
341 identities = get_identities(event, session)
342 factoid = factoids[0]
343
344 if factoid[2].identity_id not in identities and not factoidadmin:
345 raise ibid.AuthException(u"You are not permitted to do that")
346 return
347
348 log.info(u"Appending '%s' to value %s of factoid %s (%s) by %s/%s (%s)",
349 suffix, factoid[2].id, factoid[0].id, factoid[2].value, event.account, event.identity, event.sender['connection'])
350 factoid[2].value += suffix
351
352 session.flush()
353 session.close()
354 event.addresponse(True)
355
356 @match(r'^(.+?)(?:\s+#(\d+)|\s+/(.+?)/)?\s*~=\s*([sy](?P<sep>.).+(?P=sep).+(?P=sep)[g]?[i]?)$')
357 @authorise
358 def modify(self, event, name, number, pattern, operation, separator):
359 session = ibid.databases.ibid()
360 factoids = get_factoid(session, name, number, pattern, True)
361 if len(factoids) == 0:
362 event.addresponse(u"I didn't know about %s anyway" % name)
363 elif len(factoids) > 1:
364 event.addresponse(u"Pattern matches multiple factoids, please be more specific")
365 else:
366 factoidadmin = auth_responses(event, u'factoidadmin')
367 identities = get_identities(event, session)
368 factoid = factoids[0]
369
370 if factoid[2].identity_id not in identities and not factoidadmin:
371 raise ibid.AuthException(u"You are not permitted to do that")
372 return
373
374 if separator in ("^", "]"):
375 separator = '\\' + separator
376 parts = re.split(r"(?<=[^\\])[%s]" % separator, operation)
377 if len(parts) != 4:
378 event.addresponse(u"That operation makes no sense. Work on your regex-fu.")
379 return
380
381 op, search, replace, flags = parts
382 if op == "s":
383 if "i" in flags.lower():
384 search += "(?i)"
385 try:
386 factoid[2].value, subs = re.subn(search, replace, factoid[2].value, int("g" not in flags))
387 except:
388 event.addresponse(u"That operation makes no sense. Try something like s/foo/bar/")
389 return
390
391 elif op == "y":
392 if len(search) != len(replace):
393 event.addresponse(u"That operation makes no sense. The source and destination must be the same length.")
394 return
395 try:
396 table = dict((ord(x), ord(y)) for x, y in zip(search, replace))
397 factoid[2].value = factoid[2].value.translate(table)
398
399 except:
400 event.addresponse(u"That operation makes no sense. Try something like y/abcdef/ABCDEF/")
401 return
402
403 log.info(u"Applying '%s' to value %s of factoid %s (%s) by %s/%s (%s)",
404 operation, factoid[2].id, factoid[0].id, factoid[2].value, event.account, event.identity, event.sender['connection'])
405
406 session.flush()
407 session.close()
408 event.addresponse(True)
315# vi: set et sta sw=4 ts=4:409# vi: set et sta sw=4 ts=4:

Subscribers

People subscribed via source and target branches