##// END OF EJS Templates
py3: add pycompat.open and replace open() calls...
Pulkit Goyal -
r31149:76a64c1e default
parent child Browse files
Show More
@@ -280,7 +280,7 b' if sys.version_info[0] >= 3:'
280 continue
280 continue
281 r, c = t.start
281 r, c = t.start
282 l = (b'; from mercurial.pycompat import '
282 l = (b'; from mercurial.pycompat import '
283 b'delattr, getattr, hasattr, setattr, xrange\n')
283 b'delattr, getattr, hasattr, setattr, xrange, open\n')
284 for u in tokenize.tokenize(io.BytesIO(l).readline):
284 for u in tokenize.tokenize(io.BytesIO(l).readline):
285 if u.type in (tokenize.ENCODING, token.ENDMARKER):
285 if u.type in (tokenize.ENCODING, token.ENDMARKER):
286 continue
286 continue
@@ -327,7 +327,7 b' if sys.version_info[0] >= 3:'
327 # ``replacetoken`` or any mechanism that changes semantics of module
327 # ``replacetoken`` or any mechanism that changes semantics of module
328 # loading is changed. Otherwise cached bytecode may get loaded without
328 # loading is changed. Otherwise cached bytecode may get loaded without
329 # the new transformation mechanisms applied.
329 # the new transformation mechanisms applied.
330 BYTECODEHEADER = b'HG\x00\x06'
330 BYTECODEHEADER = b'HG\x00\x07'
331
331
332 class hgloader(importlib.machinery.SourceFileLoader):
332 class hgloader(importlib.machinery.SourceFileLoader):
333 """Custom module loader that transforms source code.
333 """Custom module loader that transforms source code.
@@ -96,6 +96,9 b' if ispy3:'
96 setattr = _wrapattrfunc(builtins.setattr)
96 setattr = _wrapattrfunc(builtins.setattr)
97 xrange = builtins.range
97 xrange = builtins.range
98
98
99 def open(name, mode='r', buffering=-1):
100 return builtins.open(name, sysstr(mode), buffering)
101
99 # getopt.getopt() on Python 3 deals with unicodes internally so we cannot
102 # getopt.getopt() on Python 3 deals with unicodes internally so we cannot
100 # pass bytes there. Passing unicodes will result in unicodes as return
103 # pass bytes there. Passing unicodes will result in unicodes as return
101 # values which we need to convert again to bytes.
104 # values which we need to convert again to bytes.
General Comments 0
You need to be logged in to leave comments. Login now