pBFj '4GddZeZdS)cveZdZdZdZddZeZdZeZddZ dZ d Z d d e fd Z d ZddZdZdZdZdZdS) JSONBackendzManages encoding and decoding using various backends. It tries these modules in this order: simplejson, json, ujson simplejson is a fast and popular backend and is tried first. json comes with Python and is tried second. c2|jrdStd)z4Ensures that we've loaded at least one JSON backend.Nz*jsonpickle could not load any json modules) _verifiedAssertionError)selfs @C:\PYTHON\_runtimes\venv\Lib\site-packages\jsonpickle/backend.py_verifyzJSONBackend._verify s >  FIJJJNcZ||js&|jd}|||||St |jD]T\}} |||||cS#t $r'}|t |jdz kr|Yd}~Md}~wwxYwdS)z Attempt to encode an object into JSON. This tries the loaded backends in order and passes along the last exception if no backend is able to encode the object. )indent separatorsN)r _fallthrough_backend_namesbackend_encode enumerate Exceptionlen)robjr rnameidxes rencodezJSONBackend.encodes   X&q)D&&tSJ&WW W"4#677  IC **#f+   #d122Q666G76666    sA77 B(B##B(cZ||js#|jd}|||St |jD]W\}} |||cS#|j|$r'}|t |jdz kr|Yd}~Pd}~wwxYwdS)z Attempt to decode an object from a JSON string. This tries the loaded backends in order and passes along the last exception if no backends are able to decode the string. r rN)r rrbackend_decoder_decoder_exceptionsr)rstringrrrs rdecodezJSONBackend.decode,s   5&q)D&&tV44 4"4#677  IC **488888+D1   #d122Q666GDDDD    sA11B(B##B(TcT||_g|_i|_i|_i|_i|_i|_d|_|d|d|d|dddd d d dif}d ddd f|||d |_dS)NF simplejsonjsonujsonyamldump safe_load YAMLError)dumpsloads loads_exc sort_keys)r,escape_forward_slashes)r#r"r!zdjango.util.simplejson) rr _encoders _decoders_encoder_options_decoder_optionsrr load_backend)r fallthrough json_optss r__init__zJSONBackend.__init__Fs' !#!#$&  ,''' &!!! '"""  & {    +u-. OOP#&/ ! ! r c||_dS)a Disable jsonpickle's fallthrough-on-error behavior By default, jsonpickle tries the next backend when decoding or encoding using a backend fails. This can make it difficult to force jsonpickle to use a specific backend, and catch errors, because the error will be suppressed and may not be raised by the subsequent backend. Calling `enable_backend(False)` will make jsonpickle immediately re-raise any exceptions raised by the backends. N)r)renables renable_fallthroughzJSONBackend.enable_fallthroughms#r c| t||||<n&#t$r||YdSwxYwdS)NFT)getattrAttributeErrorremove_backend)rdctbackendrrs r_storezJSONBackend._store~sY "3--CLL       ( ( (55 ts 99r(r)c| t|}n#t$rYdSwxYw |dddD]}t||}n#t$rYdSwxYw||j|||r||j|||sdSt|tr ||j |||sdSn ||j |<|j |gif|j |gif|j|d|_dS)aLoad a JSON backend by name. This method loads a backend and sets up references to that backend's loads/dumps functions and exception classes. :param dumps: is the name of the backend's encode method. The method should take an object and return a string. Defaults to 'dumps'. :param loads: names the backend's method for the reverse operation -- returning a Python object from a string. :param loads_exc: can be either the name of the exception class used to denote decoding errors, or it can be a direct reference to the appropriate exception class itself. If it is a name, then the assumption is that an exception class of that name can be found in the backend module's namespace. :param load: names the backend's 'load' method. :param dump: names the backend's 'dump' method. :rtype bool: True on success, False if the backend could not be loaded. F.rNT) __import__ ImportErrorsplitr:r;r?r.r/ isinstancestrrr0 setdefaultr1rappendr)rrr(r)r*modattrs rr2zJSONBackend.load_backends* T""CC   55   3+ ) )c4(( )   55 {{4>4e<< DKK ND#uE E  5 i % % 7;;t7sINN u .7D $T * ((Bx888 ((Bx888 ""4(((ts  0A A#"A#c|j|d|j|d|j|d|j|d|j|d||jvr|j|t|j|_ dS)z,Remove all entries for a particular backend.N) r.popr/rr1r0rremoveboolr)rrs rr<zJSONBackend.remove_backends 4&&& 4&&&  $$T4000 !!$--- !!$--- 4& & &   & &t , , ,d122r c|j|gif\}}|}|||d<|||d<|ft|z}|j||i|S)Nr r)r0getcopytupler.) rrrr roptargs optkwargsencoder_kwargs encoder_argss rrzJSONBackend.backend_encodes!266tb"XFF"))  '-N8 $  !+5N< (vg. #t~d#\D^DDDr c|j|dif\}}|}|j||g|Ri|S)Nr+)r1rPrQr/)rrrrSrTdecoder_kwargss rrzJSONBackend.backend_decodesY!266tb"XFF"))#t~d#FGWGGGGGGr c||jvr7|j||jd|dSd|z}t|)a Set the preferred json backend. If a preferred backend is set then jsonpickle tries to use it before any other backend. For example:: set_preferred_backend('simplejson') If the backend is not one of the built-in jsonpickle backends (json/simplejson) then you must load the backend prior to calling set_preferred_backend. AssertionError is raised if the backend has not been loaded. r z%The "%s" backend has not been loaded.N)rrMinsertr)rrerrmsgs rset_preferred_backendz!JSONBackend.set_preferred_backends`$ 4& & &   & &t , , ,   & &q$ / / / / /risGW5W5W5W5W5W5W5W5t{}}r