Mercurial > genshi > genshi-test
diff fixes/fix_unicode_in_strings.py @ 929:1a86e0af2ae1
Merge r1137 from py3k: add 2to3 build infrastructure to setup.py (this pulls the tests into the source distribution so that tests can be run after building with 2to3)
author | hodgestar |
---|---|
date | Fri, 18 Mar 2011 09:02:22 +0000 |
parents | |
children |
line wrap: on
line diff
new file mode 100644 --- /dev/null +++ b/fixes/fix_unicode_in_strings.py @@ -0,0 +1,17 @@ +"""Fixer that changes expressions inside strings literals from u"..." to "...". + +""" + +import re +from lib2to3 import fixer_base + +_literal_re = re.compile(r"(.+?)\b[uU]([rR]?[\'\"])") + +class FixUnicodeInStrings(fixer_base.BaseFix): + + PATTERN = "STRING" + + def transform(self, node, results): + new = node.clone() + new.value = _literal_re.sub(r"\1\2", new.value) + return new