py3: convert the mode argument of os.fdopen to unicodes (1 of 2)
authorPulkit Goyal <7895pulkit@gmail.com>
Mon, 13 Feb 2017 20:06:38 +0530
changeset 30924 48dea083f66d
parent 30923 78de43ab585f
child 30925 82f1ef8b4477
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().
mercurial/bundlerepo.py
mercurial/chgserver.py
mercurial/commandserver.py
mercurial/filemerge.py
mercurial/httppeer.py
mercurial/patch.py
mercurial/wireproto.py
mercurial/worker.py
--- a/mercurial/bundlerepo.py	Thu Feb 09 15:20:41 2017 -0500
+++ 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)
--- a/mercurial/chgserver.py	Thu Feb 09 15:20:41 2017 -0500
+++ 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):
--- a/mercurial/commandserver.py	Thu Feb 09 15:20:41 2017 -0500
+++ 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())
--- a/mercurial/filemerge.py	Thu Feb 09 15:20:41 2017 -0500
+++ 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
--- a/mercurial/httppeer.py	Thu Feb 09 15:20:41 2017 -0500
+++ 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)
--- a/mercurial/patch.py	Thu Feb 09 15:20:41 2017 -0500
+++ 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()]))
--- a/mercurial/wireproto.py	Thu Feb 09 15:20:41 2017 -0500
+++ b/mercurial/wireproto.py	Mon Feb 13 20:06:38 2017 +0530
@@ -26,6 +26,7 @@
     exchange,
     peer,
     pushkey as pushkeymod,
+    pycompat,
     streamclone,
     util,
 )
@@ -961,7 +962,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)
--- a/mercurial/worker.py	Thu Feb 09 15:20:41 2017 -0500
+++ 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()