[PATCH 1 of 2] py3: convert the mode argument of os.fdopen to unicodes (1 of 2)

Pulkit Goyal 7895pulkit at gmail.com
Mon Feb 13 20:29:14 UTC 2017


# HG changeset patch
# User Pulkit Goyal <7895pulkit at gmail.com>
# Date 1486996598 -19800
#      Mon Feb 13 20:06:38 2017 +0530
# Node ID c4e76e37aa693eeb31dccca18b589a01ee75c3b8
# Parent  72f25e17af9d6a206ea374c30f229ae9513f3f23
py3: convert the mode argument of os.fdopen to unicodes (1 of 2)

os.fdopen() does not accepts bytes as its second argument which represent the
mode in which the file is to be opened. This patch makes sure unicodes are
passed in py3 by using pycompat.sysstr().

diff -r 72f25e17af9d -r c4e76e37aa69 mercurial/bundlerepo.py
--- a/mercurial/bundlerepo.py	Mon Feb 13 02:31:56 2017 -0800
+++ b/mercurial/bundlerepo.py	Mon Feb 13 20:06:38 2017 +0530
@@ -272,7 +272,7 @@
                                             suffix=".hg10un")
             self.tempfile = temp
 
-            with os.fdopen(fdtemp, 'wb') as fptemp:
+            with os.fdopen(fdtemp, pycompat.sysstr('wb')) as fptemp:
                 fptemp.write(header)
                 while True:
                     chunk = read(2**18)
diff -r 72f25e17af9d -r c4e76e37aa69 mercurial/chgserver.py
--- a/mercurial/chgserver.py	Mon Feb 13 02:31:56 2017 -0800
+++ b/mercurial/chgserver.py	Mon Feb 13 20:06:38 2017 +0530
@@ -287,9 +287,9 @@
 
 _iochannels = [
     # server.ch, ui.fp, mode
-    ('cin', 'fin', 'rb'),
-    ('cout', 'fout', 'wb'),
-    ('cerr', 'ferr', 'wb'),
+    ('cin', 'fin', pycompat.sysstr('rb')),
+    ('cout', 'fout', pycompat.sysstr('wb')),
+    ('cerr', 'ferr', pycompat.sysstr('wb')),
 ]
 
 class chgcmdserver(commandserver.server):
diff -r 72f25e17af9d -r c4e76e37aa69 mercurial/commandserver.py
--- a/mercurial/commandserver.py	Mon Feb 13 02:31:56 2017 -0800
+++ b/mercurial/commandserver.py	Mon Feb 13 20:06:38 2017 +0530
@@ -304,8 +304,8 @@
     ui.flush()
     newfiles = []
     nullfd = os.open(os.devnull, os.O_RDWR)
-    for f, sysf, mode in [(ui.fin, util.stdin, 'rb'),
-                          (ui.fout, util.stdout, 'wb')]:
+    for f, sysf, mode in [(ui.fin, util.stdin, pycompat.sysstr('rb')),
+                          (ui.fout, util.stdout, pycompat.sysstr('wb'))]:
         if f is sysf:
             newfd = os.dup(f.fileno())
             os.dup2(nullfd, f.fileno())
diff -r 72f25e17af9d -r c4e76e37aa69 mercurial/filemerge.py
--- a/mercurial/filemerge.py	Mon Feb 13 02:31:56 2017 -0800
+++ b/mercurial/filemerge.py	Mon Feb 13 20:06:38 2017 +0530
@@ -585,7 +585,7 @@
         pre = "%s~%s." % (os.path.basename(fullbase), prefix)
         (fd, name) = tempfile.mkstemp(prefix=pre, suffix=ext)
         data = repo.wwritedata(ctx.path(), ctx.data())
-        f = os.fdopen(fd, "wb")
+        f = os.fdopen(fd, pycompat.sysstr("wb"))
         f.write(data)
         f.close()
         return name
diff -r 72f25e17af9d -r c4e76e37aa69 mercurial/httppeer.py
--- a/mercurial/httppeer.py	Mon Feb 13 02:31:56 2017 -0800
+++ b/mercurial/httppeer.py	Mon Feb 13 20:06:38 2017 +0530
@@ -20,6 +20,7 @@
     bundle2,
     error,
     httpconnection,
+    pycompat,
     statichttprepo,
     url,
     util,
@@ -327,7 +328,7 @@
         try:
             # dump bundle to disk
             fd, filename = tempfile.mkstemp(prefix="hg-bundle-", suffix=".hg")
-            fh = os.fdopen(fd, "wb")
+            fh = os.fdopen(fd, pycompat.sysstr("wb"))
             d = fp.read(4096)
             while d:
                 fh.write(d)
diff -r 72f25e17af9d -r c4e76e37aa69 mercurial/patch.py
--- a/mercurial/patch.py	Mon Feb 13 02:31:56 2017 -0800
+++ b/mercurial/patch.py	Mon Feb 13 20:06:38 2017 +0530
@@ -34,6 +34,7 @@
     mail,
     mdiff,
     pathutil,
+    pycompat,
     scmutil,
     similar,
     util,
@@ -209,7 +210,7 @@
 
     data = {}
     fd, tmpname = tempfile.mkstemp(prefix='hg-patch-')
-    tmpfp = os.fdopen(fd, 'w')
+    tmpfp = os.fdopen(fd, pycompat.sysstr('w'))
     try:
         msg = email.Parser.Parser().parse(fileobj)
 
@@ -1055,7 +1056,7 @@
                 ncpatchfp = None
                 try:
                     # Write the initial patch
-                    f = os.fdopen(patchfd, "w")
+                    f = os.fdopen(patchfd, pycompat.sysstr("w"))
                     chunk.header.write(f)
                     chunk.write(f)
                     f.write('\n'.join(['# ' + i for i in phelp.splitlines()]))
diff -r 72f25e17af9d -r c4e76e37aa69 mercurial/wireproto.py
--- a/mercurial/wireproto.py	Mon Feb 13 02:31:56 2017 -0800
+++ b/mercurial/wireproto.py	Mon Feb 13 20:06:38 2017 +0530
@@ -26,6 +26,7 @@
     exchange,
     peer,
     pushkey as pushkeymod,
+    pycompat,
     streamclone,
     util,
 )
@@ -940,7 +941,7 @@
 
         # write bundle data to temporary file because it can be big
         fd, tempname = tempfile.mkstemp(prefix='hg-unbundle-')
-        fp = os.fdopen(fd, 'wb+')
+        fp = os.fdopen(fd, pycompat.sysstr('wb+'))
         r = 0
         try:
             proto.getfile(fp)
diff -r 72f25e17af9d -r c4e76e37aa69 mercurial/worker.py
--- a/mercurial/worker.py	Mon Feb 13 02:31:56 2017 -0800
+++ b/mercurial/worker.py	Mon Feb 13 20:06:38 2017 +0530
@@ -157,7 +157,7 @@
                 os._exit(0)
         pids.add(pid)
     os.close(wfd)
-    fp = os.fdopen(rfd, 'rb', 0)
+    fp = os.fdopen(rfd, pycompat.sysstr('rb'), 0)
     def cleanup():
         signal.signal(signal.SIGINT, oldhandler)
         waitforworkers()


More information about the Mercurial-devel mailing list