a 97aDU@s|dZddlZddlZddlZddlZddlZddlZejddkZejdddkZ ejdddkZ ejdddkZ ejddkZ ejdddkZ ejddd kZeed Zd d Zd dZerddZddZddZefZefZefZeZeZn8ddZddZddZefZee fZeej!fZe"ZeZerDddZ#nddZ#de#_erxdtddZ$dudd Z%dvd!d"Z&ndwd#dZ$dxd$d Z%dyd&d"Z&d'e$_erd(d)Z'd*d+Z(d,d-Z)d.d/Z*n ddl+Z+e+j,Z'e+j-Z(e+j.Z)e+j/Z*dzd1d2Z0d3d4Z1d5d6Z2d7d8Z3d9d:Z4d;d<Z5d=d>Z6d?d@Z7dAdBZ8dCdDZ9dEdFZ:erddGdHZ;d{dIdJZndMdHZ;e?dN@dOe>_e>> 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. cSs|dSNutf-8) __unicode__encode)selfr p/private/var/folders/s6/9n5zrl012gv99k63s4q6ccsd4s6mqz/T/pip-target-f5cq3f2q/lib/python/future/utils/__init__.pykz-python_2_unicode_compatible..)PY3__str__r clsr r rpython_2_unicode_compatibleFs# rcs"Gfddd}|ddiS)a Function from jinja2/_compat.py. License: BSD. Use it like this:: class BaseForm(object): pass class FormType(type): pass class Form(with_metaclass(FormType, BaseForm)): pass This requires a bit of explanation: the basic idea is to make a dummy metaclass for one level of class instantiation that replaces itself with the actual metaclass. Because of internal type checks we also need to make sure that we downgrade the custom metaclass for one level to something closer to type (that's why __call__ and __init__ comes back from type etc.). This has the advantage over six.with_metaclass of not introducing dummy classes into the final MRO. cs&eZdZejZejZfddZdS)z!with_metaclass..metaclasscs$|durt||d|S||S)Nr )type__new__)rname this_basesdbasesmetar rrsz)with_metaclass..metaclass.__new__N)__name__ __module__ __qualname__r__call____init__rr rr r metaclasssr#temporary_classNr )rrr#r rrwith_metaclassosr%cCs t|gSN)bytessr r rbchrsr*cCs t|trt|dSt|SdSNlatin-1) isinstancestrr'r(r r rbstrs  r/cCs|Sr&r r(r r rbordsr0cCst|Sr&)chrr(r r rr*scCst|Sr&)r.r(r r rr/scCst|Sr&)ordr(r r rr0scCs.t|tr|St|tr"|dSt|SdSr+)r-r'r.r r(r r rtobytess    r3cCs"t|tr|dSd|SdS)Nr,)r-unicoder joinr(r r rr3s  zS Encodes to latin-1 (where the first 256 chars are the same as ASCII.) r cCs ||Sr&r )r)encodingr r rnative_str_to_bytessr9cCs ||Sr&)decodebr8r r rbytes_to_native_strsr=cCs|Sr&r tr8r r rtext_to_native_strsr@cCsddlm}||S)Nrnewbytes)Z future.typesrB)r)r8rBr r rr9s cCst|Sr&)nativer;r r rr=sasciicCst||S)z} Use this to create a Py2 native string when "from __future__ import unicode_literals" is in effect. )r5r r>r r rr@szu On Py3, returns an encoded string. On Py2, returns a newbytes type, ignoring the ``encoding`` argument. cOstt|i|Sr&)listrangeargskwargsr r rlrangesrJcOstt|i|Sr&)rEziprGr r rlzipsrLcOstt|i|Sr&)rEmaprGr r rlmapsrNcOstt|i|Sr&)rEfilterrGr r rlfiltersrPFcCsL|rtdd|dDStr(|Sddl}|d}t||SdS)zE A function equivalent to the str.isidentifier method on Py3 css|]}t|VqdSr&) isidentifier).0ar r r rzisidentifier...rNz[a-zA-Z_][a-zA-Z0-9_]*$)allsplitrrQrecompileboolmatch)r)ZdottedrXZ_name_rer r rrQs rQcKs$t|dd}|s|j}|fi|S)z Function for iterating over dictionary items with the same set-like behaviour on Py2.7 as on Py3. Passes kwargs to method. viewitemsNgetattritemsobjrIfuncr r rr\ s r\cKs$t|dd}|s|j}|fi|S)z Function for iterating over dictionary keys with the same set-like behaviour on Py2.7 as on Py3. Passes kwargs to method.viewkeysNr^keysr`r r rrcs rccKs$t|dd}|s|j}|fi|S)z Function for iterating over dictionary values with the same set-like behaviour on Py2.7 as on Py3. Passes kwargs to method. viewvaluesNr^valuesr`r r rrf%s rfcKs$t|dd}|s|j}|fi|S)zsUse this only if compatibility with Python versions before 2.7 is required. Otherwise, prefer viewitems(). iteritemsNr]r`r r rri1s ricKs$t|dd}|s|j}|fi|S)zrUse this only if compatibility with Python versions before 2.7 is required. Otherwise, prefer viewkeys(). iterkeysNrdr`r r rrj;s rjcKs$t|dd}|s|j}|fi|S)ztUse this only if compatibility with Python versions before 2.7 is required. Otherwise, prefer viewvalues(). itervaluesNrgr`r r rrkEs rkcCs,tst||t|d|n t|||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)rrrbr r r bind_methodOsrocCs tdS)N)sysexc_infor r r r getexceptiongsrscCs(td}|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)Z caller_frame myglobalsmylocalsr r r_get_caller_globals_and_localsks   rzcCs0t|}|dr(|dr(|ddS|SdS)zA Returns the string without any initial or final quotes. 'rpN)repr startswithendswith)Zmystringrr r r _repr_stripws rcCs6t\}}|}||d<||d<d}t|||dS)n Equivalent to: raise EXCEPTION from CAUSE on Python 3. (See PEP 3134). Z__python_future_raise_from_excZ __python_future_raise_from_causezJraise __python_future_raise_from_exc from __python_future_raise_from_causeN)rzcopyexec)exccauserxryZexecstrr r r raise_froms  rcCst|tr |durtd|}n`t|trDt|tsDtd|jn>> isinstance(obj, str) after this import: >>> from future.builtins import str r4r-rrar r ristext0srcCst|tdS)z Deprecated. Use:: >>> isinstance(obj, bytes) after this import: >>> from future.builtins import bytes rrrr r risbytes:srcCst|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) rB)rrrr r r isnewbytesDs rcCs t|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) r-numbersIntegralrr r risintPsrcCst|dr|S|SdS)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__N)rrrr r rrCcs rCrcCsB|dur*td}|j}|dur&|j}~n |dur6|}tddS)zExecute code in a namespace.Nrpzexec code in globs, locs)rq _getframervrwr)codeZglobsZlocsframer r rexec_s rcCs,t|tjr t|tjr ||S||SdS)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.) Nr)rSr<r r rold_divs rcs tr ddSfdd}|SdS)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() cSs|Sr&r fr r rrrzas_native_str..cstfdd}|S)Ncs|i|jdS)Nr8r7rG)r8rr rwrappersz/as_native_str..encoder..wrapper) functoolswraps)rrrrrencoderszas_native_str..encoderN)r)r8rr rr as_native_strs rcCs t|Sr&)rErhrr r r listvaluessrcCs t|Sr&)rEr_rr r r listitemssrcCs|Sr&)rhrr r rrscCs|Sr&)r_rr r rrscCs|Sr&r rr r rensure_new_typesrcCsddlm}ddlm}ddlm}ddlm}tt |}t |t|r|t krZ||S|t krj||S|t krz||S|tkr||S|tkr||S|Snt|||fvsJ|SdS)NrrA)newstr)newint)newdict)Zfuture.types.newbytesrBZfuture.types.newstrrZfuture.types.newintrZfuture.types.newdictrrrCrr.r5intlongdict)rarBrrrZ native_typer r rrs&     )2PY2PY26rPYPYr binary_typeror0r/r= class_typesrrrget_nextrsr integer_typesrrrQrrrrirjrkrPrrrNrJrLrC native_bytes native_strr9rrrrreraise string_typesr@ text_typer3r\rcrfr%)r )r )N)N)N)rD)F)NN)NN)r )X__doc__rmrqrrrrt version_inforZ PY34_PLUSZ PY35_PLUSZ PY36_PLUSrrZPY27rrrr%r*r/r0r.rrrrrrr'r basestringrZ ClassTyper5r3r9r=r@rJrLrNrP __builtin__rFrKrMrOrQr\rcrfrirjrkrorsrzrrrrrrstriprrrrrrrrrrrrCbuiltinsr^rrrrAttributeErrorrrr__all__r r r rs3 )$                   &$       $