ϪfAXdZddlZddlZddlZddlZddlmZddlZddl m Z ddl m Z ddl mZddlmZddlmZmZmZddlmZdd lmZmZdd lmZmZm Z dd lm!Z"m#Z$dd l%m&Z&dd l'm(Z(m)Z)ejTdk(rdZ+ndZ+eZ,e)e&ddddde-de.Z.e)e&ddddde-de/Z0e)e&ddddde-de1Z2e)e&ddddde-de3Z4e)e&ddddde-de5Z5e)e&ddddde-de6Z7e)e&ddddd e-d!e8Z8e)e&ddddd"e-d#e9Z:e)e&ddddd$e-d%e;Z<e)e&ddddd&e-d'e9Z=e)e&ddddd$e-d(e5Z>e)e&ddddde-d)e(e&ddddd*+d,Z?e(e&ddddd-+d.Z@e(e&ddddd/+d0ZAd]d1e3d2efd3ZBd^d4ZCd5e/d6e/d2e3fd7ZDd8ZEe9fd9ZFd:ed2e9fd;ZGd<ZHe(e&ddddd=+d>ZId?ZJe(e&ddddd@+dAe3d2eKfdBZLd_dCZMd:e9d2eKfdDZNe(e&dddddE+dFZOdGZPd^dHZQdIZReRe)e&dddddJe-dKe)e&dddddLe-dMe)e&dddddNe-dOe)e&dddddPe-dQe)e&dddddRe-dSe)e&dddddTe-dUe)e&dddddVe-dWe)e&dddddXe-dYe)e&dddddZe-d[gd\ZSy)`a) Compatibility module to provide backwards compatibility for useful Python features. This is mainly for use of internal Twisted code. We encourage you to use the latest version of Python directly from your code, if possible. @var unicode: The type of Unicode strings, C{unicode} on Python 2 and C{str} on Python 3. @var NativeStringIO: An in-memory file-like object that operates on the native string type (bytes in Python 2, unicode in Python 3). @var urllib_parse: a URL-parsing module (urlparse on Python 2, urllib.parse on Python 3) N)Sequence)reduce)escape) cookiejar)IOBaseStringIO TextIOBase)intern) FrameType MethodType)AnyAnyStrcast)quoteunquote)Version) deprecateddeprecatedModuleAttributePyPyTFTwistedzObsolete alias for io.IOBaseFileTypez)Obsolete alias for frozenset builtin type frozensetz)Old-style classes don't exist in Python 3 InstanceTypez Obsolete alias for zip() builtinizipz#Obsolete alias for int builtin typelongz"Obsolete alias for range() builtinrangez"Obsolete alias for input() builtin raw_inputz#Obsolete alias for set builtin typesetz#Obsolete alias for str builtin type StringTypez Obsolete alias for chr() builtinunichrunicodexrangez d.items()) replacementc"|jS)z] Return an iterable of the items of C{d}. @type d: L{dict} @rtype: iterable )itemsds 7/usr/lib/python3/dist-packages/twisted/python/compat.py iteritemsr+s 779z d.values()c"|jS)z^ Return an iterable of the values of C{d}. @type d: L{dict} @rtype: iterable )valuesr(s r* itervaluesr/s 88:r,zlist(d.items())c4t|jS)zW Return a list of the items of C{d}. @type d: L{dict} @rtype: L{list} )listr'r(s r*r'r's  ?r,nreturnc|tj}t|dzD]}|J|j}|J|S)a` In Python 3, L{inspect.currentframe} does not take a stack-level argument. Restore that functionality from Python 2 so we don't have to re-implement the C{f_back}-walking loop in places where it's called. @param n: The number of stack levels above the caller to walk. @return: a frame, n levels up the stack from the caller. )inspect currentframerf_back)r2fxs r*r7r7sM A 1q5\}} HH == Hr,c||}t|d5}|j}dddt|d}t|||y#1swY$xYw)az Execute a Python script in the given namespaces. Similar to the execfile builtin, but a namespace is mandatory, partly because that's a sensible thing to require, and because otherwise we'd have to do some frame hacking. This is a compatibility implementation for Python 3 porting, to avoid the use of the deprecated builtin C{execfile} function. Nrbexec)openreadcompiler=)filenameglobalslocalsfinsourcecodes r*execfilerGsT~ h  68V ,Dws AAabc||kry||k(ryy)z Compare two objects. Returns a negative number if C{a < b}, zero if they are equal, and a positive number if C{a > b}. rr5)rHrIs r*cmprMs 1u ar,cbdtdtdtfd}dtdtdtfd}dtdtdtfd}dtdtdtfd}dtdtdtfd}dtdtdtfd }||_||_||_||_||_||_|S) z Class decorator that ensures support for the special C{__cmp__} method. C{__eq__}, C{__lt__}, etc. methods are added to the class, relying on C{__cmp__} to implement their comparisons. selfotherr3c^tt|j|}|tur|S|dk(SNrrbool__cmp__NotImplementedrOrPcs r*__eq__zcomparable..__eq__- t||E* +  HAv r,c^tt|j|}|tur|S|dk7SrRrSrWs r*__ne__zcomparable..__ne__rZr,c^tt|j|}|tur|S|dkSrRrSrWs r*__lt__zcomparable..__lt__- t||E* +  H1u r,c^tt|j|}|tur|S|dkSrRrSrWs r*__le__zcomparable..__le__rZr,c^tt|j|}|tur|S|dkDSrRrSrWs r*__gt__zcomparable..__gt__ r_r,c^tt|j|}|tur|S|dk\SrRrSrWs r*__ge__zcomparable..__ge__rZr,) r objectrTr^rcrarerYr\)klassrYr\r^rarcres r* comparablerhsSD SD SD SD SD SD ELELELELELEL Lr,ct|trtSt|trtSt |dd}ddl}t||j|jfr|rtStS|S)a Determine the type which will be returned from the given file object's read() and accepted by its write() method as an argument. In other words, determine whether the given file is 'opened in text mode'. @param fileIshObject: Any object, but ideally one which resembles a file. @type fileIshObject: L{object} @param default: A default value to return when the type of C{fileIshObject} cannot be determined. @type default: L{type} @return: There are 3 possible return values: 1. L{str}, if the file is unambiguously opened in text mode. 2. L{bytes}, if the file is unambiguously opened in binary mode. 3. The C{default} parameter, if the given type is not understood. @rtype: L{type} encodingNr) isinstancer strrbytesgetattrcodecs StreamReader StreamWriter) fileIshObjectdefaultrjros r*ioTypertsb0-, -( }j$7H-&"5"5v7J7J!KL JL Nr,sct|ttfstd|zt|tr|j dS|j d|S)z Convert C{bytes} or C{str} to C{str} type, using ASCII encoding if conversion is necessary. @raise UnicodeError: The input string is not ASCII encodable/decodable. @raise TypeError: The input is neither C{bytes} nor C{str}. z%r is neither bytes nor strascii)rkrmrl TypeErrordecodeencoderus r* nativeStringr|JsO a% &59::!Uxx    Hr,ct|tr|jd}n|jd}t |t |k(r|S|S)a Some functions, such as C{os.path.join}, operate on string arguments which may be bytes or text, and wish to return a value of the same type. In those cases you may wish to have a string constant (in the case of C{os.path.join}, that constant would be C{os.path.sep}) involved in the parsing or processing, that must be of a matching type in order to use string operations on it. L{_matchingString} will take a constant string (either L{bytes} or L{str}) and convert it to the same type as the input string. C{constantString} should contain only characters from ASCII; to ensure this, it will be encoded or decoded regardless. @param constantString: A string literal used in processing. @type constantString: L{str} or L{bytes} @param inputString: A byte string or text string provided by the user. @type inputString: L{str} or L{bytes} @return: C{constantString} converted into the same type as C{inputString} @rtype: the type of C{inputString} rw)rkrmryrztype)constantString inputString otherTypes r*_matchingStringr\sL*.%("))'2 "))'2  NtK00r,z)raise exception.with_traceback(traceback)c$|j|)a" Re-raise an exception, with an optional traceback. Re-raised exceptions will be mutated, with their C{__traceback__} attribute being set. @param exception: The exception instance. @param traceback: The traceback to use, or L{None} indicating a new traceback. )with_traceback) exception tracebacks r*reraiser{s  " "9 --r,c#RKtt|D] }|||dzyw)a5 Return an iterable wrapper for a C{bytes} object that provides the behavior of iterating over C{bytes} on Python 2. In particular, the results of iteration are the individual bytes (rather than integers as on Python 3). @param originalBytes: A C{bytes} object that will be wrapped. r5N)rlen) originalBytesis r* iterbytesrs23}% &'AA&&'s%'zb'%d'rcd|fzS)z Convert the given integer into C{bytes}, as ASCII-encoded Arab numeral. @param i: The C{int} to convert to C{bytes}. @rtype: C{bytes} s%drL)rs r* intToBytesrs A4<r,c6t|}|||dS||||zS)aq Return a copy of the given bytes-like object. If an offset is given, the copy starts at that offset. If a size is given, the copy will only be of that length. @param object: C{bytes} to be copied. @param offset: C{int}, starting index of copy. @param size: Optional, if an C{int} is given limit the length of copy to this size. N) memoryview)rfoffsetsizeviews r* lazyByteSlicers0 f D |FG}Fftm--r,cZt|ts td|jdS)a Convert a string to L{bytes} using ASCII encoding. This is useful for sending text-like bytes that are constructed using string interpolation. For example:: networkString("Hello %d" % (n,)) @param s: A string to convert to bytes. @type s: L{str} @raise UnicodeError: The input string is not ASCII encodable. @raise TypeError: The input is not L{str}. @rtype: L{bytes} z!Can only convert strings to bytesrw)rkrlrxrzr{s r* networkStringrs)" a ;<< 88G r,z os.environbctjj}tjj}tjj Dcic]\}}||||c}}Scc}}w)z Return a L{dict} of L{os.environ} where all text-strings are encoded into L{bytes}. This function is POSIX only; environment variables are always text strings on Windows. )osenviron encodekey encodevaluer')rrr:ys r* bytesEnvironrsT $$I**((K57ZZ5E5E5G HTQIaL+a. ( HH HsA3c8|j|}t||S)aN Construct a bound method. @param cls: The class that the method should be bound to. @type cls: L{type} @param name: The name of the method. @type name: native L{str} @param self: The object that the method is bound to. @type self: any object @return: a bound method @rtype: L{_MethodType} )__dict__ _MethodType)clsnamerOfuncs r*_constructMethodrs << D tT ""r,c d|vrtjdtd|d|vr|jd}|rtt |S)a Provide a backwards-compatible way to get async param value that does not cause a syntax error under Python 3.7. @param isAsync: isAsync param value (should default to None) @type isAsync: L{bool} @param kwargs: keyword arguments of the caller (only async is allowed) @type kwargs: L{dict} @raise TypeError: Both isAsync and async specified. @return: Final isAsync param value @rtype: L{bool} asyncz:'async' keyword argument is deprecated, please use isAsyncr) stacklevel)warningswarnDeprecationWarningpoprxrT)isAsynckwargss r*_get_async_paramrsO & H  7f,**W%  =r,c ddlmmmtsydfd }t j j|jk(ry|t _y#t$rYywxYw)z Work around U{https://foss.heptapod.net/pypy/pypy/-/issues/3051} by replacing C{socket.fromfd} with a more conservative version. r)F_GETFLF_SETFLfcntlNcp|g|duz}|}  |||g|||S#||wxYwNrL) fdfamilyr~proto passprotoflagsrrr realFromFDs r*fromFDWithoutModifyingFlagsz7_pypy3BlockingHack..fromFDWithoutModifyingFlagssOGuD01 b'" &b&$;; "gu %E"gu %s ) 5r)rrr ImportError_PYPYsocketfromfd__name__)rrrrrs @@@@r*_pypy3BlockingHackrs^ 11 &&J9BBB/FM! s A A"!A"zUse functools.reduce() directlyrzUse io.StringIO directlyNativeStringIOzImport urllib.parse directly urllib_parsezUse html.escape directlyrz!Use urllib.parse.quote() directlyurlquotez#Use urllib.parse.unquote() directly urlunquotezUse http.cookiejar directly cookielibzUse sys.intern() directlyr z%Use collections.abc.Sequence directlyr)!rrGrrr rMrhr|rrr#rrrr!rrr'r+r/rr$rrrrrrr r"rrr)rr)rN)T__doc__r6rplatformr urllib.parseparserrcollections.abcr functoolsrhtmlrhttprriorrrr sysr typesr r rtypingr rrrrrr incrementalrtwisted.python.deprecaterrpython_implementationrrrrrfrziprintrrinputrr rlr!chrr"r#r$r+r/r'r7rGrMrhrtr|rrrrmrrrrrrr__all__rLr,r*rs$  #$'==6$$AJ!8!!#v- E E  Ir1a "     Ir1a /    Ir1a /    Ir1a &    Ir1a )    Ir1a (     Ir1a (    Ir1a )    Ir1a )    Ir1a &    Ir1a )    Ir1a (   GIr1a (kBC GIr1a (lCD GIr1a (6GHI C  $ * 6 f  2j#&(V F s $>  Ir1a ; .  . ' GIr1a (g>#%?.*SU, GIr1a (mD IE I#(:04 Ir1a %   Ir1a    Ir1a "   Ir1a "