
    rh	'                     &     " S  S5      r \ " 5       rg)c                       \ rS rSrSrS rSS jr\rS r\r	SS jr
S rS	 rS
S\4S jrS rSS jrS rS rS rS rSrg)JSONBackend   zManages 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.

c                 <    U R                   (       a  g[        S5      e)z4Ensures that we've loaded at least one JSON backend.Nz*jsonpickle could not load any json modules)	_verifiedAssertionError)selfs    L/home/james-whalen/.local/lib/python3.13/site-packages/jsonpickle/backend.py_verifyJSONBackend._verify   s    >>IJJ    Nc                 N   U R                  5         U R                  (       d  U R                  S   nU R                  XAX#S9$ [	        U R                  5       H  u  pT U R                  XAX#S9s  $    g! [
         a)  nU[        U R                  5      S-
  :X  a  Ue SnAMI  SnAff = f)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
separatorsr   N)r
   _fallthrough_backend_namesbackend_encode	enumerate	Exceptionlen)r   objr   r   nameidxes          r	   encodeJSONBackend.encode   s     	  &&q)D&&t&WW"4#6#67IC**f +   8
  #d112Q66G 7s   A11
B$;BB$c                 d   U R                  5         U R                  (       d   U R                  S   nU R                  X!5      $ [	        U R                  5       H  u  p2 U R                  X!5      s  $    g! U R
                  U    a)  nU[        U R                  5      S-
  :X  a  Ue SnAMS  SnAff = f)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   r   N)r
   r   r   backend_decoder   _decoder_exceptionsr   )r   stringr   r   r   s        r	   decodeJSONBackend.decode,   s     	  &&q)D&&t44"4#6#67IC**488 8 ++D1 #d112Q66G	s   A33B/B**B/c                 *   Xl         / U l        0 U l        0 U l        0 U l        0 U l        0 U l        SU l        U R                  S5        U R                  S5        U R                  S5        U R                  SSSSS	9  S
SS04nS
SSS.4UUUS.U l        g )NF
simplejsonjsonujsonyamldump	safe_load	YAMLError)dumpsloads	loads_exc 	sort_keys)r/   escape_forward_slashes)r&   r%   r$   zdjango.util.simplejson)	r   r   	_encoders	_decoders_encoder_options_decoder_optionsr   r   load_backend)r   fallthrough	json_optss      r	   __init__JSONBackend.__init__F   s    '   !# !# $&  ,'&!'"&{ 	 	

 +u-.	OP#&/	!
r   c                     Xl         g)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   )r   enables     r	   enable_fallthroughJSONBackend.enable_fallthroughm   s
     #r   c                 b     [        X45      X'   g! [         a    U R                  U5         gf = f)NFT)getattrAttributeErrorremove_backend)r   dctbackendr   r   s        r	   _storeJSONBackend._store~   s:    	"3-CL   	(	s    ..r+   r,   c                 ~    [        U5      n UR                  S5      SS  H  n[        XV5      nM     U R                  U R                  XU5      (       a"  U R                  U R                  XU5      (       d  g[        U[        5      (       a$  U R                  U R                  XU5      (       d  gOX@R                  U'   U R                  R                  U/ 0 45        U R                  R                  U/ 0 45        U R                  R                  U5        SU l        g! [         a     gf = f! [         a     gf = f)ae  Load 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.r   NT)
__import__ImportErrorsplitr?   r@   rD   r1   r2   
isinstancestrr   r3   
setdefaultr4   r   appendr   )r   r   r+   r,   r-   modattrs          r	   r5   JSONBackend.load_backend   s3   *	T"C
	

3+c( ,
 {{4>>4e<<DKKNNDuE
 E
 i%%;;t77INN O .7$$T* 	((Bx8((Bx8 	""4( A  		  		s"   D &D/ 
D,+D,/
D<;D<c                    U R                   R                  US5        U R                  R                  US5        U R                  R                  US5        U R                  R                  US5        U R
                  R                  US5        XR                  ;   a  U R                  R                  U5        [        U R                  5      U l	        g)z,Remove all entries for a particular backend.N)
r1   popr2   r   r4   r3   r   removeboolr   )r   r   s     r	   rA   JSONBackend.remove_backend   s    4&4&  $$T40!!$-!!$-&&&&&t,d112r   c                     U R                   R                  U/ 0 45      u  pVUR                  5       nUb  X7S'   Ub  XGS'   U4[        U5      -   nU R                  U   " U0 UD6$ )Nr   r   )r3   getcopytupler1   )	r   r   r   r   r   optargs	optkwargsencoder_kwargsencoder_argss	            r	   r   JSONBackend.backend_encode   sr    !2266tb"XF")'-8$!+5<(vg.~~d#\D^DDr   c                     U R                   R                  US0 45      u  p4UR                  5       nU R                  U   " U/UQ70 UD6$ )Nr.   )r4   rX   rY   r2   )r   r   r    r[   r\   decoder_kwargss         r	   r   JSONBackend.backend_decode   sK    !2266tb"XF")~~d#FGWGGGr   c                     XR                   ;   a8  U R                   R                  U5        U R                   R                  SU5        gSU-  n[        U5      e)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)r   rT   insertr   )r   r   errmsgs      r	   set_preferred_backend!JSONBackend.set_preferred_backend   sO    $ &&&&&t,&&q$/<tCF ((r   c                 $    X#4U R                   U'   g)a)  
Associate encoder-specific options with an encoder.

After calling set_encoder_options, any calls to jsonpickle's
encode method will pass the supplied args and kwargs along to
the appropriate backend's encode method.

For example::

    set_encoder_options('simplejson', sort_keys=True, indent=4)

See the appropriate encoder's documentation for details about
the supported arguments and keyword arguments.

WARNING: If you pass sort_keys=True, and the object to encode
contains ``__slots__``, and you set ``warn`` to True,
a TypeError will be raised!
N)r3   r   r   argskwargss       r	   set_encoder_optionsJSONBackend.set_encoder_options   s    & (,nd#r   c                 $    X#4U R                   U'   g)a  
Associate decoder-specific options with a decoder.

After calling set_decoder_options, any calls to jsonpickle's
decode method will pass the supplied args and kwargs along to
the appropriate backend's decode method.

For example::

    set_decoder_options('simplejson', encoding='utf8', cls=JSONDecoder)

See the appropriate decoder's documentation for details about
the supported arguments and keyword arguments.

N)r4   ri   s       r	   set_decoder_optionsJSONBackend.set_decoder_options  s      (,nd#r   )r   r   r4   r2   r3   r1   r   r   )NN)T)__name__
__module____qualname____firstlineno____doc__r
   r   r+   r!   r,   r8   r<   rD   
ValueErrorr5   rA   r   r   rf   rl   ro   __static_attributes__r.   r   r	   r   r      sd    K0 E0 E%
N#" (/g 8t	3EH
)25*5r   r   N)r   r%   r.   r   r	   <module>rx      s   W5 W5t }r   