comparison mercurial/__init__.py @ 31843:526e4597cca5

py3: add pycompat.unicode and add it to importer On python 3, builtins.unicode does not exist.
author Pulkit Goyal <7895pulkit@gmail.com>
date Fri, 07 Apr 2017 23:35:51 +0530
parents 83e080144faf
children 65cd7e705ff6
comparison
equal deleted inserted replaced
31842:c130d092042a 31843:526e4597cca5
281 if fullname == 'mercurial.pycompat': 281 if fullname == 'mercurial.pycompat':
282 yield t 282 yield t
283 continue 283 continue
284 r, c = t.start 284 r, c = t.start
285 l = (b'; from mercurial.pycompat import ' 285 l = (b'; from mercurial.pycompat import '
286 b'delattr, getattr, hasattr, setattr, xrange, open\n') 286 b'delattr, getattr, hasattr, setattr, xrange, '
287 b'open, unicode\n')
287 for u in tokenize.tokenize(io.BytesIO(l).readline): 288 for u in tokenize.tokenize(io.BytesIO(l).readline):
288 if u.type in (tokenize.ENCODING, token.ENDMARKER): 289 if u.type in (tokenize.ENCODING, token.ENDMARKER):
289 continue 290 continue
290 yield u._replace( 291 yield u._replace(
291 start=(r, c + u.start[1]), end=(r, c + u.end[1])) 292 start=(r, c + u.start[1]), end=(r, c + u.end[1]))
321 322
322 # Header to add to bytecode files. This MUST be changed when 323 # Header to add to bytecode files. This MUST be changed when
323 # ``replacetoken`` or any mechanism that changes semantics of module 324 # ``replacetoken`` or any mechanism that changes semantics of module
324 # loading is changed. Otherwise cached bytecode may get loaded without 325 # loading is changed. Otherwise cached bytecode may get loaded without
325 # the new transformation mechanisms applied. 326 # the new transformation mechanisms applied.
326 BYTECODEHEADER = b'HG\x00\x09' 327 BYTECODEHEADER = b'HG\x00\x0a'
327 328
328 class hgloader(importlib.machinery.SourceFileLoader): 329 class hgloader(importlib.machinery.SourceFileLoader):
329 """Custom module loader that transforms source code. 330 """Custom module loader that transforms source code.
330 331
331 When the source code is converted to a code object, we transform 332 When the source code is converted to a code object, we transform