py3: replace os.getenv with pycompat.osgetenv
authorPulkit Goyal <7895pulkit@gmail.com>
Mon, 19 Dec 2016 02:54:49 +0530
changeset 30664 69acfd2ca11e
parent 30663 bb0d5aad761a
child 30665 01721d382c16
py3: replace os.getenv with pycompat.osgetenv os.getenv deals with unicodes on Python 3, so we have pycompat.osgetenv to deal with bytes. This patch replaces occurrences on os.getenv with pycompat.osgetenv
hgext/largefiles/lfutil.py
mercurial/profiling.py
mercurial/url.py
--- a/hgext/largefiles/lfutil.py	Mon Dec 19 02:35:38 2016 +0530
+++ b/hgext/largefiles/lfutil.py	Mon Dec 19 02:54:49 2016 +0530
@@ -74,18 +74,19 @@
     if path:
         return path
     if pycompat.osname == 'nt':
-        appdata = os.getenv('LOCALAPPDATA', os.getenv('APPDATA'))
+        appdata = pycompat.osgetenv('LOCALAPPDATA',\
+                        pycompat.osgetenv('APPDATA'))
         if appdata:
             return os.path.join(appdata, longname)
     elif platform.system() == 'Darwin':
-        home = os.getenv('HOME')
+        home = pycompat.osgetenv('HOME')
         if home:
             return os.path.join(home, 'Library', 'Caches', longname)
     elif pycompat.osname == 'posix':
-        path = os.getenv('XDG_CACHE_HOME')
+        path = pycompat.osgetenv('XDG_CACHE_HOME')
         if path:
             return os.path.join(path, longname)
-        home = os.getenv('HOME')
+        home = pycompat.osgetenv('HOME')
         if home:
             return os.path.join(home, '.cache', longname)
     else:
--- a/mercurial/profiling.py	Mon Dec 19 02:35:38 2016 +0530
+++ b/mercurial/profiling.py	Mon Dec 19 02:54:49 2016 +0530
@@ -8,12 +8,12 @@
 from __future__ import absolute_import, print_function
 
 import contextlib
-import os
 import time
 
 from .i18n import _
 from . import (
     error,
+    pycompat,
     util,
 )
 
@@ -120,7 +120,7 @@
     Profiling is active when the context manager is active. When the context
     manager exits, profiling results will be written to the configured output.
     """
-    profiler = os.getenv('HGPROF')
+    profiler = pycompat.osgetenv('HGPROF')
     if profiler is None:
         profiler = ui.config('profiling', 'type', default='stat')
     if profiler not in ('ls', 'stat', 'flame'):
--- a/mercurial/url.py	Mon Dec 19 02:35:38 2016 +0530
+++ b/mercurial/url.py	Mon Dec 19 02:54:49 2016 +0530
@@ -18,6 +18,7 @@
     error,
     httpconnection as httpconnectionmod,
     keepalive,
+    pycompat,
     sslutil,
     util,
 )
@@ -79,7 +80,8 @@
 
 class proxyhandler(urlreq.proxyhandler):
     def __init__(self, ui):
-        proxyurl = ui.config("http_proxy", "host") or os.getenv('http_proxy')
+        proxyurl = (ui.config("http_proxy", "host") or
+                        pycompat.osgetenv('http_proxy'))
         # XXX proxyauthinfo = None
 
         if proxyurl:
@@ -97,7 +99,7 @@
             no_list.extend([p.lower() for
                             p in ui.configlist("http_proxy", "no")])
             no_list.extend([p.strip().lower() for
-                            p in os.getenv("no_proxy", '').split(',')
+                            p in pycompat.osgetenv("no_proxy", '').split(',')
                             if p.strip()])
             # "http_proxy.always" config is for running tests on localhost
             if ui.configbool("http_proxy", "always"):