Merge lp:~max-rabkin/ibid/factoid-ci-replace-709175 into lp:~ibid-core/ibid/old-trunk-1.6

Proposed by Max Rabkin
Status: Merged
Approved by: Stefano Rivera
Approved revision: 1016
Merged at revision: 1026
Proposed branch: lp:~max-rabkin/ibid/factoid-ci-replace-709175
Merge into: lp:~ibid-core/ibid/old-trunk-1.6
Diff against target: 48 lines (+21/-17)
1 file modified
ibid/plugins/factoid.py (+21/-17)
To merge this branch: bzr merge lp:~max-rabkin/ibid/factoid-ci-replace-709175
Reviewer Review Type Date Requested Status
Jonathan Hitchcock Approve
Stefano Rivera Approve
Review via email: mp+51194@code.launchpad.net

Commit message

Use regexen to do string replacement, allowing case-insensitive replacement

To post a comment you must log in.
Revision history for this message
Stefano Rivera (stefanor) :
review: Approve
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/plugins/factoid.py'
2--- ibid/plugins/factoid.py 2011-02-21 15:37:58 +0000
3+++ ibid/plugins/factoid.py 2011-02-24 19:13:19 +0000
4@@ -739,23 +739,27 @@
5 op, search, replace, flags = parts
6 flags = flags.lower()
7 if op == "s":
8- if "r" in flags:
9- if "i" in flags:
10- search += "(?i)"
11- try:
12- factoid[2].value = re.sub(search, replace, oldvalue, int("g" not in flags))
13- except:
14- event.addresponse(u"That operation makes no sense. Try something like s/foo/bar/")
15- return
16- else:
17- newvalue = oldvalue.replace(search, replace, "g" in flags and -1 or 1)
18- if newvalue == oldvalue:
19- event.addresponse(u"I couldn't find '%(terms)s' in '%(oldvalue)s'. If that was a proper regular expression, append the 'r' flag", {
20- 'terms': search,
21- 'oldvalue': oldvalue,
22- })
23- return
24- factoid[2].value = newvalue
25+ if "r" not in flags:
26+ plain_search = search
27+ search = re.escape(search)
28+ replace = replace.replace('\\', '\\\\')
29+ if "i" in flags:
30+ search += "(?i)"
31+ try:
32+ if "r" not in flags and not re.search(search, oldvalue):
33+ event.addresponse(u"I couldn't find '%(terms)s' in "
34+ u"'%(oldvalue)s'. If that was a "
35+ u"proper regular expression, append "
36+ u"the 'r' flag", {
37+ 'terms': plain_search,
38+ 'oldvalue': oldvalue,
39+ })
40+ return
41+
42+ factoid[2].value = re.sub(search, replace, oldvalue, int("g" not in flags))
43+ except:
44+ event.addresponse(u"That operation makes no sense. Try something like s/foo/bar/")
45+ return
46
47 elif op == "y":
48 if len(search) != len(replace):

Subscribers

People subscribed via source and target branches