##// END OF EJS Templates
py3: stop normalizing .encode()/.decode() arguments to unicode...
Gregory Szorc -
r43361:127cc1f7 default
parent child Browse files
Show More
@@ -49,7 +49,7 b' if ispy3:'
49 def sysstr(s):
49 def sysstr(s):
50 if isinstance(s, builtins.str):
50 if isinstance(s, builtins.str):
51 return s
51 return s
52 return s.decode(u'latin-1')
52 return s.decode('latin-1')
53
53
54 def opentext(f):
54 def opentext(f):
55 return open(f, 'r')
55 return open(f, 'r')
@@ -394,7 +394,7 b' class _gitlfsremote(object):'
394
394
395 def encodestr(x):
395 def encodestr(x):
396 if isinstance(x, pycompat.unicode):
396 if isinstance(x, pycompat.unicode):
397 return x.encode(u'utf-8')
397 return x.encode('utf-8')
398 return x
398 return x
399
399
400 return pycompat.rapply(encodestr, response)
400 return pycompat.rapply(encodestr, response)
@@ -166,14 +166,6 b' if sys.version_info[0] >= 3:'
166 if arg1idx is not None:
166 if arg1idx is not None:
167 _ensureunicode(arg1idx)
167 _ensureunicode(arg1idx)
168
168
169 # .encode() and .decode() on str/bytes/unicode don't accept
170 # byte strings on Python 3.
171 elif fn in ('encode', 'decode') and _isop(i - 1, '.'):
172 for argn in range(2):
173 argidx = _findargnofcall(argn)
174 if argidx is not None:
175 _ensureunicode(argidx)
176
177 # It changes iteritems/values to items/values as they are not
169 # It changes iteritems/values to items/values as they are not
178 # present in Python 3 world.
170 # present in Python 3 world.
179 elif fn in ('iteritems', 'itervalues') and not (
171 elif fn in ('iteritems', 'itervalues') and not (
@@ -190,7 +182,7 b' if sys.version_info[0] >= 3:'
190 # ``replacetoken`` or any mechanism that changes semantics of module
182 # ``replacetoken`` or any mechanism that changes semantics of module
191 # loading is changed. Otherwise cached bytecode may get loaded without
183 # loading is changed. Otherwise cached bytecode may get loaded without
192 # the new transformation mechanisms applied.
184 # the new transformation mechanisms applied.
193 BYTECODEHEADER = b'HG\x00\x12'
185 BYTECODEHEADER = b'HG\x00\x13'
194
186
195 class hgloader(importlib.machinery.SourceFileLoader):
187 class hgloader(importlib.machinery.SourceFileLoader):
196 """Custom module loader that transforms source code.
188 """Custom module loader that transforms source code.
@@ -206,7 +206,7 b' if ispy3:'
206 ) and not hasattr( # hasattr-py3-only
206 ) and not hasattr( # hasattr-py3-only
207 s, u'__bytes__'
207 s, u'__bytes__'
208 ):
208 ):
209 s = str(s).encode(u'ascii')
209 s = str(s).encode('ascii')
210 return bytes.__new__(cls, s)
210 return bytes.__new__(cls, s)
211
211
212 def __getitem__(self, key):
212 def __getitem__(self, key):
@@ -237,7 +237,7 b' if ispy3:'
237 This never raises UnicodeEncodeError, but only ASCII characters
237 This never raises UnicodeEncodeError, but only ASCII characters
238 can be round-trip by sysstr(sysbytes(s)).
238 can be round-trip by sysstr(sysbytes(s)).
239 """
239 """
240 return s.encode(u'utf-8')
240 return s.encode('utf-8')
241
241
242 def sysstr(s):
242 def sysstr(s):
243 """Return a keyword str to be passed to Python functions such as
243 """Return a keyword str to be passed to Python functions such as
@@ -249,18 +249,18 b' if ispy3:'
249 """
249 """
250 if isinstance(s, builtins.str):
250 if isinstance(s, builtins.str):
251 return s
251 return s
252 return s.decode(u'latin-1')
252 return s.decode('latin-1')
253
253
254 def strurl(url):
254 def strurl(url):
255 """Converts a bytes url back to str"""
255 """Converts a bytes url back to str"""
256 if isinstance(url, bytes):
256 if isinstance(url, bytes):
257 return url.decode(u'ascii')
257 return url.decode('ascii')
258 return url
258 return url
259
259
260 def bytesurl(url):
260 def bytesurl(url):
261 """Converts a str url to bytes by encoding in ascii"""
261 """Converts a str url to bytes by encoding in ascii"""
262 if isinstance(url, str):
262 if isinstance(url, str):
263 return url.encode(u'ascii')
263 return url.encode('ascii')
264 return url
264 return url
265
265
266 def raisewithtb(exc, tb):
266 def raisewithtb(exc, tb):
General Comments 0
You need to be logged in to leave comments. Login now