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

Proposed by Max Rabkin
Status: Merged
Approved by: Stefano Rivera
Approved revision: 989
Merged at revision: 991
Proposed branch: lp:~max-rabkin/ibid/factoid-ci-replace-709175-0.1
Merge into: lp:~ibid-core/ibid/old-release-0.1-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-0.1
Reviewer Review Type Date Requested Status
Jonathan Hitchcock Approve
Stefano Rivera Approve
Review via email: mp+51196@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
=== modified file 'ibid/plugins/factoid.py'
--- ibid/plugins/factoid.py 2011-02-21 15:27:41 +0000
+++ ibid/plugins/factoid.py 2011-02-24 19:25:16 +0000
@@ -722,23 +722,27 @@
722 op, search, replace, flags = parts722 op, search, replace, flags = parts
723 flags = flags.lower()723 flags = flags.lower()
724 if op == "s":724 if op == "s":
725 if "r" in flags:725 if "r" not in flags:
726 if "i" in flags:726 plain_search = search
727 search += "(?i)"727 search = re.escape(search)
728 try:728 replace = replace.replace('\\', '\\\\')
729 factoid[2].value = re.sub(search, replace, oldvalue, int("g" not in flags))729 if "i" in flags:
730 except:730 search += "(?i)"
731 event.addresponse(u"That operation makes no sense. Try something like s/foo/bar/")731 try:
732 return732 if "r" not in flags and not re.search(search, oldvalue):
733 else:733 event.addresponse(u"I couldn't find '%(terms)s' in "
734 newvalue = oldvalue.replace(search, replace, "g" in flags and -1 or 1)734 u"'%(oldvalue)s'. If that was a "
735 if newvalue == oldvalue:735 u"proper regular expression, append "
736 event.addresponse(u"I couldn't find '%(terms)s' in '%(oldvalue)s'. If that was a proper regular expression, append the 'r' flag", {736 u"the 'r' flag", {
737 'terms': search,737 'terms': plain_search,
738 'oldvalue': oldvalue,738 'oldvalue': oldvalue,
739 })739 })
740 return740 return
741 factoid[2].value = newvalue741
742 factoid[2].value = re.sub(search, replace, oldvalue, int("g" not in flags))
743 except:
744 event.addresponse(u"That operation makes no sense. Try something like s/foo/bar/")
745 return
742746
743 elif op == "y":747 elif op == "y":
744 if len(search) != len(replace):748 if len(search) != len(replace):

Subscribers

People subscribed via source and target branches