pBFj=>ZdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddlmZeedZeeefZeeehZeeeeedhZe je je je j e j!hZ"ee#eee$e%heze"zZ&ee#eee%hezZ'dZ(dZ)d Z*d Z+d Z,d Z-d Z.dZ/dZ0dZ1dZ2dZ3dZ4dZ5dZ6dZ7dZ8dZ9dZ:dZ;dZdZ?dZ@d ZAd!ZBd"ZCd2d$ZDd2d%ZEd&ZFd'ZGd(ZHd)ZId*ZJd+ZKd,ZLd-ZMd.ZNejOdfd/ZOd3d1ZPdS)4zkHelper functions for pickling and unpickling. Most functions assist in determining the type of an object. N)Iterator)tagsc,t|tS)zReturns True is obj is a reference to a type. >>> is_type(1) False >>> is_type(object) True >>> class Klass: pass >>> is_type(Klass) True ) isinstancetypeobjs =C:\PYTHON\_runtimes\venv\Lib\site-packages\jsonpickle/util.pyis_typer 9s c4  czt||sdSt||}t|tjrdSt|tjtjfsdSt|r|n|j}d}tj |D](}t| |}|n)|dSt|trdSt|dsdSt|d}t|trt||St|t!|S)NFT__self__)hasattrgetattrrtypesBuiltinMethodType MethodType FunctionTyper __class__inspectgetmrovarsget staticmethod classmethod issubclassr )r namefunc base_typeoriginalsubtypebound_tos r has_methodr%JsQ 3  u 3  D$/00t dU-u/AB C Cu s||6IH>),,==$$T**   E u(L))t 4 $ $utZ((H(K((/)X... c4>> * **rct|to,t|ttjtjf S)zReturns True is obj is a reference to an object instance. >>> is_object(1) True >>> is_object(object()) True >>> is_object(lambda x: 1) False )robjectr rrBuiltinFunctionTyper s r is_objectr)ys> c6 " " : dE&(A B,,(rc.t|tvS)zfDetermines if the object is not a class or a class instance. Used for serializing properties. )r NON_CLASS_TYPESr s r is_not_classr,s 99 ''rc.t|tvS)aHelper method to see if the object is a basic data type. Unicode strings, integers, longs, floats, booleans, and None are considered primitive and will return True when passed into *is_primitive()* >>> is_primitive(3) True >>> is_primitive([4,4]) False )r PRIMITIVESr s r is_primitiver/s 99 ""rchdtjvo$t|tjdjS)zIs the object an enum?enum)sysmodulesrEnumr s r is_enumr5s( S[ NZS[5H5M%N%NNrcbtjdtt|tuS)zoHelper method for testing if the object is a dictionary. >>> is_dictionary({'key':'value'}) True [This function will be removed in the next release of jsonpickle, 5.0.0! Please migrate now.)warningswarnDeprecationWarningr dictr s r is_dictionaryr<s1 Me 99 rc.t|tvS)zpHelper method to see if the object is a sequence (list, set, or tuple). >>> is_sequence([4]) True )r SEQUENCES_SETr s r is_sequencer?s 99 %%rcbtjdtt|tuS)zXHelper method to see if the object is a Python list. >>> is_list([4]) True r7)r8r9r:r listr s r is_listrBs1  Me 99 rcbtjdtt|tuS)zXHelper method to see if the object is a Python set. >>> is_set(set()) True r7)r8r9r:r setr s r is_setrEs1  Me 99 rcbtjdtt|tuS)z[Helper method to see if the object is a bytestring. >>> is_bytes(b'foo') True r7)r8r9r:r bytesr s r is_bytesrH1  Me 99 rcbtjdtt|tuS)zBDEPRECATED: Helper method to see if the object is a unicode stringr7)r8r9r:r strr s r is_unicoderLs/ Me 99 rcbtjdtt|tuS)z[Helper method to see if the object is a Python tuple. >>> is_tuple((1,)) True r7)r8r9r:r tupler s r is_tuplerOrIrct|do/t|jtot |tuS)zReturns True if *obj* is a subclass of the dict type. *obj* must be a subclass and not the actual builtin dict. >>> class Temp(dict): pass >>> is_dictionary_subclass(Temp()) True r)rrrr;r r s r is_dictionary_subclassrQs= [!! " s}d + + " IIT !rcvt|do)t|jtot | S)zReturns True if *obj* is a subclass of list, set or tuple. *obj* must be a subclass and not the actual builtin, such as list, set, tuple, etc.. >>> class Temp(list): pass >>> is_sequence_subclass(Temp()) True r)rrr SEQUENCESr?r s r is_sequence_subclassrTs= [!! ! s}i 0 0 !C  rc@t|tjurdSdS)zReturns True if *obj* is a special (weird) class, that is more complex than primitive data types, but is not a full object. Including: * :class:`~time.struct_time` TF)r time struct_timer s r is_noncomplexrXs"  CyyD$$$t 5rc.t|tvS)zReturns true if passed a function >>> is_function(lambda x: 1) True >>> is_function(locals) True >>> def method(): pass >>> is_function(method) True >>> is_function(1) False )r FUNCTION_TYPESr s r is_functionr[$s 99 &&rct|doPt|tjtjfo*t|dot|do |jdkpt |S)zReturn True if `obj` is a module-global function >>> import os >>> is_module_function(os.path.exists) True >>> is_module_function(lambda: None) False r __module____name__z)rrrrr(r^is_cython_functionr s r is_module_functionr`7s| [!! ' sU/1JK L L ' C & & ' C $ $ ' LJ &  ! C !rcjtjdtt|tjS)zWReturns True if passed a module >>> import os >>> is_module(os) True r7)r8r9r:rr ModuleTyper s r is_modulercLs3 Me c5+ , ,,rc`|tjvrdSt|pt| S)zReturn True if an object can be pickled >>> import os >>> is_picklable('os', os) True >>> def foo(): pass >>> is_picklable('foo', foo) True >>> is_picklable('foo', lambda: None) False F)rRESERVEDr`r[)rvalues r is_picklablerg[s4 t}u e $ $ >K,>,>(>>rcH t|dS#t$rYdSwxYw)zTests to see if ``module`` is available on the sys.path >>> is_installed('sys') True >>> is_installed('hopefullythisisnotarealmodule') False TF) __import__ ImportErrormodules r is_installedrmos<6t uus  !!cBt|dot|dS)N __getitem__append)rr s r is_list_likerqs! 3 & & A73+A+AArcbt|tot|tj SN)r abc_iteratorioIOBaser s r is_iteratorrws& c< ( ( KC1K1K-KKrcV t|jdkS#t$rYdSwxYw)N collectionsF)r r] Exceptionr s r is_collectionsr{s=Cyy#}44 uus  ((cVt|dot|jtS)Nr)rrrrSr s r is_reducible_sequence_subclassr}s# 3 $ $ MCM9)M)MMrct|rt|tjsdSt |t vs|t ust|svt|tj s\t|sMt|s>tt|ddtst|r |jdkrdSdS)zu Returns false if of a type which have special casing, and should not have their __reduce__ methods used T __slots__NdatetimeF)r{rry defaultdictr NON_REDUCIBLE_TYPESr'rQrrbr}rqr_ITERATOR_TYPEr r]r s r is_reduciblers c:c;3J#K#Kt S ((( &== !# & &  c5+ , ,  *# . .      gc;55~ F F  CLL  !^z99u 4rct|o1t|do!t|dS)z>Returns true if the object is a reference to a Cython function__repr__z #v)>)>JC++GxY/G/GMS !//    F#>> class Example(object): ... pass >>> ex = Example() >>> importable_name(ex.__class__) == 'jsonpickle.util.Example' True >>> importable_name(type(25)) == 'builtins.int' True >>> importable_name(None.__class__) == 'builtins.NoneType' True >>> importable_name(False.__class__) == 'builtins.bool' True >>> importable_name(AttributeError) == 'builtins.AttributeError' True __qualname__rr].)rr^rr]rrr)rrrls r importable_namer)s& 3 5 5D "3> 2 2F ; 3 # # ;s|\22 ;0/:  t  rcPtj|dS)zI Encode binary data to ascii text in base64. Data must be bytes. ascii)base64 b64encodedecodedatas r rrG#  D ! ! ( ( 1 11rcf tj|S#ttjf$rYdSwxYwz. Decode payload - must be ascii text. r)r b64decoderbinasciiErrorpayloads r rrNsA((( x~ &sss 00cPtj|dS)zI Encode binary data to ascii text in base85. Data must be bytes. r)r b85encoderrs r rrXrrc\ tj|S#ttf$rYdSwxYwr)r b85decoder ValueErrorrs r rr_s?((( z "sss ++c2t||Srs)rK)r getters r itemgetterris vvc{{  rc#TK|D]\}}||vr ||fVdS)zt This can't be easily replaced by dict.items() because this has the exclude parameter. Keep it for now. N)items)r excludekvs r rrmsH  1 << d r)F)r)Q__doc__rrryrruoperatorr2rVrr8collections.abcrrtrrr iterrrArDrNrSr>rKboolintfloatr.rr LambdaTyper(rrZr;r'rGrr+r r%r)r,r/r5r<r?rBrErHrLrOrQrTrXr[r`rcrgrmrqrwr{r}rr_rrrrrrrrrrrrrrrrr rs   444444dd2hh 3  sE" 4eTT$ZZ 0                  !!!",+,+,+^"((( # # #OOO   &&&                "'''&!!!* - - -???(    BBBLLLNNN,   PPPPRRRR2'2'2'j&&&&&&&---<222222/8.q11r