
    3j	'                     &     G d  d      Z  e        Zy)c                   t    e Zd ZdZd ZddZeZd ZeZddZ	d Z
d Zd	d
efdZd ZddZd Zd Zd Zd Zy)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.

    c                 2    | j                   ryt        d      )z4Ensures that we've loaded at least one JSON backend.Nz*jsonpickle could not load any json modules)	_verifiedAssertionError)selfs    ?/DATA/.local/lib/python3.12/site-packages/jsonpickle/backend.py_verifyzJSONBackend._verify   s    >>IJJ    Nc                 R   | j                          | j                  s$| j                  d   }| j                  ||||      S t	        | j                        D ]  \  }}	 | j                  ||||      c S  y# t
        $ r'}|t        | j                        dz
  k(  r|Y d}~Kd}~ww xY w)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
separators   N)r	   _fallthrough_backend_namesbackend_encode	enumerate	Exceptionlen)r   objr   r   nameidxes          r   encodezJSONBackend.encode   s     	  &&q)D&&tSJ&WW"4#6#67IC**#f +   8
  #d112Q66G 7s   A66	B&?B!!B&c                 X   | j                          | j                  s!| j                  d   }| j                  ||      S t	        | j                        D ]  \  }}	 | j                  ||      c S  y# | j
                  |   $ r'}|t        | j                        dz
  k(  r|Y d}~Qd}~ww xY w)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   decodezJSONBackend.decode,   s     	  &&q)D&&tV44"4#6#67IC**488 8 ++D1 #d112Q66G	s   A00B)B$$B)c                 2   || _         g | _        i | _        i | _        i | _        i | _        i | _        d| _        | j                  d       | j                  d       | j                  d       | j                  dddd	       d
ddif}d
dddf|||d| _        y )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__zJSONBackend.__init__F   s    '   !# !# $&  ,'&!'"&{ 	 	

 +u-.	OP#&/	!
r
   c                     || _         y)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_fallthroughzJSONBackend.enable_fallthroughm   s     #r
   c                 d    	 t        ||      ||<   y# t        $ r | j                  |       Y yw xY w)NFT)getattrAttributeErrorremove_backend)r   dctbackendr   r   s        r   _storezJSONBackend._store~   s>    	"3-CL   	(	s    //r(   r)   c                 X   	 t        |      }	 |j                  d      dd D ]  }t        ||      } 	 | j                  | j                  |||      r| j                  | j                  |||      syt        |t              r| j                  | j                  |||      sy|| j                  |<   | j                  j                  |g i f       | j                  j                  |g i f       | j                  j                  |       d| _        y# t        $ r Y yw xY w# t        $ r Y yw xY w)a  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;   r?   r.   r/   
isinstancestrr   r0   
setdefaultr1   r   appendr   )r   r   r(   r)   r*   modattrs          r   r2   zJSONBackend.load_backend   s(   *	T"C
	

3+c4( ,
 {{4>>4e<DKKNND#uE
 i%;;t77sIN .7D$$T* 	((Bx8((Bx8 	""4( A  		  		s"   D %D 	DD	D)(D)c                    | j                   j                  |d       | j                  j                  |d       | j                  j                  |d       | j                  j                  |d       | j
                  j                  |d       || j                  v r| j                  j                  |       t        | j                        | _	        y)z,Remove all entries for a particular backend.N)
r.   popr/   r   r1   r0   r   removeboolr   )r   r   s     r   r<   zJSONBackend.remove_backend   s    4&4&  $$T40!!$-!!$-4&&&&&t,d112r
   c                     | j                   j                  |g i f      \  }}|j                         }|||d<   |||d<   |ft        |      z   } | j                  |   |i |S )Nr   r   )r0   getcopytupler.   )	r   r   r   r   r   optargs	optkwargsencoder_kwargsencoder_argss	            r   r   zJSONBackend.backend_encode   sz    !2266tb"XF")'-N8$!+5N<(vg.#t~~d#\D^DDr
   c                     | j                   j                  |di f      \  }}|j                         } | j                  |   |g|i |S )Nr+   )r1   rP   rQ   r/   )r   r   r   rS   rT   decoder_kwargss         r   r   zJSONBackend.backend_decode   sO    !2266tb"XF")#t~~d#FGWGGGr
   c                     || j                   v r8| j                   j                  |       | j                   j                  d|       yd|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)r   rM   insertr   )r   r   errmsgs      r   set_preferred_backendz!JSONBackend.set_preferred_backend   sQ    $ 4&&&&&t,&&q$/<tCF ((r
   c                 &    ||f| j                   |<   y)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)r0   r   r   argskwargss       r   set_encoder_optionszJSONBackend.set_encoder_options   s    & (,Vnd#r
   c                 &    ||f| j                   |<   y)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)r1   r^   s       r   set_decoder_optionszJSONBackend.set_decoder_options  s      (,Vnd#r
   )NN)T)__name__
__module____qualname____doc__r	   r   r(   r   r)   r5   r8   r?   
ValueErrorr2   r<   r   r   r\   ra   rc   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>ri      s   W5 W5t }r
   