mercurial/encoding.py
changeset 33761 f5fc54e7e467
parent 33022 ce96efec8112
child 33811 dabe1f11ae3a
equal deleted inserted replaced
33760:cd2aca0808f8 33761:f5fc54e7e467
    15 from . import (
    15 from . import (
    16     error,
    16     error,
    17     policy,
    17     policy,
    18     pycompat,
    18     pycompat,
    19 )
    19 )
       
    20 
       
    21 charencode = policy.importmod(r'charencode')
       
    22 
       
    23 asciilower = charencode.asciilower
       
    24 asciiupper = charencode.asciiupper
    20 
    25 
    21 _sysstr = pycompat.sysstr
    26 _sysstr = pycompat.sysstr
    22 
    27 
    23 if pycompat.ispy3:
    28 if pycompat.ispy3:
    24     unichr = chr
    29     unichr = chr
   316         usub = uslice(i)
   321         usub = uslice(i)
   317         if ucolwidth(usub) <= width:
   322         if ucolwidth(usub) <= width:
   318             return concat(usub.encode(_sysstr(encoding)))
   323             return concat(usub.encode(_sysstr(encoding)))
   319     return ellipsis # no enough room for multi-column characters
   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 def lower(s):
   326 def lower(s):
   354     "best-effort encoding-aware case-folding of local string s"
   327     "best-effort encoding-aware case-folding of local string s"
   355     try:
   328     try:
   356         return asciilower(s)
   329         return asciilower(s)
   357     except UnicodeDecodeError:
   330     except UnicodeDecodeError: