# HG changeset patch # User Pulkit Goyal <7895pulkit@gmail.com> # Date 2016-12-17 20:36:00 # Node ID 344e68882cd3b2003a12aa8c90e291fd9456e160 # Parent f1c9fafcbf46a2a9d8c1e7333ab0f076b1c7cb1d py3: replace os.environ with encoding.environ (part 4 of 5) diff --git a/mercurial/scmwindows.py b/mercurial/scmwindows.py --- a/mercurial/scmwindows.py +++ b/mercurial/scmwindows.py @@ -3,6 +3,7 @@ from __future__ import absolute_import import os from . import ( + encoding, osutil, pycompat, util, @@ -48,7 +49,7 @@ def userrcpath(): 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')) diff --git a/mercurial/statprof.py b/mercurial/statprof.py --- a/mercurial/statprof.py +++ b/mercurial/statprof.py @@ -117,6 +117,7 @@ import threading import time from . import ( + encoding, pycompat, ) @@ -324,7 +325,7 @@ def stop(): 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 display_hotpath(data, fp, limit=0.05 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", diff --git a/mercurial/ui.py b/mercurial/ui.py --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -143,7 +143,7 @@ class ui(object): self.fin = util.stdin # shared read-only environment - self.environ = os.environ + self.environ = encoding.environ self.httppasswordmgrdb = urlreq.httppasswordmgrwithdefaultrealm() diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -948,14 +948,14 @@ def hgexecutable(): 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 @@ def system(cmd, environ=None, cwd=None, 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 splitpath(path): 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 @@ def gui(): # 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 @@ def hgcmd(): 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() diff --git a/mercurial/win32.py b/mercurial/win32.py --- a/mercurial/win32.py +++ b/mercurial/win32.py @@ -14,6 +14,8 @@ import os import random import subprocess +from . import encoding + _kernel32 = ctypes.windll.kernel32 _advapi32 = ctypes.windll.advapi32 _user32 = ctypes.windll.user32 @@ -424,8 +426,8 @@ def spawndetached(args): 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 @@ def spawndetached(args): 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(