##// END OF EJS Templates
py3: use namedtuple._replace to produce new tokens
Martijn Pieters -
r30166:102e6ef5 default
parent child Browse files
Show More
@@ -233,9 +233,7 b' if sys.version_info[0] >= 3:'
233 """
233 """
234 st = tokens[j]
234 st = tokens[j]
235 if st.type == token.STRING and st.string.startswith(("'", '"')):
235 if st.type == token.STRING and st.string.startswith(("'", '"')):
236 rt = tokenize.TokenInfo(st.type, 'u%s' % st.string,
236 tokens[j] = st._replace(string='u%s' % st.string)
237 st.start, st.end, st.line)
238 tokens[j] = rt
239
237
240 for i, t in enumerate(tokens):
238 for i, t in enumerate(tokens):
241 # Convert most string literals to byte literals. String literals
239 # Convert most string literals to byte literals. String literals
@@ -266,8 +264,7 b' if sys.version_info[0] >= 3:'
266 continue
264 continue
267
265
268 # String literal. Prefix to make a b'' string.
266 # String literal. Prefix to make a b'' string.
269 yield tokenize.TokenInfo(t.type, 'b%s' % s, t.start, t.end,
267 yield t._replace(string='b%s' % t.string)
270 t.line)
271 continue
268 continue
272
269
273 # Insert compatibility imports at "from __future__ import" line.
270 # Insert compatibility imports at "from __future__ import" line.
@@ -287,10 +284,8 b' if sys.version_info[0] >= 3:'
287 for u in tokenize.tokenize(io.BytesIO(l).readline):
284 for u in tokenize.tokenize(io.BytesIO(l).readline):
288 if u.type in (tokenize.ENCODING, token.ENDMARKER):
285 if u.type in (tokenize.ENCODING, token.ENDMARKER):
289 continue
286 continue
290 yield tokenize.TokenInfo(u.type, u.string,
287 yield u._replace(
291 (r, c + u.start[1]),
288 start=(r, c + u.start[1]), end=(r, c + u.end[1]))
292 (r, c + u.end[1]),
293 '')
294 continue
289 continue
295
290
296 # This looks like a function call.
291 # This looks like a function call.
@@ -322,8 +317,7 b' if sys.version_info[0] >= 3:'
322 # It changes iteritems to items as iteritems is not
317 # It changes iteritems to items as iteritems is not
323 # present in Python 3 world.
318 # present in Python 3 world.
324 elif fn == 'iteritems':
319 elif fn == 'iteritems':
325 yield tokenize.TokenInfo(t.type, 'items',
320 yield t._replace(string='items')
326 t.start, t.end, t.line)
327 continue
321 continue
328
322
329 # Emit unmodified token.
323 # Emit unmodified token.
General Comments 0
You need to be logged in to leave comments. Login now