
    IhV<                    (   d Z ddlmZ ddlZddlZddlZddlZddlmZ ddl	m
Z
 ddlmZ ddlmZmZmZmZmZ dd	lmZ dd
lmZmZ dZ eddg      Z eddg      Zej8                  j;                  d      rd Znej>                  Zej@                  Z! e"ejF                  jI                  dd            Z% edd      Z&e
e'feffd       Z(e!fdZ)d Z* G d d      Z+ e+       Z,e,jZ                  Z-e,j\                  Z.e,j^                  Z/e,j`                  Z0d Z1d Z2d Z3d Z4d Z5d  Z6 e2         e5         e3         e6        e,jo                  d!        e8       Z9e9fd"Z:e9fd#Z; e;         ed$      D ]  \  Z<Z= e/e<j|                  ge=   d&d%Z?y)'zSerialization utilities.    )annotationsN)
namedtuple)contextmanagerBytesIO   )ContentDisallowedDecodeErrorEncodeErrorSerializerNotInstalledreraise)entrypoints)bytes_to_strstr_to_bytes)pickleloadsdumpsregister
unregisterbinaryz
ascii-8bitapplication/datazapplication/textjavac                >     t        j                  |      |       d   S )Nr   )codecs
getdecoder)tcodings     L/var/www/html/planif/env/lib/python3.12/site-packages/kombu/serialization.py_decoder      s    (v  (+A..    PICKLE_PROTOCOL   codec)content_typecontent_encodingencoderc              #     K   	 d  y # |$ r  |$ r2}t        |  | |      t        j                         d          Y d }~y d }~ww xY ww)N   )r   sysexc_info)wrapperincludeexcludeexcs       r   _reraise_errorsr/   %   sF     :  :s||~a'899:s)   A	 A
A(A A AAc                $     |t        |             S Nr   )sloads     r   pickle_loadsr4   0   s    
r    c                    | r|  d| dS |S )Nz () )firstseconds     r   parenthesize_aliasr:   5   s    $)eWBvha 5v5r    c                  T    e Zd ZdZd Z	 ddZd Zd Zd Zd Z	dd	Z
dd
efdZd Zy)SerializerRegistryz2The registry keeps track of serialization methods.c                    i | _         i | _        d | _        d | _        d | _        t               | _        i | _        i | _        y r1   )		_encoders	_decoders_default_encode_default_content_type_default_content_encodingset_disabled_content_typestype_to_namename_to_type)selfs    r   __init__zSerializerRegistry.__init__<   sB    #%)")-&'*u$r    c                    |rt        |||      | j                  |<   |r|| j                  |<   || j                  |<   || j                  |<   y)a  Register a new encoder/decoder.

        Arguments:
        ---------
            name (str): A convenience name for the serialization method.

            encoder (callable): A method that will be passed a python data
                structure and should return a string representing the
                serialized data.  If :const:`None`, then only a decoder
                will be registered. Encoding will not be possible.

            decoder (Callable): A method that will be passed a string
                representing serialized data and should return a python
                data structure.  If :const:`None`, then only an encoder
                will be registered.  Decoding will not be possible.

            content_type (str): The mime-type describing the serialized
                structure.

            content_encoding (str): The content encoding (character set) that
                the `decoder` method will be returning. Will usually be
                `utf-8`, `us-ascii`, or `binary`.
        N)r#   r>   r?   rE   rF   )rG   namer&   decoderr$   r%   s         r   r   zSerializerRegistry.registerF   sU    2 #(.$DNN4  +2DNN<(*.,'".$r    c                `    d|vr| j                   |   }| j                  j                  |       y N/)rF   rD   discardrG   rJ   s     r   enablezSerializerRegistry.enableh   s-    d?$$T*D$$,,T2r    c                `    d|vr| j                   |   }| j                  j                  |       y rM   )rF   rD   addrP   s     r   disablezSerializerRegistry.disablem   s-    d?$$T*D$$((.r    c                :   	 | j                   |   }| j                  j                  |d       | j                  j                  |d       | j                  j                  |d       | j                   j                  |d       y# t
        $ r t        d|       w xY w)a  Unregister registered encoder/decoder.

        Arguments:
        ---------
            name (str): Registered serialization method name.

        Raises
        ------
            SerializerNotInstalled: If a serializer by that name
                cannot be found.
        N!No encoder/decoder installed for )rF   r?   popr>   rE   KeyErrorr   )rG   rJ   r$   s      r   r   zSerializerRegistry.unregisterr   s    	<,,T2LNN|T2NNtT*!!,5!!$- 	<(3D6:< <	<s   A?B Bc                    	 | j                   |   \  | _        | _        | _        y# t        $ r t        d|       w xY w)a  Set the default serialization method used by this library.

        Arguments:
        ---------
            name (str): The name of the registered serialization method.
                For example, `json` (default), `pickle`, `yaml`, `msgpack`,
                or any custom methods registered using :meth:`register`.

        Raises
        ------
            SerializerNotInstalled: If the serialization method
                requested is not available.
        No encoder installed for N)r>   rA   rB   r@   rX   r   rP   s     r   _set_default_serializerz*SerializerRegistry._set_default_serializer   sN    	4%)^^D%9#T')G! 	4(+D624 4	4s   "% =Nc                   |dk(  rt        |      S |r)| j                  j                  |      st        d|       |st	        |t
              rdd|fS |s@t	        |t              r0t        t        d      5  |j                  d      }ddd       d	dfS |r| j                  |   \  }}}n$| j                  }| j                  }| j                  }t        t              5   ||      }ddd       ||fS # 1 sw Y   mxY w# 1 sw Y   xY w)
