idUdZddlZddlZddlZddlZddlZddlZejddkZejdddkZ ejdddkZ ejdddkZ ejdddkZ ejddd kZ ejddd kZejddkZejddd kZejddd kZeed ZdZdZerdZdZdZefZefZefZeZe Z!ndZdZdZe"fZee#fZeej$fZe%ZeZ!erdZ&ndZ&de&_er dMdZ'dMdZ(dNdZ)n dNdZ'dNdZ(dOd Z)d!e'_er d"Z*d#Z+d$Z,d%Z-n ddl.Z.e.j/Z*e.j0Z+e.j1Z,e.j2Z-dPd'Z3d(Z4d)Z5d*Z6d+Z7d,Z8d-Z9d.Z:d/Z;d0ZdQd3Z?e@fd4ZAn d5Z>eBd6Cd7eA_e?ZDd8ZEerd9ZFnd:ZFd;ZGd<ZHeZIe ZJd=ZKd>ZLd?ZMd@ZNdAZOerddlPZPeQePdBZRndQdCZRdDZSdMdEZT eUj7dFZVdGZWn#eX$r dHZVdIZWYnwxYwerdJZYndKZYgdLZZdS)Ra A selection of cross-compatible functions for Python 2 and 3. This module exports useful functions for 2/3 compatible code: * bind_method: binds functions to classes * ``native_str_to_bytes`` and ``bytes_to_native_str`` * ``native_str``: always equal to the native platform string object (because this may be shadowed by imports from future.builtins) * lists: lrange(), lmap(), lzip(), lfilter() * iterable method compatibility: - iteritems, iterkeys, itervalues - viewitems, viewkeys, viewvalues These use the original method if available, otherwise they use items, keys, values. * types: * text_type: unicode in Python 2, str in Python 3 * string_types: basestring in Python 2, str in Python 3 * binary_type: str in Python 2, bytes in Python 3 * integer_types: (int, long) in Python 2, int in Python 3 * class_types: (type, types.ClassType) in Python 2, type in Python 3 * bchr(c): Take an integer and make a 1-character byte string * bord(c) Take the result of indexing on a byte string and make an integer * tobytes(s) Take a text string, a byte string, or a sequence of characters taken from a byte string, and make a byte string. * raise_from() * raise_with_traceback() This module also defines these decorators: * ``python_2_unicode_compatible`` * ``with_metaclass`` * ``implements_iterator`` Some of the functions in this module come from the following sources: * Jinja2 (BSD licensed: see https://github.com/mitsuhiko/jinja2/blob/master/LICENSE) * Pandas compatibility module pandas.compat * six.py by Benjamin Peterson * Django N)r)r)r)r)r)r )rr)rrpypy_translation_infoc<ts|j|_d|_|S)u A decorator that defines __unicode__ and __str__ methods under Python 2. Under Python 3, this decorator is a no-op. To support Python 2 and 3 with a single code base, define a __str__ method returning unicode text and apply this decorator to the class, like this:: >>> from future.utils import python_2_unicode_compatible >>> @python_2_unicode_compatible ... class MyClass(object): ... def __str__(self): ... return u'Unicode string: 孔子' >>> a = MyClass() Then, after this import: >>> from future.builtins import str the following is ``True`` on both Python 3 and 2:: >>> str(a) == a.encode('utf-8').decode('utf-8') True and, on a Unicode-enabled terminal with the right fonts, these both print the Chinese characters for Confucius:: >>> print(a) >>> print(str(a)) The implementation comes from django.utils.encoding. cP|dSNutf-8) __unicode__encode)selfs J/opt/cloudlinux/venv/lib/python3.11/site-packages/future/utils/__init__.pyz-python_2_unicode_compatible..ns 4#3#3#5#5#<#.metaclassc\|t||d|S||S)N)type__new__)rname this_basesdbasesmetas rr!z)with_metaclass..metaclass.__new__s5!||Cr15554eQ'' 'rN)__name__ __module__ __qualname__r __call____init__r!)r%r&sr metaclassrsA== ( ( ( ( ( ( ( (rr,temporary_classNr)r&r%r,s`` rwith_metaclassr.rsT2((((((((D((( 9&b 1 11rc"t|gSN)bytesss rbchrr4saSzzrcjt|trt|dSt|SNlatin-1) isinstancestrr1r2s rbstrr:s/ a   I&& &88Orc|Sr0rr2s rbordr<rc t|Sr0)chrr2s rr4r4 1vv rc t|Sr0)r9r2s rr:r:r@rc t|Sr0)ordr2s rr<r<r@rct|tr|St|tr|dSt|Sr6)r8r1r9rr2s rtobytesrEsH a   H!S!! xx ***Qxxrct|tr|dSd|S)Nr7)r8unicoderjoinr2s rrErEs6 a ! ! 88I&& &771:: rzS Encodes to latin-1 (where the first 256 chars are the same as ASCII.) rc,||Sr0r)r3encodings rnative_str_to_bytesrMxx!!!rc,||Sr0)decodebrLs rbytes_to_native_strrSrNrc|Sr0rtrLs rtext_to_native_strrWr=rc$ddlm}||S)Nrnewbytes) future.typesrZ)r3rLrZs rrMrMs"))))))x{{rc t|Sr0)nativerQs rrSrSsayyrasciicFt||S)z} Use this to create a Py2 native string when "from __future__ import unicode_literals" is in effect. )rHrrUs rrWrWs qzz  ***rzu On Py3, returns an encoded string. On Py2, returns a newbytes type, ignoring the ``encoding`` argument. c4tt|i|Sr0)listrangeargskwargss rlrangerfsE4*6**+++rc4tt|i|Sr0)raziprcs rlzipriC((()))rc4tt|i|Sr0)ramaprcs rlmaprmrjrc4tt|i|Sr0)rafilterrcs rlfilterrpsFD+F++,,,rFc |r,td|dDStr|Sddl}|d}t ||S)zE A function equivalent to the str.isidentifier method on Py3 c34K|]}t|VdSr0) isidentifier).0as r zisidentifier..s(99q<??999999r.rNz[a-zA-Z_][a-zA-Z0-9_]*$)allsplitrrsrecompileboolmatch)r3dottedrz_name_res rrsrss:99AGGCLL999999 '~~ ::899HNN1%%&&&rc Ft|dd}|s|j}|di|S)z Function for iterating over dictionary items with the same set-like behaviour on Py2.7 as on Py3. Passes kwargs to method. viewitemsNrgetattritemsobjrefuncs rrrs6 3 T * *D y 4>>&>>rc Ft|dd}|s|j}|di|S)z Function for iterating over dictionary keys with the same set-like behaviour on Py2.7 as on Py3. Passes kwargs to method.viewkeysNrrkeysrs rrrs6 3 D ) )D x 4>>&>>rc Ft|dd}|s|j}|di|S)z Function for iterating over dictionary values with the same set-like behaviour on Py2.7 as on Py3. Passes kwargs to method. viewvaluesNrrvaluesrs rrr(s6 3 d + +D z 4>>&>>rc Ft|dd}|s|j}|di|S)zsUse this only if compatibility with Python versions before 2.7 is required. Otherwise, prefer viewitems(). iteritemsNrrrs rrr4s6 3 T * *D y 4>>&>>rc Ft|dd}|s|j}|di|S)zrUse this only if compatibility with Python versions before 2.7 is required. Otherwise, prefer viewkeys(). iterkeysNrrrs rrr>s6 3 D ) )D x 4>>&>>rc Ft|dd}|s|j}|di|S)ztUse this only if compatibility with Python versions before 2.7 is required. Otherwise, prefer viewvalues(). itervaluesNrrrs rrrHs6 3 d + +D z 4>>&>>rc ts't||tj|d|dSt|||dS)a/Bind a method to class, python 2 and python 3 compatible. Parameters ---------- cls : type class to receive bound method name : basestring name of method on class instance func : function function to be bound as method Returns ------- None N)rsetattrtypes MethodType)rr"rs r bind_methodrRsK$ !T5+D$<<=====T4     rc4tjdS)N)sysexc_inforrr getexceptionrjs <>>! rcptjd}|dj}|dj}||fS)zr Returns the globals and locals of the calling frame. Is there an alternative to frame hacking here? rr)inspectstack f_globalsf_locals) caller_frame myglobalsmylocalss r_get_caller_globals_and_localsrns7 =??1%LQ)IA'H h rct|}|dr|dr |ddS|S)zA Returns the string without any initial or final quotes. 'r)repr startswithendswith)mystringrs r _repr_striprzsF XA||CQZZ__2wrct\}}|}||d<||d<d}t|||dS)n Equivalent to: raise EXCEPTION from CAUSE on Python 3. (See PEP 3134). __python_future_raise_from_exc __python_future_raise_from_causezJraise __python_future_raise_from_exc from __python_future_raise_from_causeN)rcopyexec)exccauserrexecstrs r raise_fromrsX=>> 8NN$$ 69 238= 45^ Wi*****rct|tr|td|}nt|tr,t |tstd|jzt||r|}n3t|t r||}n| |}n ||}|j|ur|||)z A function that matches the Python 2.x ``raise`` statement. This allows re-raising exceptions with the cls value and traceback on Python 2 and 3. Nz0instance exception may not have a separate valuez,class must derive from BaseException, not %s) r8 BaseException TypeErrorr issubclassr'tuple __traceback__with_traceback)tpvaluetbrs rraise_rs b- ( (   RSSSCC D ! ! *R*G*G JR[XYY Y%$$ E5)) b%jbddbii  B & &$$R(( ( rcp|tkrtj\}}}||r0)Ellipsisrrr)r traceback_s rraise_with_tracebackrs2  !lnnOAq)  +++rc~t|tr t|tr |}n|}d|_t|trOt|tr:||_t jd|j_d|_n||d|_d|_nkt|trG||_t |jdt jdd|_ntdt jd|_ |)rFrTNrz/exception causes must derive from BaseExceptionr)r8r r Exception__suppress_context__ __cause__rrrrobject __setattr__r __context__)rres rrrs c4  ZY%?%? AA A!& eT " " Oz%'C'C O%''AK(+ q(9AK %%)A " " ]AK%)A " " } - - OAK   q{_clnnQ>O P P P%)A " "MNN N q) rz def raise_(tp, value=None, tb=None): raise tp, value, tb def raise_with_traceback(exc, traceback=Ellipsis): if traceback == Ellipsis: _, _, traceback = sys.exc_info() raise exc, None, traceback zjRaise exception with existing traceback. If traceback is not passed, uses sys.exc_info() to get traceback.c4tr|S|j|_|`|S)a From jinja2/_compat.py. License: BSD. Use as a decorator like this:: @implements_iterator class UppercasingIterator(object): def __init__(self, iterable): self._iter = iter(iterable) def __iter__(self): return self def __next__(self): return next(self._iter).upper() )r__next__nextrs rimplements_iteratorrs$   < L rc|jSr0)rxs rrrsrc|jSr0)rrs rrrsrcltr|St|tr|dS|Sr)rr8rHr)filenames rencode_filenamers8  h ( ( ,??7++ +rcdt|do dt|vpt|dS)a Python 2.7 has both new-style and old-style classes. Old-style classes can be pesky in some circumstances, such as when using inheritance. Use this function to test for whether a class is new-style. (Python 3 only has new-style classes.) __class____dict__ __slots__)hasattrdirrs r is_new_styler#s= 3 $ $ H*C*@+G-4S+-F-FHrc<t|tdS)z Deprecated. Use:: >>> isinstance(obj, str) after this import: >>> from future.builtins import str rGr8r rs ristextr3 c499 % %%rc<t|tdS)z Deprecated. Use:: >>> isinstance(obj, bytes) after this import: >>> from future.builtins import bytes rrrs risbytesr=rrc2t|jdkS)a Equivalent to the result of ``type(obj) == type(newbytes)`` in other words, it is REALLY a newbytes instance, not a Py2 native str object? Note that this does not cover subclasses of newbytes, and it is not equivalent to ininstance(obj, newbytes) rZ)r r'rs r isnewbytesrGs 99  ++rc6t|tjS)a_ Deprecated. Tests whether an object is a Py3 ``int`` or either a Py2 ``int`` or ``long``. Instead of using this function, you can use: >>> from future.builtins import int >>> isinstance(obj, int) The following idiom is equivalent: >>> from numbers import Integral >>> isinstance(obj, Integral) r8numbersIntegralrs risintrSs c7+ , ,,rcNt|dr|S|S)aO On Py3, this is a no-op: native(obj) -> obj On Py2, returns the corresponding native Py2 types that are superclasses for backported objects from Py3: >>> from builtins import str, bytes, int >>> native(str(u'ABC')) u'ABC' >>> type(native(str(u'ABC'))) unicode >>> native(bytes(b'ABC')) b'ABC' >>> type(native(bytes(b'ABC'))) bytes >>> native(int(10**20)) 100000000000000000000L >>> type(native(int(10**20))) long Existing native types on Py2 will be returned unchanged: >>> type(native(u'ABC')) unicode __native__)rrrs rr]r]fs+:sL!!~~ rrc||&tjd}|j}||j}~n||}t ddS)zExecute code in a namespace.Nrzexec code in globs, locs)r _getframerrr)codeglobslocsframes rexec_rsM =M!$$EOE|~ \D +,,,,,rc~t|tjrt|tjr||zS||z S)z DEPRECATED: import ``old_div`` from ``past.utils`` instead. Equivalent to ``a / b`` on Python 2 without ``from __future__ import division``. TODO: generalize this to other objects (like arrays etc.) r)rurRs rold_divrs?!W%&&:a9I+J+JAv 1u rc&trdSfd}|S)a~ A decorator to turn a function or method call that returns text, i.e. unicode, into one that returns a native platform str. Use it as a decorator like this:: from __future__ import unicode_literals class MyClass(object): @as_native_str(encoding='ascii') def __repr__(self): return next(self._iter).upper() c|Sr0r)fs rrzas_native_str..srcJtjfd}|S)Nc<|i|S)N)rLrK)rdrerLrs rwrapperz/as_native_str..encoder..wrappers)q$)&))00(0CCCr) functoolswraps)rrrLs` rencoderzas_native_str..encodersB _Q   D D D D D  DNr)r)rLrs` r as_native_strrs5 {      rc*|Sr0)rr$s r listvaluesr sxxzzrc*|Sr0)rr s r listitemsr swwyyrcDt|Sr0)rarr s rr r sAHHJJrcDt|Sr0)rarr s rr r sAGGIIrc|Sr0rrs rensure_new_typers rcddlm}ddlm}ddlm}ddlm}tt|}t|t|rp|tkr ||S|tkr ||S|tkr ||S|tkr ||S|tkr ||S|St|||fvsJ|S)NrrY)newstr)newint)newdict)future.types.newbytesrZfuture.types.newstrrfuture.types.newintrfuture.types.newdictrr r]rr9rHintlongdict)rrZrrr native_types rrrs222222............0000006#;;''  k499 - - c!!x}}$''vc{{"##vc{{"$$vc{{"$$ws||# 996 22222Jr)2PY2PY26rPYPYr binary_typerr<r:rS class_typesrrrget_nextrr integer_typesrrrsrrrrrrrpr r rmrfrir] native_bytes native_strrMrrrrreraise string_typesrW text_typerErrrr.)rr0)r^)F)NN)[__doc__rrrrrr version_infor PY34_PLUS PY35_PLUS PY36_PLUS PY37_PLUS PY38_PLUS PY39_PLUSrrPY27rr rr.r4r:r<r9r(rr$r r"r)r1r! basestringr ClassTyperHrErMrSrWrfrirmrp __builtin__rbrhrlrorsrrrrrrrrrrrrrrrstripr'rr#rrr&r%rrrrr]builtinsrrrrrr r AttributeErrorr__all__rrrr:s:11f   qQ  QqS !V +  QqS !V +  QqS !V +  QqS !V +  QqS !V +  QqS !V +  qQ !& !&ws+,,&&&R 2 2 2H 4LDM%KIKK;L$KM)KIK      +""""""""++++ !,,,******----  F ?D ?D G ' ' ' '         !!!0   k +++$$$$$L-5,,,,, """H D  EGG   E . ##HHHHHH  &&&&&& , , ,---&   H-OOO GHf % %EE - - - -   4 NN    : sH** H87H8