Mercurial > p > roundup > code
view website/issues/extensions/local_replace.py @ 4866:a5222e7ac94b
Website, Issues: local_replace.py general improvements.
* simplified the regular expressions, three into one.
* only allowing one space after r|rev|revision
* better test order to reflect the order of regexs
* tests: indicate in the comment what should fail
| author | Bernhard Reiter <bernhard@intevation.de> |
|---|---|
| date | Thu, 13 Mar 2014 09:49:14 +0100 |
| parents | 7140ebfc3764 |
| children | 3737662fd96b |
line wrap: on
line source
import re substitutions = [ (re.compile('debian:\#(?P<id>\d+)'), '<a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=\g<id>">debian#\g<id></a>' ), (re.compile('\#(?P<ws>\s*)(?P<id>\d+)'), "<a href='issue\g<id>'>#\g<ws>\g<id></a>" ), (re.compile('(?P<prews>\s+)(?P<revstr>(revision|rev|r)\s?)(?P<revision>\d+)'), "\g<prews><a href='http://svn.roundup-tracker.org/viewvc/roundup?view=rev&rev=\g<revision>'>\g<revstr>\g<revision></a>"), ] def local_replace(message): for cre, replacement in substitutions: message = cre.sub(replacement, message) return message def init(instance): instance.registerUtil('localReplace', local_replace) if "__main__" == __name__: print " debian:#222", local_replace(" debian:#222") print " #555", local_replace(" #555") print " revision 222", local_replace(" revision 222") print " r 222", local_replace(" r 222") print " wordthatendswithr 222", local_replace(" wordthatendswithr 222") # should fail print " too many spaces r 222", local_replace(" too many spaces r 222") # should fail print " r7140eb", local_replace(" r7140eb") print " rev7140eb", local_replace(" rev7140eb") print " rev7140eb", local_replace(" rev7140eb")