a  Encode data.

        Serialize a data structure into a string suitable for sending
        as an AMQP message body.

        Arguments:
        ---------
            data (List, Dict, str): The message data to send.

            serializer (str): An optional string representing
                the serialization method you want the data marshalled
                into. (For example, `json`, `raw`, or `pickle`).

                If :const:`None` (default), then json will be used, unless
                `data` is a :class:`str` or :class:`unicode` object. In this
                latter case, no serialization occurs as it would be
                unnecessary.

                Note that if `serializer` is specified, then that
                serialization method will be used even if a :class:`str`
                or :class:`unicode` object is passed in.

        Returns
        -------
            Tuple[str, str, str]: A three-item tuple containing the
            content type (e.g., `application/json`), content encoding, (e.g.,
            `utf-8`) and a string containing the serialized data.

        Raises
        ------
            SerializerNotInstalled: If the serialization method
                requested is not available.
        rawrZ   r   r   r7   r-   utf-8Nz
text/plain)
raw_encoder>   getr   
isinstancebytesstrr/   r   encoder@   rA   rB   )rG   data
serializerpayloadr$   r%   r&   s          r   r   zSerializerRegistry.dumps   s   D d##dnn00<(+J<8: : ju5 &x55 js3 b9 /++g./'11z* 4L*G **G55L#==[) 	$dmG	$-w66/ /	$ 	$s   6C4	D 4C= D	Fc                   |rt        |      nd}|||vr8||vr4| j                  |d      || j                  v r|s| j                  |d      |xs dj                         }|r{| j                  j                  |      }|r!t        t              5   ||      cddd       S |t        vr5t        |t              s%t        t              5  t        ||      cddd       S |S # 1 sw Y   HxY w# 1 sw Y   |S xY w)a  Decode serialized data.

        Deserialize a data stream as serialized using `dumps`
        based on `content_type`.

        Arguments:
        ---------
            data (bytes, buffer, str): The message data to deserialize.

            content_type (str): The content-type of the data.
                (e.g., `application/json`).

            content_encoding (str): The content-encoding of the data.
                (e.g., `utf-8`, `binary`, or `us-ascii`).

            accept (Set): List of content-types to accept.

        Raises
        ------
            ContentDisallowed: If the content-type is not accepted.

        Returns
        -------
            Any: The unserialized data.
        r   N	untrusteddisabledr_   )r   _for_untrusted_contentrD   lowerr?   ra   r/   r
   SKIP_DECODErb   rd   r   )rG   rf   r$   r%   acceptforce_trusted_contentdecodes           r   r   zSerializerRegistry.loads   s    6 7C\2/ 	#33$F211,LLt;;;E11,
KK,7>>@^^''5F$[1 (!$<( ({2"4-$[1 ;"4)9:; ;( (;s   C!	C-!C*-C7c                    t        dj                  |t        | j                  j	                  ||      |                  S )Nz-Refusing to deserialize {} content of type {})r	   formatr:   rE   ra   )rG   ctypewhys      r   rl   z)SerializerRegistry._for_untrusted_content  s=     ;BB"4#4#4#8#8#FN
 	
r    )r_   r1   )__name__
__module____qualname____doc__rH   r   rQ   rT   r   r[   r   TRUSTED_CONTENTr   rl   r7   r    r   r<   r<   9   sD    < #* /D3
/
<,4*@7F /b
r    r<   c                    d}| }t        |t              r.d}t        t        d      5  |j	                  |      }ddd       nd}|||fS # 1 sw Y   xY w)zSpecial case serializer.r   r_   r7   r^   Nr   )rb   rd   r/   r   re   )rf   r$   rh   r%   s       r   r`   r`   !  se    %LG'3"["5 	7nn%56G	7 	7 $)722		7 	7s   A

