pBFj:ddlZddlZddlZddlmZmZmZmZddlm Z  ddZ d Z d Z Gd d Z Gd de ZdZdZddZdZddZGddZdZdZdZdZdZGddZdS)N)errorshandlerstagsutil)jsonFTignorec |<|stjdtd|stjdtdt|tr|}n(t j|stjd|pt}|pt|||||| }| |} | | ||S) a Convert a JSON string into a Python object. :param backend: If set to an instance of jsonpickle.backend.JSONBackend, jsonpickle will use that backend for deserialization. :param context: Supply a pre-built Pickler or Unpickler object to the `jsonpickle.encode` and `jsonpickle.decode` machinery instead of creating a new instance. The `context` represents the currently active Pickler and Unpickler objects when custom handlers are invoked by jsonpickle. :param keys: If set to True then jsonpickle will decode non-string dictionary keys into python objects via the jsonpickle protocol. :param reset: Custom pickle handlers that use the `Pickler.flatten` method or `jsonpickle.encode` function must call `encode` with `reset=False` in order to retain object references during pickling. This flag is not typically used outside of a custom handler or `__getstate__` implementation. :param safe: If set to ``False``, use of ``eval()`` for backwards-compatible (pre-0.7.0) deserialization of repr-serialized objects is enabled. Defaults to ``True``. The default value was ``False`` in jsonpickle v3 and changed to ``True`` in jsonpickle v4. .. warning:: ``eval()`` is used when set to ``False`` and is not secure against malicious inputs. You should avoid setting ``safe=False``. :param classes: If set to a single class, or a sequence (list, set, tuple) of classes, then the classes will be made available when constructing objects. If set to a dictionary of class names to class objects, the class object will be provided to jsonpickle to deserialize the class name into. This can be used to give jsonpickle access to local classes that are not available through the global module import scope, and the dict method can be used to deserialize encoded objects into a new class. :param v1_decode: If set to True it enables you to decode objects serialized in jsonpickle v1. Please do not attempt to re-encode the objects in the v1 format! Version 2's format fixes issue #255, and allows dictionary identity to be preserved through an encode/decode cycle. :param on_missing: If set to 'error', it will raise an error if the class it's decoding is not found. If set to 'warn', it will warn you in said case. If set to a non-awaitable function, it will call said callback function with the class name (a string) as the only parameter. Strings passed to `on_missing` are lowercased automatically. :param handle_readonly: If set to True, the Unpickler will handle objects encoded with 'handle_readonly' properly. Do not set this flag for objects not encoded with 'handle_readonly' set to True. >>> decode('"my string"') == 'my string' True >>> decode('36') 36 Nz-keys will default to True in jsonpickle 5.0.0) stacklevelz@safe=False is deprecated and will be removed in jsonpickle 5.0.0zHUnpickler.on_missing must be a string or a function! It will be ignored!)keysbackendsafe v1_decode on_missinghandle_readonly)resetclasses) warningswarnDeprecationWarning isinstancestrlowerr is_functionr Unpicklerdecoderestore) stringrcontextr rrrrrrdatas BC:\PYTHON\_runtimes\venv\Lib\site-packages\jsonpickle/unpickler.pyrrsP  M?"       MR"     *c"" %%''  j ) )  V   oG  ' G >>& ! !D ??4ug? > >>c` t||dS#t$rYdSwxYw)zBWorkaround unreliable hasattr() availability on sqlalchemy objectsTF)object__getattribute__AttributeError)objattrs r" _safe_hasattrr*xsDT***t uus  --cjt|to|tjS)zr8r:r@r#r"rBrBs2r#rBcLt|||dS)z#Use setattr to update a proxy entryN)setattrr:)r(r)proxys r" _obj_setattrrMs" Cuyy{{#####r#c4|||<dS)z0Use obj[key] assignments to update a proxy entryN)r:)r(idxrLs r" _obj_setvaluerPsyy{{CHHHr#c^|rN ||S#t$r8 ||dddcYS#t$rYnwxYwYnwxYw|d}tt |dz ddD]}t jd|d|} t|tj |}||dD]}t||}|cS#tttf$rYwxYw|dkrtdSdS)zLoads the module and returns the class. >>> cls = loadclass('datetime.datetime') >>> cls.__name__ 'datetime' >>> loadclass('does.not.exist') >>> loadclass('builtins.int')() 0 .rrNzbuiltins.NoneType)KeyErrorrsplitsplitrangelenruntranslate_module_namejoin __import__sysmodulesgetattrr' ImportError ValueErrortype)module_and_namernamesup_tomoduler( class_names r" loadclassrgs} ?+ +    55c1==bABBBB        ! !# & &Es5zzA~q"--  -chhuVeV}.E.EFF  v   +f%C#EFFm / / c:..JJJ Z8    H ---Dzz 4sA A!;A AAAA A9?C;;DDc6t|tuo||vSzHelper class that tests to see if the obj is a dictionary and contains a particular key/tag. >>> obj = {'test': 1} >>> has_tag(obj, 'test') True >>> has_tag(obj, 'fail') False >>> has_tag(42, 'fail') False )radictr(tags r"has_tagrms 99  ++r#ct|tjrtdt|tjr|tjSt|tjr|tjS |tj}|tj}n#t$rgcYSwxYwt||}|sgSt|dr't|j t|kr|SgS)z'Return arguments suitable for __new__()z+__newargs_ex__ returns both args and kwargsr_fields) rmr NEWARGSEXr`NEWARGSINITARGSSEQOBJECTrTrghasattrrXrp)r(rseq_listobj_dicttyperefs r"getargsrzssDN##HFGGGsDL!!!4<  sDM"""4=!!tx=t{#  '222G  w "" w  3x== 0 0O Is$B(( B76B7ceZdZdZdS)_trivialclassicz? A trivial class that can be instantiated with no args N)r<r=r>r?r@r#r"r|r|sr#r|c0t}||_|S)z Implement the mandated strategy for dealing with classic classes which cannot be instantiated without __getinitargs__ because they take parameters )r| __class__)clsr5s r"make_blank_classicr s   HH Or#c|d\}}t}|}d|vr|ddd}t|||<t||S)a+Returns an instance of the object from the object's repr() string. It involves the dynamic specification of code. .. warning:: This function is unsafe and uses `eval()`. >>> obj = loadrepr('datetime/datetime.datetime.now()') >>> obj.__class__.__name__ 'datetime' /rRrr)rVlocalsr[eval)reprstrreevalstrmylocals localnames r"loadreprr+slmmC((OFGxxHI iLLa((+ $V,,HY  " ""r#cT|d\}} t|}n#t$rYdSwxYw|d}|d}||kr||dsdS|ddD]%} t ||}#t $rYdSwxYw|S)zReturns a reference to a module. >>> fn = _loadmodule('datetime/datetime.datetime.fromtimestamp') >>> fn.__name__ 'fromtimestamp' rNrRrr)rVr[r_r,r^r') module_strre identifierresultidentifier_partsfirst_identifiernames r" _loadmodulerAs$))#..FJF## tt!'',,'*6!!&*;*;?O(,  % % $Cuf F3e $ $ $ $ r#ct|ttttt fs|}n||}||Sr3)rrlistrjsettuple _restore_tagsr7r(rrs r"_restorezUnpickler._restoresI#T4e<== ."GG((--Gws||r#c|r||r||||}|r||S)a#Restores a flattened object to its original python state. Simply returns any of the basic builtin types >>> u = Unpickler() >>> u.restore('hello world') == 'hello world' True >>> u.restore({'key': 'value'}) == {'key': 'value'} True )rregister_classesrr)r7r(rrrs r"rzUnpickler.restorese   JJLLL  +  ! !' * * * c""  !     r#cTt|tttfr|D]}||dSt|t r8|jd|DdS||jtj |<dS)zqRegister one or more classes :param classes: sequence of classes or a single class to register c3vK|]4\}}t|tr|ntj||fV5dSr3)rrrimportable_name).0rhandlers r" z-Unpickler.register_classes..sb!! !C&c3//NCCT5I#5N5N!!!!!!r#N) rrrrrrjrupdateitemsrr)r7rrs r"rzUnpickler.register_classess geS1 2 2 C + +%%c**** + +  & & C M !! %,MMOO !!!     #dh-"6"6w"?"?@@ @ 23   33 69A Ac tj|tjdS#t t f$rYdSwxYwr)r b85decoderB85rr'rrs r"_restore_base85zUnpickler._restore_base85rrc<dd|jzS)aCalculates the name of the current location in the JSON stack. This is called as jsonpickle traverses the object structure to create references to previously-traversed objects. This allows cyclical data structures such as doubly-linked lists. jsonpickle ensures that duplicate python references to the same object results in only a single JSON object definition and special reference tags to represent each reference. >>> u = Unpickler() >>> u._namestack = [] >>> u._refname() == '/' True >>> u._namestack = ['a'] >>> u._refname() == '/a' True >>> u._namestack = ['a', 'b'] >>> u._refname() == '/a/b' True r)rZrr6s r"_refnamezUnpickler._refnames,SXXdo....r#ct|} |j|}nb#t$rUt|j|j|<|j|||j|<YnwxYw|Sr3)idrrTrXrEappendrr)r7r(obj_id_s r"_mkrefzUnpickler._mkrefsC 2 (AA 2 2 2'*4:D V $ J  c " " "/2DN4==?? + + +  2  s AA>=A>cgfd|D}|tfdtD}j|S)Nc:g|]}|Sr@rrvr7s r" z+Unpickler._restore_list..s%222DMM!$$222r#cLg|] \}}t|t||f!Sr@)rr1)rrOrrparents r"rz+Unpickler._restore_list..sF   U%(( S% (   r#)rextendrP enumerater)r7r(childrenproxiesrrs` @@r" _restore_listzUnpickler._restore_lists F2222c222 h     '//    W%%% r#c t||tjS#t$rtgcYSwxYwr3)iterrrITERATOR TypeErrorrs r"_restore_iteratorzUnpickler._restore_iterator sT **3t}+=>>?? ?   88OOO s14AAct|}t|}|j|}||j|<|j|=||j|<||j|<dSr3)rrrErr)r7rLr5proxy_id instance_idinstance_indexs r"_swaprefzUnpickler._swaprefsce99ll )(3(6%  X &%- >"*2t}}'''r#c >t}|| tt|j|t j}n?#t$r2g}||| |||cYSwxYwt|dkr)| dgdt|z z|\}}}}} |t j kst|dddkrI|d} t| ts|| } | j| g|ddR} nCt#|s/g}||| |||S||} |r | |n#t&$r | jD]\} } || | || _n#t&$r |D]\} } t/| | | n^#t0$rQ|\}}|r| j||r+|D]\} } t/| | | YnwxYwYnwxYwYnwxYw|rA | |n*#t&$r|D]}| |YnwxYw| r| D]\} } | | | || | || | S)z Supports restoring with all elements of __reduce__ as per pep 307. Assumes that iterator items (the last two) are represented as lists as per pickler implementation. Nr< __newobj__rr)r1rrmaprrREDUCErrrrXrNEWOBJr^rra__new__callable __setstate__r'__dict__r setdefaultrK Exceptionrr __setitem__)r7r(rL reduce_valrfargsstate listitems dictitemsrstage1kr dict_state slots_statexs r"_restore_reducezUnpickler._restore_reduces  E c$-T[1ABBCCJJ   F KK    MM% ( ( (MMM   z??Q     tfC OO(;< = = =/9,4 9   wq*b99\IIq'Cc4(( )mmC(( S[0tABBx000FFA;;  F### eV,,, QXF  6 6##E****! 6 6 66!' 5 5 7 7//1((A....&+FOO% 6 6 6 6$)KKMM22DAq#FAq11112$66627/ K%?"O22:>>>&6(3(9(9(;(;661 '1 5 5 5 5 6 6 6,  % % i((((! % % %"%%AMM!$$$$%% %  )! ) )1""1a(((( F eV$$$ s~2A9BBF&& J 1>>>>)    $Hk::%$'(:$;$;%!+8+=Sz J J % !% 4 %%HHHH  H&J(*<*E&Jq&J&JERRR%(( C $$h5&%ABBB O   ! ! ! !  4))(33Hs=$D.D54D5E  H*H, H5A H H  Hc||tj}t|to-t |dkot|dt }|ot|dt }t|dr||nt|t r| ||dd}ne|rA| |d|dd}|r| |d|dd}n"t|dst|ds|}|S) Nr rrrF)r#r$__getnewargs____getnewargs_ex__) rrSTATErrrXrjrvrr()r7r(r5r has_slotshas_slots_and_dicts r"_restore_statezUnpickler._restore_statesg c$*o.. ue $ $ WUq WZaRV=W=W 'E:eAh+E+E 8^ , ,   ! !% ( ( ( ( t $ $ ..x%/HH ..a(5U/H" 22!HhuQV3#344 W )> >  Hr#c|||}t|tjrt |dr>|tjD]*}|||+nMt |dr=|tjD]*}|||+t|tjr| ||}|S)Nradd) r(rmrrtrvrrr1r,r/)r7r(r5rs r""_restore_object_instance_variablesz,Unpickler._restore_object_instance_variabless**399 3 ! ! 3x** 3TX66AOODMM!$4$4555565)) 3TX33ALLq!1!12222 3 # # :**399Hr#rct}||||}t|tjr|tj\}}nt ||j}i}|r||}|r||}t|tpt|dd } |s>t|dr.|r|j ||g|Ri|} || _n,|j |g|Ri|} nt |} n#t $rd}YnwxYw|rd ||} n]#t $rP t#|} n<#t$$r/||||cYcYSwxYwYnwxYw|| ||| t| t,r| S||| } t1| dr8t| jtr| j| _| S)Nro__meta__rTr )r1rr rmrrqrzrrrrar^rvrr r%rrrrrrrr2r*r:) r7r(rrfrLfactoryrkwargs is_oldstyler5s r"_restore_object_instancez"Unpickler._restore_object_instance/s E##C(( 3 ' ' t~.LD&&3 666DF  '==&&D  +]]6**F%c400RGCT4R4RS   /73 #:#: /A*s{3I$III&IIH/6H,,*s{3@@@@@@HH!>>#..   KKK   , ,3: , , ,,1#66HH ,,,))*555;;s+++++++,H ,  H eX&&& h & & O::3II #4 5 5 F*  $f; ;  F(0'?'C'C'E'EH $sIAD22 EEE F'E('F'(4F!F' F!!F'&F'c|tj}t||j}t j|t j|}|nt }|||||}| || |||S|*| |||S| |||Sr) rrurgrrr:r1rrrrrr8)r7r(rfrrrLr5s r"_restore_objectzUnpickler._restore_objectjs%  DM:::,sHL$<$<==  HHE KK   wt}},,S11H KK ! ! ! MM% * * *O ;  ! !* - - -;;s## #,,S#zBBBr#cNt|tj|jSr)rgrFUNCTIONrrs r"_restore_functionzUnpickler._restore_function|sT]+T]CCCCr#c~ fd|tjDS#t$rtcYSwxYw)Nc:h|]}|Sr@rrs r" z)Unpickler._restore_set..s%<<<DMM!$$<<.s/CCaq))CCCCCCr#r@)rrTUPLErrs` r"_restore_tuplezUnpickler._restore_tuplesS CCCC3tz?CCCCC C   22 s *. <<cR tjt|kst|tt fvr|Sn#t $rYnwxYwt|t ur!tj|vr |j}n*tj |vr |j }ntj |vr|j }ntj |vr|j}ntj|vr|j}ntj|vr|j}ntj|vr|j}ntj|vr|j}ntj|vr|j}nytj|vr|j}nctj|vr|j}nMtj|vr|jr|j}n0|j }n(|j!}n t|tur|j"}n|}|S)z8Return the restoration function for the specified object)#rrrrarrjrrGrHrArBrrrrrrrrrur:rrrrr<r=rrrrrrrDrrs r"rzUnpickler._restore_tagss =CHH,,c4,1N1N##    D  99  zS  -S+S.S.C*#%%0##.c!!,##.#%%0##.c!!91"5GG"0GG, #YY$  (GG"Gs;? A  A )NFTFr F)TN)TT)r)%r<r=r>r8rrrrrrrrrrrrrrrrrrrr rrrr(r/r2r8r:r=rBrDrHrr@r#r"rrpse  $  *6*CCC(  ///0       3 3 3HHHT          ... ( ( (   ,8&FJIIIIVB"9999vCCC$DDD 000d /;))))))r#r) NNFTTNFr Fr3)rr\rrrrrrrrrr*r/r1rBrMrPrgrmrzr|rrrrrrr@r#r"rJs  ************     f?f?f?f?RBBB $!$!$!$!$!$!$!$!N     v   $$$  ))))X,,,"4 ###,2" v v v v v v v v v v r#