Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/libfuturize/fixes/fix_bytes.py @ 5:9b1c78e6ba9c draft default tip
"planemo upload commit 6c0a8142489327ece472c84e558c47da711a9142"
| author | shellac |
|---|---|
| date | Mon, 01 Jun 2020 08:59:25 -0400 |
| parents | 79f47841a781 |
| children |
comparison
equal
deleted
inserted
replaced
| 4:79f47841a781 | 5:9b1c78e6ba9c |
|---|---|
| 1 """Optional fixer that changes all unprefixed string literals "..." to b"...". | |
| 2 | |
| 3 br'abcd' is a SyntaxError on Python 2 but valid on Python 3. | |
| 4 ur'abcd' is a SyntaxError on Python 3 but valid on Python 2. | |
| 5 | |
| 6 """ | |
| 7 from __future__ import unicode_literals | |
| 8 | |
| 9 import re | |
| 10 from lib2to3.pgen2 import token | |
| 11 from lib2to3 import fixer_base | |
| 12 | |
| 13 _literal_re = re.compile(r"[^bBuUrR]?[\'\"]") | |
| 14 | |
| 15 class FixBytes(fixer_base.BaseFix): | |
| 16 BM_compatible = True | |
| 17 PATTERN = "STRING" | |
| 18 | |
| 19 def transform(self, node, results): | |
| 20 if node.type == token.STRING: | |
| 21 if _literal_re.match(node.value): | |
| 22 new = node.clone() | |
| 23 new.value = u'b' + new.value | |
| 24 return new |
