o ]LbTA@sdZddlmZddlZddlZddlZddlZddlZddlZddl Z ej ddkZ dej vZ dZese>re>2dZ>ej?2dZ@ejA2dZBejCZDeDre/eDZDe+jEZFeFZGddZHddZIddZJeKZLejMZNeOZPeQedddurFej-dkr>ddejRDZSnddejRDZSe,TdjUZVd jWZXGd!d"d"eYZZd#d$Z[d%d&Z\d'd(Z]d)d*Z^d+d,Z_d-d.Z`d/d0Zad1d2Zbd3d4ZcecejdZdecejQZQecejeZeecejfZfejgZheiZjdgd7d8ZkecejeZld9d:Zmd;d<Znd=d>Zodhd@dAZpdBdCZqdDdCZrej ddEdkrdFdGZsdHdIZtnejuZtnddlvZvehZhejZjewZVexZXeiZZeyZ[e&Z\e&Z]e&Z^e&Z_e&Z`ekZkedZdeQZQeeZeefZfezdJdKdLZ/e&Z0dMd2Zbe{Z|dNdOZldPd:Zme&Zne&Zoej1Z3ej4Z5ej-Z6ej7Z8ej9Z:ej;Zej?Z@ePZPeQedddur5ejRZSejAZBejCZDej}Zpevj~ZFeFZGeZHegZIeZJeZLejNZNdQdCZqdRdCZrejuZteBdSZeBdTZeBdUZe6dVkZe6dWkZdXdYZdZd[Zdid^d_Zdid`daZdjdbdcZ ?dkdedfZdS)lzwMercurial portability shim for python 3. This contains aliases to hide python version-specific details from the core. )absolute_importN__pypy__F)futurescCs|j|dSN)set_exception_infofexc_infor 4/usr/lib/python3/dist-packages/mercurial/pycompat.pyfuture_set_exception_info(rcCs||ddS)Nr) set_exceptionr r r r r8cCs|Srr )ar r r identity>rcsf|dur|St|tttfrt|fdd|DSt|tr/t|fdd|DS|S)Nc3s|]}t|VqdSr_rapply).0xr r r Gsz_rapply..c3s(|]\}}t|t|fVqdSrrrkvrr r rIs&) isinstancelistsettupletypedictitemsr xsr rr rBs rcCs|tur|St||S)aApply function recursively to every item preserving the data structure >>> def f(x): ... return 'f(%s)' % x >>> rapply(f, None) is None True >>> rapply(f, 'a') 'f(a)' >>> rapply(f, {'a'}) == {'f(a)'} True >>> rapply(f, ['a', 'b', None, {'c': 'd'}, []]) ['f(a)', 'f(b)', None, {'f(c)': 'f(d)'}, []] >>> xs = [object()] >>> rapply(identity, xs) is xs True )rrr%r r r rapplyMs r'nt)rasciicG tt|Sr)rmapargsr r r maplist r/cGr+r)rranger-r r r rangelistr0r2cGr+r)rzipr-r r r ziplistr0r4argvcCsg|]}|ddqS)mbcsignoreencoderrr r r sr;cCsg|]}t|qSr )fsencoder:r r r r;sz>Bs%rc@s@eZdZdZer dddZdddZddZd d Zd d Z d S)bytestraA bytes which mostly acts as a Python 2 str >>> bytestr(), bytestr(bytearray(b'foo')), bytestr(u'ascii'), bytestr(1) ('', 'foo', 'ascii', '1') >>> s = bytestr(b'foo') >>> assert s is bytestr(s) __bytes__() should be called if provided: >>> class bytesable(object): ... def __bytes__(self): ... return b'bytes' >>> bytestr(bytesable()) 'bytes' There's no implicit conversion from non-ascii str as its encoding is unknown: >>> bytestr(chr(0x80)) # doctest: +ELLIPSIS Traceback (most recent call last): ... UnicodeEncodeError: ... Comparison between bytestr and bytes should work: >>> assert bytestr(b'foo') == b'foo' >>> assert b'foo' == bytestr(b'foo') >>> assert b'f' in bytestr(b'foo') >>> assert bytestr(b'f') in b'foo' Sliced elements should be bytes, not integer: >>> s[1], s[:2] (b'o', b'fo') >>> list(s), list(reversed(s)) ([b'f', b'o', b'o'], [b'o', b'o', b'f']) As bytestr type isn't propagated across operations, you need to cast bytes to bytestr explicitly: >>> s = bytestr(b'foo').upper() >>> t = bytestr(s) >>> s[0], t[0] (70, b'F') Be careful to not pass a bytestr object to a function which expects bytearray-like behavior. >>> t = bytes(t) # cast to bytes >>> assert type(t) is bytes cCsdSrr )selfsr r r __init__rzbytestr.__init__cCs@t|tr|St|ttfst|dst|d}t||S)N __bytes__r*)rr=bytes bytearrayhasattrstrr9__new__)clsr@r r r rGs  zbytestr.__new__cCs"t||}t|tst|}|Sr)rC __getitem__rbytechr)r?keyr@r r r rIs  zbytestr.__getitem__cCstt|Sr) iterbytestrrC__iter__r?r r r rMrzbytestr.__iter__cCst|ddS)Nr)rC__repr__rNr r r rOrzbytestr.__repr__N)r>) __name__ __module__ __qualname____doc__ TYPE_CHECKINGrArGrIrMrOr r r r r=s8    r=cCs tt|S)z4Iterate bytes as if it were a str object of Python 2)r,rJr@r r r rL rLcCst|tr t|S|S)zPromote bytes to bytestr)rrCr=rUr r r maybebytestrs rWcCst|tr|S|dS)zConvert an internal str (e.g. keyword, __doc__) back to bytes This never raises UnicodeEncodeError, but only ASCII characters can be round-trip by sysstr(sysbytes(s)). utf-8)rrCr9rUr r r sysbytes s  rYcCst|tjr|S|dS)a8Return a keyword str to be passed to Python functions such as getattr() and str.encode() This never raises UnicodeDecodeError. Non-ascii characters are considered invalid and mapped to arbitrary but unique code points such that 'sysstr(a) != sysstr(b)' for all 'a != b'. latin-1)rbuiltinsrFdecoderUr r r sysstrs  r]cCt|tr |dS|S)z Converts a bytes url back to strr*)rrCr\urlr r r strurl"  racCr^)z0Converts a str url to bytes by encoding in asciir*)rrFr9r_r r r bytesurl(rbrccCs ||)z(Raise exception with the given traceback)with_traceback)exctbr r r raisewithtb.rVrgcCs t|dd}|dur |St|S)zTGet docstring as bytes; may be None so gettext() won't confuse it with _('')rSN)getattrrY)objdocr r r getdoc2s rkcstfdd}|S)Ncs|t|g|RSr)r])objectnamer.rr r w;sz_wrapattrfunc..w) functoolswraps)r rnr rr _wrapattrfunc:srqrcCst|t|||Sr)r[openr])rmmode bufferingencodingr r r rtIsrtcCsZdd|D}|d}dd|D}||||\}}dd|D}dd|D}||fS)a Takes bytes arguments, converts them to unicode, pass them to getopt.getopt(), convert the returned values back to bytes and then return them for Python 3 compatibility as getopt.getopt() don't accepts bytes on Python 3. cSg|]}|dqSrZr\r:r r r r;Uz#_getoptbwrapper..rZcSrxryrzr:r r r r;Wr{cSs(g|]}|dd|ddfqS)rrZrr8r:r r r r;Ys(cSrxryr8r:r r r r;Zr{rz)origr. shortlistnamelistoptsr r r _getoptbwrapperNs rcCdd|D}|S)z Converts the keys of a python dictonary to str i.e. unicodes so that they can be passed as keyword arguments as dictionaries with bytes keys can't be passed as keyword arguments to functions on Python 3. cSi|] \}}|d|qSryrzrr r r czstrkwargs..r$dicr r r strkwargs]srcCr)z Converts keys of python dictionaries to bytes as they were converted to str to pass that dictonary as a keyword argument on Python 3. cSrryr8rr r r rkrzbyteskwargs..rrr r r byteskwargsfsrTcCs"t|d||}dd|DS)z Takes bytes argument, convert it to str i.e. unicodes, pass that into shlex.split(), convert the returned value to bytes and return that for Python 3 compatibility as shelx.split() don't accept bytes on Python 3. rZcSrxryr8r:r r r r;vr{zshlexsplit..)shlexsplitr\)r@commentsposixretr r r shlexsplitosrcC|Srrrr r r xrcCrr)valuesrr r r ryrcCs|j}|tjtjfr dS|tjtjfrdS|tjrdSt|dkrB|ds0|dr.dSdS|ds@|d s<|d r>d Sd Sd St|d krT|dsNdS|dsTd Sd S)Nzutf-32zutf-16z utf-8-sigrrz utf-16-bez utf-32-berrz utf-16-lez utf-32-lerX) startswithcodecs BOM_UTF32_BE BOM_UTF32_LE BOM_UTF16_BE BOM_UTF16_LEBOM_UTF8len)b bstartswithr r r _detect_encodings&   rcOs6t|ttfr|t|d}tj|g|Ri|S)N surrogatepass)rrCrDr\rjsonloads)r@r.kwargsr r r json_loadssrs2def raisewithtb(exc, tb): raise exc, None, tb cCs t|tr|Stdt|j)z Partial backport from os.py in Python 3, which only accepts bytes. In Python 2, our paths should only ever be bytes, a unicode path indicates a bug. zexpect str, not %s)rrF TypeErrorr"rP)filenamer r r r<s r<cCs t|ddS)NrS)rh)rir r r rkr0cCst||ttuSr)rh_notset)thingattrr r r safehasattrrcCs ||||Srr )r|r.r}r~r r r rr0cCrr) iteritemsrr r r rrcCrr) itervaluesrr r r rrsjavasdarwinslinuxsposixsntcCsttj|||Sr)rgetoptr.r}r~r r r getoptbrrcCsttj|||Sr)rr gnu_getoptrr r r gnugetoptbrrr>tmpcCt|||Sr)tempfilemkdtempsuffixprefixdirr r r rrrcCrr)rmkstemprr r r rrrcOs:|durd}nt|}d|vsJtj|g|Ri|S)Nzw+br)r]r TemporaryFile)rur.rr r r unnamedtempfile s  rw+bcCs*t|}d|vs Jtj||||||dS)Nr)rrrdelete)r]rNamedTemporaryFile)rubufsizerrrrr r r namedtempfiles   r)rrrsN)FT)r>rNr)rrsr>rNT)rS __future__rrinspectrosrsysr version_infoispy3builtin_module_namesispypyrTglobalstyping cookielibcPicklepicklehttplibQueuequeue SocketServer socketserver xmlrpclibthirdparty.concurrentrrOSErrorFileNotFoundErrorr[concurrent.futureshttp.cookiejar cookiejar http.clientclient xmlrpc.clientrrr'rroiostructrm_enablelegacywindowsfsencodingr<fsdecodecurdirr9oscurdirlinesep oslineseposnamepathsep ospathseppardirospardirsepossepaltseposaltsepdevnull osdevnullplatform sysplatform executable sysexecutableBytesIObytesiostringior/r2r4inputrawinputgetfullargspec getargspecintlongrhr5sysargvStructpackrJ__mod__bytereprrCr=rLrWrYr]rarcrgrkrqdelattrrEsetattrr1xrangerFunicodertrrrrrrrrrr cStringIOchrrepriterexecrlrrStringIOr,r3 raw_inputrisjythonisdarwinislinuxisposix iswindowsrrrrrrr r r r sL                    U