Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Side by Side Diff: third_party/google-endpoints/libfuturize/fixes/fix_oldstr_wrap.py

Issue 2666783008: Add google-endpoints to third_party/. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 """
2 For the ``future`` package.
3
4 Adds this import line:
5
6 from past.builtins import str as oldstr
7
8 at the top and wraps any unadorned string literals 'abc' or explicit byte-string
9 literals b'abc' in oldstr() calls so the code has the same behaviour on Py3 as
10 on Py2.6/2.7.
11 """
12
13 from __future__ import unicode_literals
14 import re
15 from lib2to3 import fixer_base
16 from lib2to3.pgen2 import token
17 from lib2to3.fixer_util import syms
18 from libfuturize.fixer_util import (future_import, touch_import_top,
19 wrap_in_fn_call)
20
21
22 _literal_re = re.compile(r"[^uUrR]?[\'\"]")
23
24
25 class FixOldstrWrap(fixer_base.BaseFix):
26 BM_compatible = True
27 PATTERN = "STRING"
28
29 def transform(self, node, results):
30 if node.type == token.STRING:
31 touch_import_top(u'past.types', u'oldstr', node)
32 if _literal_re.match(node.value):
33 new = node.clone()
34 # Strip any leading space or comments:
35 # TODO: check: do we really want to do this?
36 new.prefix = u''
37 new.value = u'b' + new.value
38 wrapped = wrap_in_fn_call("oldstr", [new], prefix=node.prefix)
39 return wrapped
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698