Mercurial > hg
comparison mercurial/pycompat.py @ 30663:bb0d5aad761a
py3: have bytes version of os.getenv
os.getenv() on python 3 deals with unicodes. If we want to pass bytes. we have
os.getenvb() which deals with bytes. This patch adds up a pycompat.osgetenv
which deals with bytes on both python 2 and 3.
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Mon, 19 Dec 2016 02:35:38 +0530 |
parents | a82a6eee2613 |
children | 3fcaf0f660ce |
comparison
equal
deleted
inserted
replaced
30662:69459fdf3b1b | 30663:bb0d5aad761a |
---|---|
43 # A bytes version of os.name. | 43 # A bytes version of os.name. |
44 osname = os.name.encode('ascii') | 44 osname = os.name.encode('ascii') |
45 ospathsep = os.pathsep.encode('ascii') | 45 ospathsep = os.pathsep.encode('ascii') |
46 ossep = os.sep.encode('ascii') | 46 ossep = os.sep.encode('ascii') |
47 osaltsep = os.altsep | 47 osaltsep = os.altsep |
48 osgetenv = os.getenvb | |
48 if osaltsep: | 49 if osaltsep: |
49 osaltsep = osaltsep.encode('ascii') | 50 osaltsep = osaltsep.encode('ascii') |
50 # os.getcwd() on Python 3 returns string, but it has os.getcwdb() which | 51 # os.getcwd() on Python 3 returns string, but it has os.getcwdb() which |
51 # returns bytes. | 52 # returns bytes. |
52 getcwd = os.getcwdb | 53 getcwd = os.getcwdb |
154 stdout = sys.stdout | 155 stdout = sys.stdout |
155 stderr = sys.stderr | 156 stderr = sys.stderr |
156 sysargv = sys.argv | 157 sysargv = sys.argv |
157 sysplatform = sys.platform | 158 sysplatform = sys.platform |
158 getcwd = os.getcwd | 159 getcwd = os.getcwd |
160 osgetenv = os.getenv | |
159 | 161 |
160 stringio = io.StringIO | 162 stringio = io.StringIO |
161 empty = _queue.Empty | 163 empty = _queue.Empty |
162 queue = _queue.Queue | 164 queue = _queue.Queue |
163 | 165 |