# HG changeset patch # User Yuya Nishihara # Date 1501510427 -32400 # Node ID f5fc54e7e467790000c66c4cb1832fd466ab4052 # Parent cd2aca0808f859d2bcd7643a2b5cffadbbdab947 encoding: drop circular import by proxying through '.charencode' I decided not to split charencode.c to new C extension module because it would duplicate binary codes unnecessarily. diff -r cd2aca0808f8 -r f5fc54e7e467 mercurial/encoding.py --- 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: diff -r cd2aca0808f8 -r f5fc54e7e467 mercurial/policy.py --- a/mercurial/policy.py Mon Jul 31 23:40:36 2017 +0900 +++ b/mercurial/policy.py Mon Jul 31 23:13:47 2017 +0900 @@ -80,7 +80,9 @@ # map import request to other package or module _modredirects = { + (r'cext', r'charencode'): (r'cext', r'parsers'), (r'cffi', r'base85'): (r'pure', r'base85'), + (r'cffi', r'charencode'): (r'pure', r'charencode'), (r'cffi', r'diffhelpers'): (r'pure', r'diffhelpers'), (r'cffi', r'parsers'): (r'pure', r'parsers'), } diff -r cd2aca0808f8 -r f5fc54e7e467 mercurial/pure/charencode.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial/pure/charencode.py Mon Jul 31 23:13:47 2017 +0900 @@ -0,0 +1,22 @@ +# charencode.py - miscellaneous character encoding +# +# Copyright 2005-2009 Matt Mackall and others +# +# This software may be used and distributed according to the terms of the +# GNU General Public License version 2 or any later version. + +from __future__ import absolute_import + +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 asciiupper(s): + '''convert a string to uppercase if ASCII + + Raises UnicodeDecodeError if non-ASCII characters are found.''' + s.decode('ascii') + return s.upper()