[PATCH 2 of 7] py3: replace os.getenv with pycompat.osgetenv

Pulkit Goyal 7895pulkit at gmail.com
Wed Dec 21 17:03:47 EST 2016


# HG changeset patch
# User Pulkit Goyal <7895pulkit at gmail.com>
# Date 1482096289 -19800
#      Mon Dec 19 02:54:49 2016 +0530
# Node ID 64800628e1ffbe3d99535c2a8b4d0bc48c822a20
# Parent  eee84d7c0647a50d4e9828b324e1e37214abd169
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

diff -r eee84d7c0647 -r 64800628e1ff hgext/largefiles/lfutil.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:
diff -r eee84d7c0647 -r 64800628e1ff mercurial/profiling.py
--- 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'):
diff -r eee84d7c0647 -r 64800628e1ff mercurial/url.py
--- a/mercurial/url.py	Mon Dec 19 02:35:38 2016 +0530
+++ b/mercurial/url.py	Mon Dec 19 02:54:49 2016 +0530
@@ -19,6 +19,7 @@
     error,
     httpconnection as httpconnectionmod,
     keepalive,
+    pycompat,
     sslutil,
     util,
 )
@@ -80,7 +81,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:
@@ -98,7 +100,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"):


More information about the Mercurial-devel mailing list