changeset 30639:d524c88511a7

py3: replace os.name with pycompat.osname (part 1 of 2) os.name returns unicodes on py3 and we have pycompat.osname which returns bytes. This series of 2 patches will change every ocurrence of os.name with pycompat.osname.
author Pulkit Goyal <7895pulkit@gmail.com>
date Mon, 19 Dec 2016 00:16:52 +0530
parents 1c5cbf28f007
children 7a3e67bfa417
files mercurial/hgweb/server.py mercurial/i18n.py mercurial/pure/osutil.py mercurial/scmutil.py mercurial/sslutil.py mercurial/subrepo.py mercurial/util.py mercurial/worker.py
diffstat 8 files changed, 18 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/server.py	Sun Dec 18 02:08:59 2016 +0530
+++ b/mercurial/hgweb/server.py	Mon Dec 19 00:16:52 2016 +0530
@@ -18,6 +18,7 @@
 
 from .. import (
     error,
+    pycompat,
     util,
 )
 
@@ -266,7 +267,7 @@
 class MercurialHTTPServer(_mixin, httpservermod.httpserver, object):
 
     # SO_REUSEADDR has broken semantics on windows
-    if os.name == 'nt':
+    if pycompat.osname == 'nt':
         allow_reuse_address = 0
 
     def __init__(self, ui, app, addr, handler, **kwargs):
--- a/mercurial/i18n.py	Sun Dec 18 02:08:59 2016 +0530
+++ b/mercurial/i18n.py	Mon Dec 19 00:16:52 2016 +0530
@@ -29,7 +29,7 @@
     unicode = str
 
 _languages = None
-if (os.name == 'nt'
+if (pycompat.osname == 'nt'
     and 'LANGUAGE' not in encoding.environ
     and 'LC_ALL' not in encoding.environ
     and 'LC_MESSAGES' not in encoding.environ
--- a/mercurial/pure/osutil.py	Sun Dec 18 02:08:59 2016 +0530
+++ b/mercurial/pure/osutil.py	Mon Dec 19 00:16:52 2016 +0530
@@ -159,7 +159,7 @@
 else:
     listdir = listdirpure
 
-if os.name != 'nt':
+if pycompat.osname != 'nt':
     posixfile = open
 
     _SCM_RIGHTS = 0x01
--- a/mercurial/scmutil.py	Sun Dec 18 02:08:59 2016 +0530
+++ b/mercurial/scmutil.py	Mon Dec 19 00:16:52 2016 +0530
@@ -34,7 +34,7 @@
     util,
 )
 
-if os.name == 'nt':
+if pycompat.osname == 'nt':
     from . import scmwindows as scmplatform
 else:
     from . import scmposix as scmplatform
@@ -281,7 +281,7 @@
     val = ui.config('ui', 'portablefilenames', 'warn')
     lval = val.lower()
     bval = util.parsebool(val)
-    abort = os.name == 'nt' or lval == 'abort'
+    abort = pycompat.osname == 'nt' or lval == 'abort'
     warn = bval or lval == 'warn'
     if bval is None and not (warn or abort or lval == 'ignore'):
         raise error.ConfigError(
@@ -1461,7 +1461,7 @@
 
         # Only Windows/NTFS has slow file closing. So only enable by default
         # on that platform. But allow to be enabled elsewhere for testing.
-        defaultenabled = os.name == 'nt'
+        defaultenabled = pycompat.osname == 'nt'
         enabled = ui.configbool('worker', 'backgroundclose', defaultenabled)
 
         if not enabled:
--- a/mercurial/sslutil.py	Sun Dec 18 02:08:59 2016 +0530
+++ b/mercurial/sslutil.py	Mon Dec 19 00:16:52 2016 +0530
@@ -18,6 +18,7 @@
 from .i18n import _
 from . import (
     error,
+    pycompat,
     util,
 )
 
@@ -706,7 +707,7 @@
     # because we'll get a certificate verification error later and the lack
     # of loaded CA certificates will be the reason why.
     # Assertion: this code is only called if certificates are being verified.
-    if os.name == 'nt':
+    if pycompat.osname == 'nt':
         if not _canloaddefaultcerts:
             ui.warn(_('(unable to load Windows CA certificates; see '
                       'https://mercurial-scm.org/wiki/SecureConnections for '
@@ -737,7 +738,7 @@
     # / is writable on Windows. Out of an abundance of caution make sure
     # we're not on Windows because paths from _systemcacerts could be installed
     # by non-admin users.
-    assert os.name != 'nt'
+    assert pycompat.osname != 'nt'
 
     # Try to find CA certificates in well-known locations. We print a warning
     # when using a found file because we don't want too much silent magic
--- a/mercurial/subrepo.py	Sun Dec 18 02:08:59 2016 +0530
+++ b/mercurial/subrepo.py	Mon Dec 19 00:16:52 2016 +0530
@@ -1313,7 +1313,7 @@
             notfoundhint = _("check git is installed and in your PATH")
             if e.errno != errno.ENOENT:
                 raise error.Abort(genericerror % (self._path, e.strerror))
-            elif os.name == 'nt':
+            elif pycompat.osname == 'nt':
                 try:
                     self._gitexecutable = 'git.cmd'
                     out, err = self._gitnodir(['--version'])
--- a/mercurial/util.py	Sun Dec 18 02:08:59 2016 +0530
+++ b/mercurial/util.py	Mon Dec 19 00:16:52 2016 +0530
@@ -63,7 +63,7 @@
 urlreq = pycompat.urlreq
 xmlrpclib = pycompat.xmlrpclib
 
-if os.name == 'nt':
+if pycompat.osname == 'nt':
     from . import windows as platform
     stdout = platform.winstdout(pycompat.stdout)
 else:
@@ -238,7 +238,7 @@
         def buffer(sliceable, offset=0):
             return memoryview(sliceable)[offset:]
 
-closefds = os.name == 'posix'
+closefds = pycompat.osname == 'posix'
 
 _chunksize = 4096
 
@@ -1175,7 +1175,7 @@
             return _("filename ends with '%s', which is not allowed "
                      "on Windows") % t
 
-if os.name == 'nt':
+if pycompat.osname == 'nt':
     checkosfilename = checkwinfilename
 else:
     checkosfilename = platform.checkosfilename
@@ -1394,7 +1394,7 @@
             # pure build; use a safe default
             return True
     else:
-        return os.name == "nt" or encoding.environ.get("DISPLAY")
+        return pycompat.osname == "nt" or encoding.environ.get("DISPLAY")
 
 def mktempcopy(name, emptyok=False, createmode=None):
     """Create a temporary file with the same contents from name
--- a/mercurial/worker.py	Sun Dec 18 02:08:59 2016 +0530
+++ b/mercurial/worker.py	Mon Dec 19 00:16:52 2016 +0530
@@ -16,6 +16,7 @@
 from . import (
     encoding,
     error,
+    pycompat,
     scmutil,
     util,
 )
@@ -52,7 +53,7 @@
             raise error.Abort(_('number of cpus must be an integer'))
     return min(max(countcpus(), 4), 32)
 
-if os.name == 'posix':
+if pycompat.osname == 'posix':
     _startupcost = 0.01
 else:
     _startupcost = 1e30
@@ -186,7 +187,7 @@
     elif os.WIFSIGNALED(code):
         return -os.WTERMSIG(code)
 
-if os.name != 'nt':
+if pycompat.osname != 'nt':
     _platformworker = _posixworker
     _exitstatus = _posixexitstatus