changeset 30637:344e68882cd3

py3: replace os.environ with encoding.environ (part 4 of 5)
author Pulkit Goyal <7895pulkit@gmail.com>
date Sun, 18 Dec 2016 02:06:00 +0530
parents f1c9fafcbf46
children 1c5cbf28f007
files mercurial/scmwindows.py mercurial/statprof.py mercurial/ui.py mercurial/util.py mercurial/win32.py
diffstat 5 files changed, 17 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/scmwindows.py	Sun Dec 18 01:54:36 2016 +0530
+++ b/mercurial/scmwindows.py	Sun Dec 18 02:06:00 2016 +0530
@@ -3,6 +3,7 @@
 import os
 
 from . import (
+    encoding,
     osutil,
     pycompat,
     util,
@@ -48,7 +49,7 @@
     home = os.path.expanduser('~')
     path = [os.path.join(home, 'mercurial.ini'),
             os.path.join(home, '.hgrc')]
-    userprofile = os.environ.get('USERPROFILE')
+    userprofile = encoding.environ.get('USERPROFILE')
     if userprofile and userprofile != home:
         path.append(os.path.join(userprofile, 'mercurial.ini'))
         path.append(os.path.join(userprofile, '.hgrc'))
--- a/mercurial/statprof.py	Sun Dec 18 01:54:36 2016 +0530
+++ b/mercurial/statprof.py	Sun Dec 18 02:06:00 2016 +0530
@@ -117,6 +117,7 @@
 import time
 
 from . import (
+    encoding,
     pycompat,
 )
 
@@ -324,7 +325,7 @@
 
         state.accumulate_time(clock())
         state.last_start_time = None
-        statprofpath = os.environ.get('STATPROF_DEST')
+        statprofpath = encoding.environ.get('STATPROF_DEST')
         if statprofpath:
             save_data(statprofpath)
 
@@ -680,7 +681,7 @@
 
 def write_to_flame(data, fp, scriptpath=None, outputfile=None, **kwargs):
     if scriptpath is None:
-        scriptpath = os.environ['HOME'] + '/flamegraph.pl'
+        scriptpath = encoding.environ['HOME'] + '/flamegraph.pl'
     if not os.path.exists(scriptpath):
         print("error: missing %s" % scriptpath, file=fp)
         print("get it here: https://github.com/brendangregg/FlameGraph",
--- a/mercurial/ui.py	Sun Dec 18 01:54:36 2016 +0530
+++ b/mercurial/ui.py	Sun Dec 18 02:06:00 2016 +0530
@@ -143,7 +143,7 @@
             self.fin = util.stdin
 
             # shared read-only environment
-            self.environ = os.environ
+            self.environ = encoding.environ
 
             self.httppasswordmgrdb = urlreq.httppasswordmgrwithdefaultrealm()
 
--- a/mercurial/util.py	Sun Dec 18 01:54:36 2016 +0530
+++ b/mercurial/util.py	Sun Dec 18 02:06:00 2016 +0530
@@ -948,14 +948,14 @@
     Defaults to $HG or 'hg' in the search path.
     """
     if _hgexecutable is None:
-        hg = os.environ.get('HG')
+        hg = encoding.environ.get('HG')
         mainmod = sys.modules['__main__']
         if hg:
             _sethgexecutable(hg)
         elif mainfrozen():
             if getattr(sys, 'frozen', None) == 'macosx_app':
                 # Env variable set by py2app
-                _sethgexecutable(os.environ['EXECUTABLEPATH'])
+                _sethgexecutable(encoding.environ['EXECUTABLEPATH'])
             else:
                 _sethgexecutable(sys.executable)
         elif os.path.basename(getattr(mainmod, '__file__', '')) == 'hg':
@@ -1006,7 +1006,7 @@
             os.chdir(cwd)
         rc = os.system(cmd)
     else:
-        env = dict(os.environ)
+        env = dict(encoding.environ)
         env.update((k, py2shell(v)) for k, v in environ.iteritems())
         env['HG'] = hgexecutable()
         if out is None or _isstdout(out):
@@ -1384,7 +1384,7 @@
 def gui():
     '''Are we running in a GUI?'''
     if sys.platform == 'darwin':
-        if 'SSH_CONNECTION' in os.environ:
+        if 'SSH_CONNECTION' in encoding.environ:
             # handle SSH access to a box where the user is logged in
             return False
         elif getattr(osutil, 'isgui', None):
@@ -1394,7 +1394,7 @@
             # pure build; use a safe default
             return True
     else:
-        return os.name == "nt" or os.environ.get("DISPLAY")
+        return os.name == "nt" or encoding.environ.get("DISPLAY")
 
 def mktempcopy(name, emptyok=False, createmode=None):
     """Create a temporary file with the same contents from name
@@ -2297,7 +2297,7 @@
     if mainfrozen():
         if getattr(sys, 'frozen', None) == 'macosx_app':
             # Env variable set by py2app
-            return [os.environ['EXECUTABLEPATH']]
+            return [encoding.environ['EXECUTABLEPATH']]
         else:
             return [sys.executable]
     return gethgcmd()
--- a/mercurial/win32.py	Sun Dec 18 01:54:36 2016 +0530
+++ b/mercurial/win32.py	Sun Dec 18 02:06:00 2016 +0530
@@ -14,6 +14,8 @@
 import random
 import subprocess
 
+from . import encoding
+
 _kernel32 = ctypes.windll.kernel32
 _advapi32 = ctypes.windll.advapi32
 _user32 = ctypes.windll.user32
@@ -424,8 +426,8 @@
     pi = _PROCESS_INFORMATION()
 
     env = ''
-    for k in os.environ:
-        env += "%s=%s\0" % (k, os.environ[k])
+    for k in encoding.environ:
+        env += "%s=%s\0" % (k, encoding.environ[k])
     if not env:
         env = '\0'
     env += '\0'
@@ -433,7 +435,7 @@
     args = subprocess.list2cmdline(args)
     # Not running the command in shell mode makes Python 2.6 hang when
     # writing to hgweb output socket.
-    comspec = os.environ.get("COMSPEC", "cmd.exe")
+    comspec = encoding.environ.get("COMSPEC", "cmd.exe")
     args = comspec + " /c " + args
 
     res = _kernel32.CreateProcessA(