
     h<              	       B   d 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*j.        Z.d Z/d Z0d Z1d Z2d Z3d Z4 e0              e3              e1              e4             e*5                    d            e0e3e1e4e0e1e3e4d!Z6 e7            Z8e8fd"Z9e8fd#Z: e:              ed$          D ]\  Z;Z< e-e;j=        ge<R   d&d%Z>dS )'zSerialization utilities.    N)
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     O/var/www/html/Sam_Eipo/venv/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_loadsr3   .   s    4

r   c                     | r|  d| dn|S )Nz () )firstseconds     r   parenthesize_aliasr9   3   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 r0   )		_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>   rD   rE   )rF   namer%   decoderr#   r$   s         r   r   zSerializerRegistry.registerD   s`    0  	#(.$ $DN4   	3+2DN<(*.,'".$r   c                 \    d|vr| j         |         }| j                            |           d S N/)rE   rC   discardrF   rJ   s     r   enablezSerializerRegistry.enablee   s5    d??$T*D$,,T22222r   c                 \    d|vr| j         |         }| j                            |           d S rM   )rE   rC   addrP   s     r   disablezSerializerRegistry.disablej   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)zUnregister 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 )rE   r>   popr=   rD   KeyErrorr   )rF   rJ   r#   s      r   r   zSerializerRegistry.unregistero   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=   r@   rA   r?   rX   r   rP   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.
        rawrZ   r   r   r6   r,   rH   Nz
text/plain)
raw_encoder=   getr   
isinstancebytesstrr.   r
   encoder?   r@   rA   )rF   data
serializerpayloadr#   r$   r%   s          r   r   zSerializerRegistry.dumps   s   > 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disabledrH   )r   _for_untrusted_contentrC   lowerr>   r`   r.   r	   SKIP_DECODEra   rc   r   )rF   re   r#   r$   acceptforce_trusted_contentdecodes           r   r   zSerializerRegistry.loads   s   0 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   formatr9   rD   r`   )rF   ctypewhys      r   rk   z)SerializerRegistry._for_untrusted_content  sJ     ;BB"4#4#8#8#F#FNN 
 
 	
r   )rH   r0   )__name__
__module____qualname____doc__rG   r   rQ   rT   r   r[   r   TRUSTED_CONTENTr   rk   r6   r   r   r;   r;   7   s        <<   #*/ / / /B3 3 3
/ / /
< < <(4 4 4&=7 =7 =7 =7@ , , , ,\
 
 
 
 
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   rH   r6   r^   Nr   )ra   rc   r.   r
   rd   )re   r#   rg   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}   application/jsonrH   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yamlapplication/x-yamlrH   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_available8  s     )KM M Mr   )r   r   r   	safe_dump	safe_loadImportError)r   r   s     r   register_yamlr   *  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 r0   )r3   r   )r1   s    r   unpickler   C  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_dumpsM  s    vcO4444r   r   application/x-python-serializer   r   N)r   r   r   r   r   )r   s    r   register_pickler   G  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 )zNRegister msgpack serializer.

    See Also:
        https://msgpack.org/.
    Nr   )r   r!   )packbunpackbc                      | d          S )NT)use_bin_typer6   )r1   r   s    r   packzregister_msgpack.<locals>.packa  s    uQT2222r   c                      | d          S )NF)r]   r6   )r1   r   s    r   unpackz register_msgpack.<locals>.unpackd  s    wqe,,,,r   c                       t          d          )Nz(msgpack requires msgpack-python >= 0.4.0r   r   s     r   version_mismatchz*register_msgpack.<locals>.version_mismatchg  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_availablel  s    (<= = =r   msgpackapplication/x-msgpackr   r   )r   versionr   r   r   
ValueErrorr   r   )r   r   r   r   r   r   r   s        @@r   register_msgpackr   U  s    D6&?f$$........3 3 3 3 3- - - - - -@ @ @ -,D6$ & & &	= 	= 	= &%vvv& 4,!      s   )2 AAr}   )r}   r   r   r   r~   r   r   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   rQ   rX   )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 )aA  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++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 )rN   r6   ).0nrE   s     r   	<setcomp>z)prepare_accept_content.<locals>.<setcomp>  s)    NNN1AA|ANNNr   rV   r   )r   rE   rX   r   r   )content_typesrE   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r0   )?ry   r   osr   r(   collectionsr   
contextlibr   ior   
exceptionsr   r	   r
   r   r   utils.compatr   utils.encodingr   r   __all__	frozensetrm   rz   platform
startswithr   rq   r2   pickle_loadintenvironr`   r   r"   	Exceptionr.   r3   r9   r;   r   r   r   r   r   r_   r   r   r   r   r   r[   
_setupfunsobjectr   r   r   epr   rJ   r   r6   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R
 R
 R
 R
 R
 R
 R
 R
l  

3 
3 
30 0 0M M M2) ) )1 1 1     H            	     ( ( ( %'&5-	 	
 
 )/    " *0 " " " "(      /00  HBHRWt     r   