Mercurial > genshi > mirror
annotate fixes/fix_unicode_in_strings.py @ 921:07defc3702b3 experimental-py3k
Fix handling of tails in py:match processing. See Genshi ticket #399.
author | hodgestar |
---|---|
date | Mon, 29 Nov 2010 20:45:22 +0000 |
parents | c74a141a48ff |
children |
rev | line source |
---|---|
912
c74a141a48ff
py3k branch: 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)
hodgestar
parents:
diff
changeset
|
1 """Fixer that changes expressions inside strings literals from u"..." to "...". |
c74a141a48ff
py3k branch: 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)
hodgestar
parents:
diff
changeset
|
2 |
c74a141a48ff
py3k branch: 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)
hodgestar
parents:
diff
changeset
|
3 """ |
c74a141a48ff
py3k branch: 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)
hodgestar
parents:
diff
changeset
|
4 |
c74a141a48ff
py3k branch: 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)
hodgestar
parents:
diff
changeset
|
5 import re |
c74a141a48ff
py3k branch: 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)
hodgestar
parents:
diff
changeset
|
6 from lib2to3 import fixer_base |
c74a141a48ff
py3k branch: 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)
hodgestar
parents:
diff
changeset
|
7 |
c74a141a48ff
py3k branch: 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)
hodgestar
parents:
diff
changeset
|
8 _literal_re = re.compile(r"(.+?)\b[uU]([rR]?[\'\"])") |
c74a141a48ff
py3k branch: 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)
hodgestar
parents:
diff
changeset
|
9 |
c74a141a48ff
py3k branch: 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)
hodgestar
parents:
diff
changeset
|
10 class FixUnicodeInStrings(fixer_base.BaseFix): |
c74a141a48ff
py3k branch: 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)
hodgestar
parents:
diff
changeset
|
11 |
c74a141a48ff
py3k branch: 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)
hodgestar
parents:
diff
changeset
|
12 PATTERN = "STRING" |
c74a141a48ff
py3k branch: 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)
hodgestar
parents:
diff
changeset
|
13 |
c74a141a48ff
py3k branch: 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)
hodgestar
parents:
diff
changeset
|
14 def transform(self, node, results): |
c74a141a48ff
py3k branch: 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)
hodgestar
parents:
diff
changeset
|
15 new = node.clone() |
c74a141a48ff
py3k branch: 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)
hodgestar
parents:
diff
changeset
|
16 new.value = _literal_re.sub(r"\1\2", new.value) |
c74a141a48ff
py3k branch: 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)
hodgestar
parents:
diff
changeset
|
17 return new |