Ac                 l    ddl m}  t        j                  d| j                  | j
                  dd       y)z2Register a encoder/decoder for JSON serialization.r   )jsonr~   zapplication/jsonr_   r$   r%   N)kombu.utilsr~   registryr   r   r   )_jsons    r   register_jsonr   .  s,    )fekk5;;#5'.  0r    c                     	 ddl } t        j                  d| j                  | j                  dd       y# t
        $ r d }t        j                  dd|d       Y yw xY w)zRegister a encoder/decoder for YAML serialization.

    It is slower than JSON, but allows for more data types
    to be serialized. Useful if you need to send data such as dates

    r   Nyamlzapplication/x-yamlr_   r   c                     t        d      )zRaise SerializerNotInstalled.

            Used in case a client receives a yaml message, but yaml
            isn't installed.
            z9No decoder installed for YAML. Install the PyYAML libraryr   argskwargss     r   not_availablez$register_yaml.<locals>.not_availableE  s     )KM Mr    )r   r   r   	safe_dump	safe_loadImportError)r   r   s     r   register_yamlr   7  sb    M&$..$..';+2 	 	4  
M	M 	&$7KL
Ms   25 $AAc                *    t        t        |             S r1   )r4   r   )r2   s    r   unpickler   P  s    Q((r    c                 f    t         j                  fd} t        j                  d| t        dd       y)zpRegister pickle serializer.

    The fastest serialization method, but restricts
    you to python clients.
    c                     || t               S )N)protocol)pickle_protocol)objdumpers     r   pickle_dumpsz%register_pickle.<locals>.pickle_dumpsZ  s    cO44r    r   zapplication/x-python-serializer   r   N)r   r   r   r   r   )r   s    r   register_pickler   T  s1     "( 5 hh#C'/  1r    c                     dx} }	 ddl }|j                  dk\  rddl mm fd} fd}nd }|x} }t        j                  d	| |d
d       y# t        t
        f$ r
 d }|x} }Y 3w xY w)zZRegister msgpack serializer.

    See Also
    --------
        https://msgpack.org/.
    Nr   )r   r"   )packbunpackbc                     | d      S )NT)use_bin_typer7   )r2   r   s    r   packzregister_msgpack.<locals>.packo  s    QT22r    c                     | d      S )NF)r]   r7   )r2   r   s    r   unpackz register_msgpack.<locals>.unpackr  s    qe,,r    c                     t        d      )Nz(msgpack requires msgpack-python >= 0.4.0r   r   s     r   version_mismatchz*register_msgpack.<locals>.version_mismatchu  s    ,>@ @r    c                     t        d      )NzKNo decoder installed for msgpack. Please install the msgpack-python libraryr   r   s     r   r   z'register_msgpack.<locals>.not_availablez  s    (<= =r    msgpackzapplication/x-msgpackr   r   )r   versionr   r   r   
ValueErrorr   r   )r   r   r   r   r   r   r   s        @@r   register_msgpackr   b  s     D6&??f$.3-@ -,D6 4,!   $ &	= &%v&s   -A A)(A)r~   c                ~    | t         u rg dn| } | | D ]  }	 t        j                  |        yy# t        $ r Y (w xY w)zEnable serializers that are considered to be unsafe.

    Note:
    ----
        Will enable ``pickle``, ``yaml`` and ``msgpack`` by default, but you
        can also specify a list of serializers (by name or content type)
        to enable.
    )r   r   r   N)NOTSETr   rQ   rX   )choiceschoices     r   enable_insecure_serializersr     sR     07&/@+gG 	F'	   s   0	<<c                    | t         u rdgn| } t        j                  D ]  }t        j                  |        | | D ]  }t        j	                  |        yy)aJ  Disable untrusted serializers.

    Will disable all serializers except ``json``
    or you can specify a list of deserializers to allow.

    Note:
    ----
        Producers will still be able to serialize data
        in these formats, but consumers will not accept
        incoming data using the untrusted content types.
    r~   N)r   r   r?   rT   rQ   )allowedrJ   s     r   disable_insecure_serializersr     s]     "V+vhG""  	"DOOD!	" r    zkombu.serializersc                    |st         j                  n|}| 	 | D ch c]  }d|v r|n||    c}S | S c c}w # t        $ r }t        d|j                  d          d}~ww xY w)zReplace aliases of content_types with full names from registry.

    Raises
    ------
        SerializerNotInstalled: If the serialization method
            requested is not available.
    NrN   rV   r   )r   rF   rX   r   r   )content_typesrF   nes       r   prepare_accept_contentr     s     1=8((,L 	A@MN1A|A6NN 	 O 	A(3AFF1I;?A A	As!   8 38 8 	A!AA!r1   )@rz   
__future__r   r   osr   r)   collectionsr   
contextlibr   ior   
exceptionsr	   r
   r   r   r   utils.compatr   utils.encodingr   r   __all__	frozensetrn   r{   platform
startswithr   rr   r3   pickle_loadintenvironra   r   r#   	Exceptionr/   r4   r:   r<   r   r   r   r   r   r`   r   r   r   r   r   r[   objectr   r   r   epr   rJ   r   r7   r    r   <module>r      s    "  	  
 " % : : % 6
@<01/1CDE<<6"/ mmGkk bjjnn%6:;7KL &L3I2K: : % 
6]
 ]
B   

30M2)1!J       	     (	 )/ $ *0 "*   /0 HBRWWtr    