Show More
@@ -156,10 +156,33 b' if sys.version_info > (3, 5, 0):' | |||
|
156 | 156 | |
|
157 | 157 | osenvironb = getattr(os, 'environb', None) |
|
158 | 158 | if osenvironb is None: |
|
159 | # Windows lacks os.environb, for instance. | |
|
160 | osenvironb = { | |
|
161 | _bytespath(k): _bytespath(v) for k, v in os.environ.items() | |
|
162 | } | |
|
159 | # Windows lacks os.environb, for instance. A proxy over the real thing | |
|
160 | # instead of a copy allows the environment to be updated via bytes on | |
|
161 | # all platforms. | |
|
162 | class environbytes(object): | |
|
163 | def __init__(self, strenv): | |
|
164 | self.__len__ = strenv.__len__ | |
|
165 | self.clear = strenv.clear | |
|
166 | self._strenv = strenv | |
|
167 | def __getitem__(self, k): | |
|
168 | v = self._strenv.__getitem__(_strpath(k)) | |
|
169 | return _bytespath(v) | |
|
170 | def __setitem__(self, k, v): | |
|
171 | self._strenv.__setitem__(_strpath(k), _strpath(v)) | |
|
172 | def __delitem__(self, k): | |
|
173 | self._strenv.__delitem__(_strpath(k)) | |
|
174 | def __contains__(self, k): | |
|
175 | return self._strenv.__contains__(_strpath(k)) | |
|
176 | def __iter__(self): | |
|
177 | return iter([_bytespath(k) for k in iter(self._strenv)]) | |
|
178 | def get(self, k, default=None): | |
|
179 | v = self._strenv.get(_strpath(k), _strpath(default)) | |
|
180 | return _bytespath(v) | |
|
181 | def pop(self, k, default=None): | |
|
182 | v = self._strenv.pop(_strpath(k), _strpath(default)) | |
|
183 | return _bytespath(v) | |
|
184 | ||
|
185 | osenvironb = environbytes(os.environ) | |
|
163 | 186 | |
|
164 | 187 | elif sys.version_info >= (3, 0, 0): |
|
165 | 188 | print('%s is only supported on Python 3.5+ and 2.7, not %s' % |
General Comments 0
You need to be logged in to leave comments.
Login now