Plan 9 from Bell Labs’s /usr/web/sources/contrib/jas/root/sys/lib/python2.7/site-packages/mercurial/encoding.pyc

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


��Qc@smddlZddlZddlZddlZd�Zid�d6d�d6ed6ZyIejjd�Zes�ej	�p�d	Zejed
���ZnWnej
k
r�d	ZnXejjdd�Zd
Zde
fd��YZd�Zd�Zejjdd�dkr$dp'dZd�Zd�Zd�Zd�Zd�Zd�Zd�ZdS(i�NcCsxytjWntk
r)tj�dSXtjtj�}tjtjd�tjtj�}tjtj|�|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.
    it(tlocaletCODESETtAttributeErrortgetdefaultlocalet	setlocaletLC_CTYPEtnl_langinfo(toldloctresult((s6/sys/lib/python2.7/site-packages/mercurial/encoding.pyt_getpreferredencodings
cCsdS(Ntascii((((s6/sys/lib/python2.7/site-packages/mercurial/encoding.pyt<lambda>$st646cCsdS(NR((((s6/sys/lib/python2.7/site-packages/mercurial/encoding.pyR%ssANSI_X3.4-1968s	mac-romant
HGENCODINGRcCstS(N(tencoding(((s6/sys/lib/python2.7/site-packages/mercurial/encoding.pyR-stHGENCODINGMODEtstricts
ISO-8859-1tlocalstrcBs eZdZd�Zd�ZRS(sdThis class allows strings that are unmodified to be
    round-tripped to the local encoding and backcCstj||�}||_|S(N(tstrt__new__t_utf8(tclstutlts((s6/sys/lib/python2.7/site-packages/mercurial/encoding.pyR6s	cCs
t|j�S(N(thashR(tself((s6/sys/lib/python2.7/site-packages/mercurial/encoding.pyt__hash__:s(t__name__t
__module__t__doc__RR(((s6/sys/lib/python2.7/site-packages/mercurial/encoding.pyR3s	cCs)y�|jd�}tdkr%|S|jtd�}||jt�krP|St||�SWn�tk
r�yT|jt�}|jtd�}||jt�kr�|St|jd�|�SWq�k
r�|jdd�}|jtd�SXnXWn(tk
r$}tj|dd��nXdS(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'
    sUTF-8treplacesutf-8thints!please check your locale settingsN(	tdecodeRtencodeRtUnicodeDecodeErrortfallbackencodingtLookupErrorterrortAbort(RRtrtk((s6/sys/lib/python2.7/site-packages/mercurial/encoding.pyttolocal=s*"

cCs�t|t�r|jSy|jtt�jd�SWnwtk
r�}|td|j	d�|j	d!}t
jd||f��n(tk
r�}t
j|dd��nXdS(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.
    sutf-8ii
sdecoding near '%s': %s!R!s!please check your locale settingsN(
t
isinstanceRRR"RtencodingmodeR#R$tmaxtstartR'R(R&(RtinsttsubR*((s6/sys/lib/python2.7/site-packages/mercurial/encoding.pyt	fromlocalzs$tHGENCODINGAMBIGUOUStnarrowtwidetWFAtWFcCst|jtd��S(sCFind the column width of a string for display in the local encodingR (t	ucolwidthR"R(R((s6/sys/lib/python2.7/site-packages/mercurial/encoding.pytcolwidth�scCs]ttdd�}|dk	rStg|D]$}||�tkrFdpId^q(�St|�S(s5Find the column width of a Unicode string for displayteast_asian_widthiiN(tgetattrtunicodedatatNonetsumR5tlen(tdteawtc((s6/sys/lib/python2.7/site-packages/mercurial/encoding.pyR8�s5cCsKxDt||t|��D])}|||!}t|�|kr|SqWdS(sOUse colwidth to find a c-column substring of s starting at byte
    index startN(txrangeR?R9(RR/RBtxtt((s6/sys/lib/python2.7/site-packages/mercurial/encoding.pytgetcols�s 
cCs�y|jd�|j�SWntk
r.nXyct|t�rV|jjd�}n|jtt�}|j�}||kr�|S|jt�SWn?t	k
r�|j�St
k
r�}tj|dd��nXdS(s9best-effort encoding-aware case-folding of local string sRsutf-8R!s!please check your locale settingsN(
R"tlowerR$R,RRRR-R#tUnicodeErrorR&R'R((RRtluR*((s6/sys/lib/python2.7/site-packages/mercurial/encoding.pyRG�s"



cCs�y|jd�|j�SWntk
r.nXyct|t�rV|jjd�}n|jtt�}|j�}||kr�|S|jt�SWn?t	k
r�|j�St
k
r�}tj|dd��nXdS(s9best-effort encoding-aware case-folding of local string sRsutf-8R!s!please check your locale settingsN(
R"tupperR$R,RRRR-R#RHR&R'R((RRtuuR*((s6/sys/lib/python2.7/site-packages/mercurial/encoding.pyRJ�s"



cCs�t|t�r|jSy|jd�r,|SWn�tk
r�|jdd�jd�}d}d}x_|D]W}|||d!|kr�||7}|d7}qk|tdt|��jd�7}qkW|SXdS(s�convert a local, possibly-binary string into UTF-8b

    This is intended as a generic method to preserve data when working
    with schemes like JSON and XML that have no provision for
    arbitrary byte strings. As Mercurial often doesn't know
    what encoding data is in, we use so-called UTF-8b.

    If a string is already valid UTF-8 (or ASCII), it passes unmodified.
    Otherwise, unsupported bytes are mapped to UTF-16 surrogate range,
    uDC00-uDCFF.

    Principles of operation:

    - ASCII and UTF-8 data successfully round-trips and is understood
      by Unicode-oriented clients
    - filenames and file contents in arbitrary other encodings can have
      be round-tripped or recovered by clueful clients
    - local strings that have a cached known UTF-8 encoding (aka
      localstr) get sent as UTF-8 so Unicode-oriented clients get the
      Unicode data they want
    - because we must preserve UTF-8 bytestring in places such as
      filenames, metadata can't be roundtripped without help

    (Note: "UTF-8b" often refers to decoding a mix of valid UTF-8 and
    arbitrary bytes into an internal Unicode format that can be
    re-encoded back into the original. Here we are exposing the
    internal surrogate encoding as a UTF-8 string.)
    sutf-8tignoreRiii�N(R,RRR"R$R#tunichrtord(Rts2R)tposRB((s6/sys/lib/python2.7/site-packages/mercurial/encoding.pyttoutf8b�s



'cCs�d|kr|S|jd�}d}xT|D]L}t|�d@dkre|tt|�d@�7}q,||jd�7}q,W|S(stGiven a UTF-8b string, return a local, possibly-binary string.

    return the original binary string. This
    is a round-trip process for strings like filenames, but metadata
    that's was passed through tolocal will remain in UTF-8.

    >>> m = "\xc3\xa9\x99abcd"
    >>> n = toutf8b(m)
    >>> n
    '\xc3\xa9\xed\xb2\x99abcd'
    >>> fromutf8b(n) == m
    True
    s�utf-8Ri��i�(R"RNtchrR#(RRR)RB((s6/sys/lib/python2.7/site-packages/mercurial/encoding.pyt	fromutf8bs
(R'R<RtosR
t_encodingfixerstenvirontgetRtgetpreferredencodingtErrorR-R%RRR+R2R5R9R8RFRGRJRQRS(((s6/sys/lib/python2.7/site-packages/mercurial/encoding.pyt<module>s6$	




	=							1

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].