ó a˜Qc@smddlZddlZddlZddlZd„Zid„d6d„d6ed6ZyIejjdƒZes¢ej ƒp„d Zejed „ƒƒZnWnej k r¿d ZnXejjd d ƒZ d Z de fd„ƒYZd„Zd„Zejjddƒdkr$dp'dZd„Zd„Zd„Zd„Zd„Zd„Zd„ZdS(iÿÿÿÿNcCsxy tjWntk 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_CTYPEt nl_langinfo(toldloctresult((s6/sys/lib/python2.7/site-packages/mercurial/encoding.pyt_getpreferredencoding s   cCsdS(Ntascii((((s6/sys/lib/python2.7/site-packages/mercurial/encoding.pyt$st646cCsdS(NR ((((s6/sys/lib/python2.7/site-packages/mercurial/encoding.pyR %ssANSI_X3.4-1968s mac-romant HGENCODINGR cCstS(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úy[|jdƒ}tdkr%|S|jtdƒ}||jtƒkrP|St||ƒSWn˜tk røyT|jtƒ}|jtdƒ}||jtƒkr«|St|jdƒ|ƒSWqùtk 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( tdecodeRtencodeRtUnicodeDecodeErrortfallbackencodingt LookupErrorterrortAbort(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 j d||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(tgetattrt unicodedatatNonetsumR5tlen(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Ó}t j |ddƒ‚nXdS(s9best-effort encoding-aware case-folding of local string sR sutf-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Ó}t j |ddƒ‚nXdS(s9best-effort encoding-aware case-folding of local string sR sutf-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ísutf-8RiÿiÜ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.pyts6 $      =        1