Show More
@@ -246,7 +246,7 b' class converter_source(object):' | |||||
246 | if not encoding: |
|
246 | if not encoding: | |
247 | encoding = self.encoding or b'utf-8' |
|
247 | encoding = self.encoding or b'utf-8' | |
248 |
|
248 | |||
249 |
if isinstance(s, |
|
249 | if isinstance(s, str): | |
250 | return s.encode("utf-8") |
|
250 | return s.encode("utf-8") | |
251 | try: |
|
251 | try: | |
252 | return s.decode(pycompat.sysstr(encoding)).encode("utf-8") |
|
252 | return s.decode(pycompat.sysstr(encoding)).encode("utf-8") |
@@ -86,7 +86,7 b' def readauthormap(ui, authorfile, author' | |||||
86 |
|
86 | |||
87 |
|
87 | |||
88 | def recode(s): |
|
88 | def recode(s): | |
89 |
if isinstance(s, |
|
89 | if isinstance(s, str): | |
90 | return s.encode(pycompat.sysstr(orig_encoding), 'replace') |
|
90 | return s.encode(pycompat.sysstr(orig_encoding), 'replace') | |
91 | else: |
|
91 | else: | |
92 | return s.decode('utf-8').encode( |
|
92 | return s.decode('utf-8').encode( |
@@ -113,7 +113,7 b' class darcs_source(common.converter_sour' | |||||
113 | shutil.rmtree(self.tmppath, ignore_errors=True) |
|
113 | shutil.rmtree(self.tmppath, ignore_errors=True) | |
114 |
|
114 | |||
115 | def recode(self, s, encoding=None): |
|
115 | def recode(self, s, encoding=None): | |
116 |
if isinstance(s, |
|
116 | if isinstance(s, str): | |
117 | # XMLParser returns unicode objects for anything it can't |
|
117 | # XMLParser returns unicode objects for anything it can't | |
118 | # encode into ASCII. We convert them back to str to get |
|
118 | # encode into ASCII. We convert them back to str to get | |
119 | # recode's normal conversion behavior. |
|
119 | # recode's normal conversion behavior. |
@@ -273,7 +273,7 b' def _urlerrorreason(urlerror):' | |||||
273 | except (AttributeError, IndexError): |
|
273 | except (AttributeError, IndexError): | |
274 | # it might be anything, for example a string |
|
274 | # it might be anything, for example a string | |
275 | reason = inst.reason |
|
275 | reason = inst.reason | |
276 |
if isinstance(reason, |
|
276 | if isinstance(reason, str): | |
277 | # SSLError of Python 2.7.9 contains a unicode |
|
277 | # SSLError of Python 2.7.9 contains a unicode | |
278 | reason = encoding.unitolocal(reason) |
|
278 | reason = encoding.unitolocal(reason) | |
279 | return reason |
|
279 | return reason | |
@@ -406,7 +406,7 b' class _gitlfsremote(object):' | |||||
406 | ) |
|
406 | ) | |
407 |
|
407 | |||
408 | def encodestr(x): |
|
408 | def encodestr(x): | |
409 |
if isinstance(x, |
|
409 | if isinstance(x, str): | |
410 | return x.encode('utf-8') |
|
410 | return x.encode('utf-8') | |
411 | return x |
|
411 | return x | |
412 |
|
412 |
@@ -219,9 +219,7 b' def _loadhgrc(orig, ui, wdirvfs, hgvfs, ' | |||||
219 | rawparams = encoding.unifromlocal(wdirvfs.read(b".arcconfig")) |
|
219 | rawparams = encoding.unifromlocal(wdirvfs.read(b".arcconfig")) | |
220 | # json.loads only returns unicode strings |
|
220 | # json.loads only returns unicode strings | |
221 | arcconfig = pycompat.rapply( |
|
221 | arcconfig = pycompat.rapply( | |
222 | lambda x: encoding.unitolocal(x) |
|
222 | lambda x: encoding.unitolocal(x) if isinstance(x, str) else x, | |
223 | if isinstance(x, pycompat.unicode) |
|
|||
224 | else x, |
|
|||
225 | pycompat.json_loads(rawparams), |
|
223 | pycompat.json_loads(rawparams), | |
226 | ) |
|
224 | ) | |
227 |
|
225 | |||
@@ -447,9 +445,7 b' def callconduit(ui, name, params):' | |||||
447 | time.sleep(retry_interval) |
|
445 | time.sleep(retry_interval) | |
448 | ui.debug(b'Conduit Response: %s\n' % body) |
|
446 | ui.debug(b'Conduit Response: %s\n' % body) | |
449 | parsed = pycompat.rapply( |
|
447 | parsed = pycompat.rapply( | |
450 | lambda x: encoding.unitolocal(x) |
|
448 | lambda x: encoding.unitolocal(x) if isinstance(x, str) else x, | |
451 | if isinstance(x, pycompat.unicode) |
|
|||
452 | else x, |
|
|||
453 | # json.loads only accepts bytes from py3.6+ |
|
449 | # json.loads only accepts bytes from py3.6+ | |
454 | pycompat.json_loads(encoding.unifromlocal(body)), |
|
450 | pycompat.json_loads(encoding.unifromlocal(body)), | |
455 | ) |
|
451 | ) | |
@@ -473,9 +469,7 b' def debugcallconduit(ui, repo, name):' | |||||
473 | rawparams = encoding.unifromlocal(ui.fin.read()) |
|
469 | rawparams = encoding.unifromlocal(ui.fin.read()) | |
474 | # json.loads only returns unicode strings |
|
470 | # json.loads only returns unicode strings | |
475 | params = pycompat.rapply( |
|
471 | params = pycompat.rapply( | |
476 | lambda x: encoding.unitolocal(x) |
|
472 | lambda x: encoding.unitolocal(x) if isinstance(x, str) else x, | |
477 | if isinstance(x, pycompat.unicode) |
|
|||
478 | else x, |
|
|||
479 | pycompat.json_loads(rawparams), |
|
473 | pycompat.json_loads(rawparams), | |
480 | ) |
|
474 | ) | |
481 | # json.dumps only accepts unicode strings |
|
475 | # json.dumps only accepts unicode strings |
@@ -94,7 +94,7 b' def decode(arg):' | |||||
94 |
|
94 | |||
95 |
|
95 | |||
96 | def encode(arg): |
|
96 | def encode(arg): | |
97 |
if isinstance(arg, |
|
97 | if isinstance(arg, str): | |
98 | return arg.encode(_encoding) |
|
98 | return arg.encode(_encoding) | |
99 | elif isinstance(arg, tuple): |
|
99 | elif isinstance(arg, tuple): | |
100 | return tuple(map(encode, arg)) |
|
100 | return tuple(map(encode, arg)) | |
@@ -135,7 +135,7 b' def basewrapper(func, argtype, enc, dec,' | |||||
135 |
|
135 | |||
136 |
|
136 | |||
137 | def wrapper(func, args, kwds): |
|
137 | def wrapper(func, args, kwds): | |
138 |
return basewrapper(func, |
|
138 | return basewrapper(func, str, encode, decode, args, kwds) | |
139 |
|
139 | |||
140 |
|
140 | |||
141 | def reversewrapper(func, args, kwds): |
|
141 | def reversewrapper(func, args, kwds): |
@@ -36,7 +36,7 b' def hgweb(config, name=None, baseui=None' | |||||
36 | - list of virtual:real tuples (multi-repo view) |
|
36 | - list of virtual:real tuples (multi-repo view) | |
37 | """ |
|
37 | """ | |
38 |
|
38 | |||
39 |
if isinstance(config, |
|
39 | if isinstance(config, str): | |
40 | raise error.ProgrammingError( |
|
40 | raise error.ProgrammingError( | |
41 | b'Mercurial only supports encoded strings: %r' % config |
|
41 | b'Mercurial only supports encoded strings: %r' % config | |
42 | ) |
|
42 | ) |
@@ -85,9 +85,9 b' def gettext(message):' | |||||
85 |
|
85 | |||
86 | cache = _msgcache.setdefault(encoding.encoding, {}) |
|
86 | cache = _msgcache.setdefault(encoding.encoding, {}) | |
87 | if message not in cache: |
|
87 | if message not in cache: | |
88 |
if type(message) is |
|
88 | if type(message) is str: | |
89 | # goofy unicode docstrings in test |
|
89 | # goofy unicode docstrings in test | |
90 |
paragraphs = message.split(u'\n\n') # type: List[ |
|
90 | paragraphs = message.split(u'\n\n') # type: List[str] | |
91 | else: |
|
91 | else: | |
92 | # should be ascii, but we have unicode docstrings in test, which |
|
92 | # should be ascii, but we have unicode docstrings in test, which | |
93 | # are converted to utf-8 bytes on Python 3. |
|
93 | # are converted to utf-8 bytes on Python 3. |
@@ -227,7 +227,7 b' def callcatch(ui, func):' | |||||
227 | except (AttributeError, IndexError): |
|
227 | except (AttributeError, IndexError): | |
228 | # it might be anything, for example a string |
|
228 | # it might be anything, for example a string | |
229 | reason = inst.reason |
|
229 | reason = inst.reason | |
230 |
if isinstance(reason, |
|
230 | if isinstance(reason, str): | |
231 | # SSLError of Python 2.7.9 contains a unicode |
|
231 | # SSLError of Python 2.7.9 contains a unicode | |
232 | reason = encoding.unitolocal(reason) |
|
232 | reason = encoding.unitolocal(reason) | |
233 | ui.error(_(b"abort: error: %s\n") % stringutil.forcebytestr(reason)) |
|
233 | ui.error(_(b"abort: error: %s\n") % stringutil.forcebytestr(reason)) |
@@ -372,9 +372,7 b' def obfuscate(text):' | |||||
372 | """Any text. Returns the input text rendered as a sequence of |
|
372 | """Any text. Returns the input text rendered as a sequence of | |
373 | XML entities. |
|
373 | XML entities. | |
374 | """ |
|
374 | """ | |
375 | text = pycompat.unicode( |
|
375 | text = str(text, pycompat.sysstr(encoding.encoding), r'replace') | |
376 | text, pycompat.sysstr(encoding.encoding), r'replace' |
|
|||
377 | ) |
|
|||
378 | return b''.join([b'&#%d;' % ord(c) for c in text]) |
|
376 | return b''.join([b'&#%d;' % ord(c) for c in text]) | |
379 |
|
377 | |||
380 |
|
378 |
General Comments 0
You need to be logged in to leave comments.
Login now