diff mercurial/pycompat.py @ 31159: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
line wrap: on
line diff
--- a/mercurial/pycompat.py	Fri Aug 05 13:56:10 2016 +0200
+++ b/mercurial/pycompat.py	Fri Mar 03 13:04:32 2017 +0530
@@ -96,6 +96,9 @@
     setattr = _wrapattrfunc(builtins.setattr)
     xrange = builtins.range
 
+    def open(name, mode='r', buffering=-1):
+        return builtins.open(name, sysstr(mode), buffering)
+
     # getopt.getopt() on Python 3 deals with unicodes internally so we cannot
     # pass bytes there. Passing unicodes will result in unicodes as return
     # values which we need to convert again to bytes.