Show More
@@ -0,0 +1,22 b'' | |||
|
1 | # charencode.py - miscellaneous character encoding | |
|
2 | # | |
|
3 | # Copyright 2005-2009 Matt Mackall <mpm@selenic.com> and others | |
|
4 | # | |
|
5 | # This software may be used and distributed according to the terms of the | |
|
6 | # GNU General Public License version 2 or any later version. | |
|
7 | ||
|
8 | from __future__ import absolute_import | |
|
9 | ||
|
10 | def asciilower(s): | |
|
11 | '''convert a string to lowercase if ASCII | |
|
12 | ||
|
13 | Raises UnicodeDecodeError if non-ASCII characters are found.''' | |
|
14 | s.decode('ascii') | |
|
15 | return s.lower() | |
|
16 | ||
|
17 | def asciiupper(s): | |
|
18 | '''convert a string to uppercase if ASCII | |
|
19 | ||
|
20 | Raises UnicodeDecodeError if non-ASCII characters are found.''' | |
|
21 | s.decode('ascii') | |
|
22 | return s.upper() |
@@ -18,6 +18,11 b' from . import (' | |||
|
18 | 18 | pycompat, |
|
19 | 19 | ) |
|
20 | 20 | |
|
21 | charencode = policy.importmod(r'charencode') | |
|
22 | ||
|
23 | asciilower = charencode.asciilower | |
|
24 | asciiupper = charencode.asciiupper | |
|
25 | ||
|
21 | 26 | _sysstr = pycompat.sysstr |
|
22 | 27 | |
|
23 | 28 | if pycompat.ispy3: |
@@ -318,38 +323,6 b" def trim(s, width, ellipsis='', leftside" | |||
|
318 | 323 | return concat(usub.encode(_sysstr(encoding))) |
|
319 | 324 | return ellipsis # no enough room for multi-column characters |
|
320 | 325 | |
|
321 | def _asciilower(s): | |
|
322 | '''convert a string to lowercase if ASCII | |
|
323 | ||
|
324 | Raises UnicodeDecodeError if non-ASCII characters are found.''' | |
|
325 | s.decode('ascii') | |
|
326 | return s.lower() | |
|
327 | ||
|
328 | def asciilower(s): | |
|
329 | # delay importing avoids cyclic dependency around "parsers" in | |
|
330 | # pure Python build (util => i18n => encoding => parsers => util) | |
|
331 | parsers = policy.importmod(r'parsers') | |
|
332 | impl = getattr(parsers, 'asciilower', _asciilower) | |
|
333 | global asciilower | |
|
334 | asciilower = impl | |
|
335 | return impl(s) | |
|
336 | ||
|
337 | def _asciiupper(s): | |
|
338 | '''convert a string to uppercase if ASCII | |
|
339 | ||
|
340 | Raises UnicodeDecodeError if non-ASCII characters are found.''' | |
|
341 | s.decode('ascii') | |
|
342 | return s.upper() | |
|
343 | ||
|
344 | def asciiupper(s): | |
|
345 | # delay importing avoids cyclic dependency around "parsers" in | |
|
346 | # pure Python build (util => i18n => encoding => parsers => util) | |
|
347 | parsers = policy.importmod(r'parsers') | |
|
348 | impl = getattr(parsers, 'asciiupper', _asciiupper) | |
|
349 | global asciiupper | |
|
350 | asciiupper = impl | |
|
351 | return impl(s) | |
|
352 | ||
|
353 | 326 | def lower(s): |
|
354 | 327 | "best-effort encoding-aware case-folding of local string s" |
|
355 | 328 | try: |
@@ -80,7 +80,9 b' def _importfrom(pkgname, modname):' | |||
|
80 | 80 | |
|
81 | 81 | # map import request to other package or module |
|
82 | 82 | _modredirects = { |
|
83 | (r'cext', r'charencode'): (r'cext', r'parsers'), | |
|
83 | 84 | (r'cffi', r'base85'): (r'pure', r'base85'), |
|
85 | (r'cffi', r'charencode'): (r'pure', r'charencode'), | |
|
84 | 86 | (r'cffi', r'diffhelpers'): (r'pure', r'diffhelpers'), |
|
85 | 87 | (r'cffi', r'parsers'): (r'pure', r'parsers'), |
|
86 | 88 | } |
General Comments 0
You need to be logged in to leave comments.
Login now