comparison mercurial/pycompat.py @ 31149:76a64c1e5439

py3: add pycompat.open and replace open() calls open() requires mode argument as unicodes on Python 3. This patch introduces pycompat.open() which is inserted to files using transformer and replaces builtins.open() calls.
author Pulkit Goyal <7895pulkit@gmail.com>
date Fri, 03 Mar 2017 13:04:32 +0530
parents 6a70cf94d1b5
children 64596338ba10
comparison
equal deleted inserted replaced
31148:3eaff87a0a89 31149:76a64c1e5439
93 delattr = _wrapattrfunc(builtins.delattr) 93 delattr = _wrapattrfunc(builtins.delattr)
94 getattr = _wrapattrfunc(builtins.getattr) 94 getattr = _wrapattrfunc(builtins.getattr)
95 hasattr = _wrapattrfunc(builtins.hasattr) 95 hasattr = _wrapattrfunc(builtins.hasattr)
96 setattr = _wrapattrfunc(builtins.setattr) 96 setattr = _wrapattrfunc(builtins.setattr)
97 xrange = builtins.range 97 xrange = builtins.range
98
99 def open(name, mode='r', buffering=-1):
100 return builtins.open(name, sysstr(mode), buffering)
98 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.
102 def getoptb(args, shortlist, namelist): 105 def getoptb(args, shortlist, namelist):