
    ^fV<                    8   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j                            d          rd Znej        Zej         Z! e"ej#        $                    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,j-        Z-e,j.        Z.e,j/        Z/e,j0        Z0d Z1d Z2d Z3d Z4d Z5d  Z6 e2              e5              e3              e6             e,7                    d!            e8            Z9e9fd"Z:e9fd#Z; e;              ed$          D ]\  Z<Z= e/e<j>        ge=R   d&d%Z?dS )'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                H     t          j        |          |           d         S )Nr   )codecs
getdecoder)tcodings     E/var/www/html/env/lib/python3.11/site-packages/kombu/serialization.py_decoder      s"    (v ((++A..    PICKLE_PROTOCOL   codec)content_typecontent_encodingencoderc              #     K   	 d V  d S # |$ r  |$ r<}t          |  | |          t          j                    d                    Y d }~d S d }~ww xY w)N   )r   sysexc_info)wrapperincludeexcludeexcs       r   _reraise_errorsr/   %   s      :    : : :s|~~a'8999999999:s   
 
A1AAc                2     |t          |                     S Nr   )sloads     r   pickle_loadsr4   0   s    4

r    c                    | r|  d| dn|S )Nz () )firstseconds     r   parenthesize_aliasr:   5   s#    $)5e  v    v5r    c                  V    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d	S )SerializerRegistryz2The registry keeps track of serialization methods.c                    i | _         i | _        d | _        d | _        d | _        t                      | _        i | _        i | _        d S 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__<   sJ    #%)")-&'*uu$r    utf-8c                |    |rt          |||          | j        |<   |r
|| j        |<   || j        |<   || j        |<   dS )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   s`    2  	#(.$ $DN4   	3+2DN<(*.,'".$r    c                \    d|vr| j         |         }| j                            |           d S N/)rF   rD   discardrG   rK   s     r   enablezSerializerRegistry.enableh   s5    d??$T*D$,,T22222r    c                \    d|vr| j         |         }| j                            |           d S rN   )rF   rD   addrQ   s     r   disablezSerializerRegistry.disablem   s5    d??$T*D$((.....r    c                :   	 | j         |         }| j                            |d           | j                            |d           | j                            |d           | j                             |d           dS # 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   rK   r$   s      r   r   zSerializerRegistry.unregisterr   s    	<,T2LN|T222NtT***!!,555!!$----- 	< 	< 	<(:D::< < <	<s   A9A= =Bc                    	 | j         |         \  | _        | _        | _        dS # 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@   rY   r   rQ   s     r   _set_default_serializerz*SerializerRegistry._set_default_serializer   sd    	4%)^D%9#T')G!!! 	4 	4 	4(2D224 4 4	4s	    $ ANc                H   |dk    rt          |          S |r,| j                            |          st          d|           |st	          |t
                    rdd|fS |s]t	          |t                    rHt          t          d          5  |	                    d          }ddd           n# 1 swxY w Y   d	d|fS |r| j        |         \  }}}n| j
        }| j        }| j        }t          t                    5   ||          }ddd           n# 1 swxY w Y   |||fS )
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.
        rawr[   r   r   r7   r-   rI   Nz
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### 	:dn00<< 	:(8J88: : :  	6ju55 	6 &x55  	2js33 	2 b999 / /++g../ / / / / / / / / / / / / / /'11 	>z* 4L*GG *G5L#=[)) 	$ 	$gdmmG	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$-w66s$   B//B36B3<DDDFc                :   |rt          |          nd}|||vr||vr|                     |d          n!|| j        v r|s|                     |d          |pd                                }|r| j                            |          }|r7t          t                    5   ||          cddd           S # 1 swxY w Y   |t          vrQt          |t                    s<t          t                    5  t          ||          cddd           S # 1 swxY w Y   |S )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disabledrI   )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 0\222/ 	#333$F2211,LLLt;;;E;11,
KKK,7>>@@ 	;^''55F ($[11 ( (!6$<<( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ({22"4-- 3$[11 ; ;"4)9::; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;s$   B66B:=B:3DDDc                    t          d                    |t          | j                            ||          |                              S )Nz-Refusing to deserialize {} content of type {})r	   formatr:   rE   ra   )rG   ctypewhys      r   rl   z)SerializerRegistry._for_untrusted_content  sJ     ;BB"4#4#8#8#F#FNN 
 
 	
r    )rI   r1   )__name__
__module____qualname____doc__rH   r   rR   rU   r   r\   r   TRUSTED_CONTENTr   rl   r7   r    r   r<   r<   9   s        <<   #* /  /  /  /D3 3 3
/ / /
< < <,4 4 4*@7 @7 @7 @7F / / / /b
 
 
 
 
r    r<   c                    d}| }t          |t                    rFd}t          t          d          5  |                    |          }ddd           n# 1 swxY w Y   nd}|||fS )zSpecial case serializer.r   rI   r7   r_   Nr   )rb   rd   r/   r   re   )rf   r$   rh   r%   s       r   r`   r`   !  s    %LG'3 $"["555 	7 	7nn%566G	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 $)722s   AAAc                 d    ddl m}  t                              d| j        | j        dd           dS )z2Register a encoder/decoder for JSON serialization.r   )jsonr~   zapplication/jsonrI   r$   r%   N)kombu.utilsr~   registryr   r   r   )_jsons    r   register_jsonr   .  sK    ))))))fek5;#5'.  0 0 0 0 0r    c                     	 ddl } t                              d| j        | j        dd           dS # t
          $ r$ d }t                              dd|d           Y dS 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-yamlrI   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 Mr    )r   r   r   	safe_dump	safe_loadImportError)r   r   s     r   register_yamlr   7  s    M&$.$.';+2 	 	4 	4 	4 	4 	4  
M 
M 
M	M 	M 	M 	&$7KLLLLLL
Ms   -1 *AAc                :    t          t          |                     S r1   )r4   r   )r2   s    r   unpickler   P  s    Q(((r    c                 l    t           j        fd} t                              d| t          dd           dS )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    vcO4444r    r   zapplication/x-python-serializer   r   N)r   r   r   r   r   )r   s    r   register_pickler   T  sR     "( 5 5 5 5 hh#C'/  1 1 1 1 1r    c                     dx} }	 ddl }|j        dk    rddl mm fd} fd}nd }|x} }n# t          t
          f$ r
 d }|x} }Y nw xY wt                              d	| |d
d           dS )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    uQT2222r    c                     | d          S )NF)r^   r7   )r2   r   s    r   unpackz register_msgpack.<locals>.unpackr  s    wqe,,,,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 3 3 3 3- - - - - -@ @ @ -,D6$ & & &	= 	= 	= &%vvv& 4,!      s   )2 AAr~   c                    | t           u rg dn| } | 0| D ]/}	 t                              |           # t          $ r Y *w xY wdS dS )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   rR   rY   )choiceschoices     r   enable_insecure_serializersr     s     07&/@/@++++gG 	 	F''''   	 	 	s   2
??c                    | t           u rdgn| } t          j        D ]}t                              |           | | D ]}t                              |           dS dS )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?   rU   rR   )allowedrK   s     r   disable_insecure_serializersr     s~     "V++vhhG"   	" 	"DOOD!!!! 	" 	"r    zkombu.serializersc                    st           j        n| >	 fd| D             S # t          $ r"}t          d|j        d                    d}~ww xY w| S )zReplace aliases of content_types with full names from registry.

    Raises
    ------
        SerializerNotInstalled: If the serialization method
            requested is not available.
    Nc                ,    h | ]}d |v r|n|         S )rO   r7   ).0nrF   s     r   	<setcomp>z)prepare_accept_content.<locals>.<setcomp>  s)    NNN1AA|ANNNr    rW   r   )r   rF   rY   r   r   )content_typesrF   es    ` r   prepare_accept_contentr     s     1=N8((,L 	ANNNNNNNN 	A 	A 	A(?AF1I??A A A	A s   # 
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   rK   r   r7   r    r   <module>r      s     " " " " " "  				  



 " " " " " " % % % % % %      : : : : : : : : : : : : : : % % % % % % 6 6 6 6 6 6 6 6
@i<011)/1CDEE<6"" / / / / mGk #bjnn%6::;;
7KLL &L3I2K: : : : %    
6 6 6]
 ]
 ]
 ]
 ]
 ]
 ]
 ]
B  

3 
3 
30 0 0M M M2) ) )1 1 1! ! !J            	     ( ( (	 )/    $ *0 " " " "*      /00  HBHRWt     r    