Mercurial > public > mercurial-scm > hg-stable
diff mercurial/encoding.py @ 33782:f5fc54e7e467
encoding: drop circular import by proxying through '<policy>.charencode'
I decided not to split charencode.c to new C extension module because it
would duplicate binary codes unnecessarily.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Mon, 31 Jul 2017 23:13:47 +0900 |
parents | ce96efec8112 |
children | dabe1f11ae3a |
line wrap: on
line diff
--- a/mercurial/encoding.py Mon Jul 31 23:40:36 2017 +0900 +++ b/mercurial/encoding.py Mon Jul 31 23:13:47 2017 +0900 @@ -18,6 +18,11 @@ pycompat, ) +charencode = policy.importmod(r'charencode') + +asciilower = charencode.asciilower +asciiupper = charencode.asciiupper + _sysstr = pycompat.sysstr if pycompat.ispy3: @@ -318,38 +323,6 @@ return concat(usub.encode(_sysstr(encoding))) return ellipsis # no enough room for multi-column characters -def _asciilower(s): - '''convert a string to lowercase if ASCII - - Raises UnicodeDecodeError if non-ASCII characters are found.''' - s.decode('ascii') - return s.lower() - -def asciilower(s): - # delay importing avoids cyclic dependency around "parsers" in - # pure Python build (util => i18n => encoding => parsers => util) - parsers = policy.importmod(r'parsers') - impl = getattr(parsers, 'asciilower', _asciilower) - global asciilower - asciilower = impl - return impl(s) - -def _asciiupper(s): - '''convert a string to uppercase if ASCII - - Raises UnicodeDecodeError if non-ASCII characters are found.''' - s.decode('ascii') - return s.upper() - -def asciiupper(s): - # delay importing avoids cyclic dependency around "parsers" in - # pure Python build (util => i18n => encoding => parsers => util) - parsers = policy.importmod(r'parsers') - impl = getattr(parsers, 'asciiupper', _asciiupper) - global asciiupper - asciiupper = impl - return impl(s) - def lower(s): "best-effort encoding-aware case-folding of local string s" try: