File: //usr/lib64/python2.7/site-packages/mercurial/encoding.pyc
�
Hq�Qc @ sm d d l Z d d l Z d d l Z d d l Z d � Z i d � d 6d � d 6e d 6Z yI e j j d � Z e s� e j � p� d Z e j e d
� � � Z n Wn e j
k
r� d Z n Xe j j d d � Z d
Z d e
f d � � YZ d � Z d � Z e j j d d � d k r$d p'd Z d � Z d � Z d � Z d � Z d � Z d � Z d � Z d S( i����Nc C sx y t j Wn t k
r) t j � d SXt j t j � } t j t j d � t j t j � } t j t j | � | S( s�
On darwin, getpreferredencoding ignores the locale environment and
always returns mac-roman. http://bugs.python.org/issue6202 fixes this
for Python 2.7 and up. This is the same corrected code for earlier
Python versions.
However, we can't use a version check for this method, as some distributions
patch Python to fix this. Instead, we use it as a 'fixer' for the mac-roman
encoding, as it is unlikely that this encoding is the actually expected.
i t ( t localet CODESETt AttributeErrort getdefaultlocalet setlocalet LC_CTYPEt nl_langinfo( t oldloct result( ( s8 /usr/lib64/python2.7/site-packages/mercurial/encoding.pyt _getpreferredencoding s
c C s d S( Nt ascii( ( ( ( s8 /usr/lib64/python2.7/site-packages/mercurial/encoding.pyt <lambda>$ s t 646c C s d S( NR ( ( ( ( s8 /usr/lib64/python2.7/site-packages/mercurial/encoding.pyR % s s ANSI_X3.4-1968s mac-romant
HGENCODINGR c C s t S( N( t encoding( ( ( s8 /usr/lib64/python2.7/site-packages/mercurial/encoding.pyR - s t HGENCODINGMODEt stricts
ISO-8859-1t localstrc B s e Z d Z d � Z d � Z RS( sd This class allows strings that are unmodified to be
round-tripped to the local encoding and backc C s t j | | � } | | _ | S( N( t strt __new__t _utf8( t clst ut lt s( ( s8 /usr/lib64/python2.7/site-packages/mercurial/encoding.pyR 6 s c C s
t | j � S( N( t hashR ( t self( ( s8 /usr/lib64/python2.7/site-packages/mercurial/encoding.pyt __hash__: s ( t __name__t
__module__t __doc__R R ( ( ( s8 /usr/lib64/python2.7/site-packages/mercurial/encoding.pyR 3 s c C s) y� y[ | j d � } t d k r% | S| j t d � } | | j t � k rP | St | | � SWn� t k
r� yT | j t � } | j t d � } | | j t � k r� | St | j d � | � SWq� t k
r� | j d d � } | j t d � SXn XWn( t k
r$} t j | d d �� n Xd S( s�
Convert a string from internal UTF-8 to local encoding
All internal strings should be UTF-8 but some repos before the
implementation of locale support may contain latin1 or possibly
other character sets. We attempt to decode everything strictly
using UTF-8, then Latin-1, and failing that, we use UTF-8 and
replace unknown characters.
The localstr class is used to cache the known UTF-8 encoding of
strings next to their local representation to allow lossless
round-trip conversion back to UTF-8.
>>> u = 'foo: \xc3\xa4' # utf-8
>>> l = tolocal(u)
>>> l
'foo: ?'
>>> fromlocal(l)
'foo: \xc3\xa4'
>>> u2 = 'foo: \xc3\xa1'
>>> d = { l: 1, tolocal(u2): 2 }
>>> len(d) # no collision
2
>>> 'foo: ?' in d
False
>>> l1 = 'foo: \xe4' # historical latin1 fallback
>>> l = tolocal(l1)
>>> l
'foo: ?'
>>> fromlocal(l) # magically in utf-8
'foo: \xc3\xa4'
s UTF-8t replaces utf-8t hints! please check your locale settingsN( t decodeR t encodeR t UnicodeDecodeErrort fallbackencodingt LookupErrort errort Abort( R R t rt k( ( s8 /usr/lib64/python2.7/site-packages/mercurial/encoding.pyt tolocal= s* "
c C s� t | t � r | j Sy | j t t � j d � SWnw t k
r� } | t d | j d � | j d !} t
j d | | f � � n( t k
r� } t
j | d d �� n Xd S( s�
Convert a string from the local character encoding to UTF-8
We attempt to decode strings using the encoding mode set by
HGENCODINGMODE, which defaults to 'strict'. In this mode, unknown
characters will cause an error message. Other modes include
'replace', which replaces unknown characters with a special
Unicode character, and 'ignore', which drops the character.
s utf-8i i
s decoding near '%s': %s!R! s! please check your locale settingsN(
t
isinstanceR R R"