##// END OF EJS Templates
tests: require Python 3.5+ in run-tests.py...
Gregory Szorc -
r49711:078e1e1c default
parent child Browse files
Show More
@@ -45,6 +45,7 b''
45
45
46 from __future__ import absolute_import, print_function
46 from __future__ import absolute_import, print_function
47
47
48
48 import argparse
49 import argparse
49 import collections
50 import collections
50 import contextlib
51 import contextlib
@@ -154,81 +155,70 b' if pygmentspresent:'
154
155
155 origenviron = os.environ.copy()
156 origenviron = os.environ.copy()
156
157
157
158 if sys.version_info < (3, 5, 0):
158 if sys.version_info > (3, 5, 0):
159 PYTHON3 = True
160 xrange = range # we use xrange in one place, and we'd rather not use range
161
162 def _sys2bytes(p):
163 if p is None:
164 return p
165 return p.encode('utf-8')
166
167 def _bytes2sys(p):
168 if p is None:
169 return p
170 return p.decode('utf-8')
171
172 osenvironb = getattr(os, 'environb', None)
173 if osenvironb is None:
174 # Windows lacks os.environb, for instance. A proxy over the real thing
175 # instead of a copy allows the environment to be updated via bytes on
176 # all platforms.
177 class environbytes(object):
178 def __init__(self, strenv):
179 self.__len__ = strenv.__len__
180 self.clear = strenv.clear
181 self._strenv = strenv
182
183 def __getitem__(self, k):
184 v = self._strenv.__getitem__(_bytes2sys(k))
185 return _sys2bytes(v)
186
187 def __setitem__(self, k, v):
188 self._strenv.__setitem__(_bytes2sys(k), _bytes2sys(v))
189
190 def __delitem__(self, k):
191 self._strenv.__delitem__(_bytes2sys(k))
192
193 def __contains__(self, k):
194 return self._strenv.__contains__(_bytes2sys(k))
195
196 def __iter__(self):
197 return iter([_sys2bytes(k) for k in iter(self._strenv)])
198
199 def get(self, k, default=None):
200 v = self._strenv.get(_bytes2sys(k), _bytes2sys(default))
201 return _sys2bytes(v)
202
203 def pop(self, k, default=None):
204 v = self._strenv.pop(_bytes2sys(k), _bytes2sys(default))
205 return _sys2bytes(v)
206
207 osenvironb = environbytes(os.environ)
208
209 getcwdb = getattr(os, 'getcwdb')
210 if not getcwdb or WINDOWS:
211 getcwdb = lambda: _sys2bytes(os.getcwd())
212
213 elif sys.version_info >= (3, 0, 0):
214 print(
159 print(
215 '%s is only supported on Python 3.5+ and 2.7, not %s'
160 '%s is only supported on Python 3.5+, not %s'
216 % (sys.argv[0], '.'.join(str(v) for v in sys.version_info[:3]))
161 % (sys.argv[0], '.'.join(str(v) for v in sys.version_info[:3]))
217 )
162 )
218 sys.exit(70) # EX_SOFTWARE from `man 3 sysexit`
163 sys.exit(70) # EX_SOFTWARE from `man 3 sysexit`
219 else:
164
220 PYTHON3 = False
165 PYTHON3 = True
221
166 xrange = range # we use xrange in one place, and we'd rather not use range
222 # In python 2.x, path operations are generally done using
167
223 # bytestrings by default, so we don't have to do any extra
168
224 # fiddling there. We define the wrapper functions anyway just to
169 def _sys2bytes(p):
225 # help keep code consistent between platforms.
170 if p is None:
226 def _sys2bytes(p):
171 return p
172 return p.encode('utf-8')
173
174
175 def _bytes2sys(p):
176 if p is None:
227 return p
177 return p
228
178 return p.decode('utf-8')
229 _bytes2sys = _sys2bytes
179
230 osenvironb = os.environ
180
231 getcwdb = os.getcwd
181 osenvironb = getattr(os, 'environb', None)
182 if osenvironb is None:
183 # Windows lacks os.environb, for instance. A proxy over the real thing
184 # instead of a copy allows the environment to be updated via bytes on
185 # all platforms.
186 class environbytes(object):
187 def __init__(self, strenv):
188 self.__len__ = strenv.__len__
189 self.clear = strenv.clear
190 self._strenv = strenv
191
192 def __getitem__(self, k):
193 v = self._strenv.__getitem__(_bytes2sys(k))
194 return _sys2bytes(v)
195
196 def __setitem__(self, k, v):
197 self._strenv.__setitem__(_bytes2sys(k), _bytes2sys(v))
198
199 def __delitem__(self, k):
200 self._strenv.__delitem__(_bytes2sys(k))
201
202 def __contains__(self, k):
203 return self._strenv.__contains__(_bytes2sys(k))
204
205 def __iter__(self):
206 return iter([_sys2bytes(k) for k in iter(self._strenv)])
207
208 def get(self, k, default=None):
209 v = self._strenv.get(_bytes2sys(k), _bytes2sys(default))
210 return _sys2bytes(v)
211
212 def pop(self, k, default=None):
213 v = self._strenv.pop(_bytes2sys(k), _bytes2sys(default))
214 return _sys2bytes(v)
215
216 osenvironb = environbytes(os.environ)
217
218 getcwdb = getattr(os, 'getcwdb')
219 if not getcwdb or WINDOWS:
220 getcwdb = lambda: _sys2bytes(os.getcwd())
221
232
222
233 if WINDOWS:
223 if WINDOWS:
234 _getcwdb = getcwdb
224 _getcwdb = getcwdb
General Comments 0
You need to be logged in to leave comments. Login now