[PATCH 2 of 2] py3: make util.posixfile compatible with py3

Pulkit Goyal 7895pulkit at gmail.com
Thu Feb 23 06:59:01 EST 2017


# HG changeset patch
# User Pulkit Goyal <7895pulkit at gmail.com>
# Date 1487768580 -19800
#      Wed Feb 22 18:33:00 2017 +0530
# Node ID 4572027bbe6795e66758120375f647c1c1804195
# Parent  80693cfda5a63dee28cf9e63cf0e8cef3f27f23a
py3: make util.posixfile compatible with py3

On python 3, python's inbuilt open function accepts unicodes as its mode
argument whereas we need to pass bytes to windows.posixfile. So this patch
adds that support.

diff -r 80693cfda5a6 -r 4572027bbe67 mercurial/util.py
--- a/mercurial/util.py	Mon Feb 20 18:40:42 2017 +0530
+++ b/mercurial/util.py	Wed Feb 22 18:33:00 2017 +0530
@@ -114,7 +114,6 @@
 pconvert = platform.pconvert
 poll = platform.poll
 popen = platform.popen
-posixfile = platform.posixfile
 quotecommand = platform.quotecommand
 readpipe = platform.readpipe
 rename = platform.rename
@@ -147,6 +146,15 @@
 # libraries, and sure enough Mercurial is not a library.)
 os.stat_float_times(False)
 
+def posixfile(name, mode='r', buffering=-1):
+    if pycompat.ispy3:
+        if pycompat.osname == 'nt':
+            return platform.posixfile(name, mode, buffering)
+        else:
+            return platform.posixfile(name, pycompat.sysstr(mode), buffering)
+    else:
+        return platform.posixfile(name, mode, buffering)
+
 def safehasattr(thing, attr):
     return getattr(thing, attr, _notset) is not _notset
 


More information about the Mercurial-devel mailing list