HEX
Server: LiteSpeed
System: Linux kapuas.iixcp.rumahweb.net 5.14.0-427.42.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Nov 1 14:58:02 EDT 2024 x86_64
User: mirz4654 (1666)
PHP: 8.1.33
Disabled: system,exec,escapeshellarg,escapeshellcmd,passthru,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,popen,pclose,dl,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setsid,posix_setuid,posix_setpgid,ini_alter,show_source,define_syslog_variables,symlink,syslog,openlog,openlog,closelog,ocinumcols,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dll,ftp,myshellexec,socket_bind,mail,posix_getwpuid
Upload Files
File: //usr/local/lib/python3.9/site-packages/kombu/__pycache__/serialization.cpython-39.pyc
a

X>hV<�@s�dZddlmZddlZddlZddlZddlZddlmZddl	m
Z
ddlmZddl
mZmZmZmZmZdd	lmZdd
lmZmZdZedd
g�Zeddg�Zej�d�r�dd�ZnejZej Z!e"ej#�$dd��Z%edd�Z&e
e'feffdd��Z(e!fdd�Z)dd�Z*Gdd�d�Z+e+�Z,e,j-Z-e,j.Z.e,j/Z/e,j0Z0dd �Z1d!d"�Z2d#d$�Z3d%d&�Z4d'd(�Z5d)d*�Z6e2�e5�e3�e6�e,�7d+�e8�Z9e9fd,d-�Z:e9fd.d/�Z;e;�ed0�D]\Z<Z=e/e<j>ge=�R��q�d3d1d2�Z?dS)4zSerialization 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/datazapplication/text�javacCst�|�|�dS)Nr)�codecs�
getdecoder)�tZcoding�r�=/usr/local/lib/python3.9/site-packages/kombu/serialization.py�_decodesrZPICKLE_PROTOCOL��codec)�content_type�content_encoding�encoderc
cs^z
dVWnN|y�Yn<|yX}z$t|||�t��d�WYd}~n
d}~00dS)N�)r�sys�exc_info)�wrapper�include�exclude�excrrr�_reraise_errors%s
r*cCs|t|��S�Nr)�s�loadrrr�pickle_loads0sr.cCs|r|�d|�d�S|S)Nz (�)r)�first�secondrrr�parenthesize_alias5sr2c@sdeZdZdZdd�Zddd�Zdd�Zd	d
�Zdd�Zd
d�Z	ddd�Z
ddefdd�Zdd�Z
dS)�SerializerRegistryz2The registry keeps track of serialization methods.cCs6i|_i|_d|_d|_d|_t�|_i|_i|_dSr+)	�	_encoders�	_decoders�_default_encode�_default_content_type�_default_content_encoding�set�_disabled_content_types�type_to_name�name_to_type)�selfrrr�__init__<szSerializerRegistry.__init__�utf-8cCs<|rt|||�|j|<|r$||j|<||j|<||j|<dS)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)rr4r5r;r<)r=�namer"�decoderr r!rrrrFs�


zSerializerRegistry.registercCs"d|vr|j|}|j�|�dS�N�/)r<r:�discard�r=r@rrr�enablehs
zSerializerRegistry.enablecCs"d|vr|j|}|j�|�dSrB)r<r:�addrErrr�disablems
zSerializerRegistry.disablecCslzF|j|}|j�|d�|j�|d�|j�|d�|j�|d�Wn tyftd|����Yn0dS)aUnregister 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 )r<r5�popr4r;�KeyErrorr)r=r@r rrrrrs
�zSerializerRegistry.unregistercCs@z|j|\|_|_|_Wn ty:td|����Yn0dS)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)r4r7r8r6rKrrErrr�_set_default_serializer�s�
��z*SerializerRegistry._set_default_serializerNcCs�|dkrt|�S|r.|j�|�s.td|����|sFt|t�rFdd|fS|s�t|t�r�ttdd��|�	d�}Wd�n1s�0Yd	d|fS|r�|j|\}}}n|j
}|j}|j}tt��||�}Wd�n1s�0Y|||fS)
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.
        �rawrLrrr�r(r?Nz
text/plain)
�
raw_encoder4�getr�
isinstance�bytes�strr*r
�encoder6r7r8)r=�data�
serializer�payloadr r!r"rrrr�s*"�
(
�

&zSerializerRegistry.dumpsFcCs�|rt|�nd}|dur6||vrP||vrP|�|d��n||jvrP|sP|�|d��|pVd��}|�r�|j�|�}|r�tt��||�Wd�S1s�0Y|tv�r�t	|t
��s�tt��t||�Wd�S1s�0Y|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.
        rNZ	untrusted�disabledr?)r�_for_untrusted_contentr:�lowerr5rQr*r	�SKIP_DECODErRrTr)r=rVr r!�accept�forceZ_trusted_content�decoderrrr�s,��
&
�
(zSerializerRegistry.loadsc	Cs td�|t|j�||�|���S)Nz-Refusing to deserialize {} content of type {})r�formatr2r;rQ)r=�ctype�whyrrrrZs��z)SerializerRegistry._for_untrusted_content)r?)N)�__name__�
__module__�__qualname__�__doc__r>rrFrHrrMr�TRUSTED_CONTENTrrZrrrrr39s�
"
C�
1r3cCs\d}|}t|t�rNd}ttdd��|�|�}Wd�qR1sB0Ynd}|||fS)zSpecial case serializer.rr?rrONr)rRrTr*r
rU)rVr rXr!rrrrP!s
*rPcCs(ddlm}tjd|j|jddd�dS)z2Register a encoder/decoder for JSON serialization.r)�jsonrhzapplication/jsonr?�r r!N)Zkombu.utilsrh�registryrrr)�_jsonrrr�
register_json.s
�rlc	CsTz$ddl}tjd|j|jddd�Wn*tyNdd�}t�dd|d�Yn0dS)	z�Register 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

    rN�yamlzapplication/x-yamlr?ric_std��dS)z�Raise SerializerNotInstalled.

            Used in case a client receives a yaml message, but yaml
            isn't installed.
            z9No decoder installed for YAML. Install the PyYAML libraryN�r��args�kwargsrrr�
not_availableEs�z$register_yaml.<locals>.not_available)rmrjrZ	safe_dumpZ	safe_load�ImportError)rmrrrrr�
register_yaml7s�
rtcCstt|��Sr+)r.r�r,rrr�unpicklePsrvcCs&tjfdd�}tjd|tddd�dS)zpRegister pickle serializer.

    The fastest serialization method, but restricts
    you to python clients.
    cSs||td�S)N)�protocol)�pickle_protocol)�objZdumperrrr�pickle_dumpsZsz%register_pickle.<locals>.pickle_dumpsrzapplication/x-python-serializerriN)rrrjrrv)rzrrr�register_pickleTs

�r{c	s�d}}zPddl}|jdkrFddlm�m��fdd�}�fdd�}nd	d
�}|}}Wn&ttfy~dd�}|}}Yn0tjd
||ddd�dS)zZRegister msgpack serializer.

    See Also
    --------
        https://msgpack.org/.
    Nr)rr��packb�unpackbcs�|dd�S)NT)�use_bin_typerru)r}rr�packoszregister_msgpack.<locals>.packcs�|dd�S)NF)rNrru)r~rr�unpackrsz register_msgpack.<locals>.unpackc_std��dS)Nz(msgpack requires msgpack-python >= 0.4.0rnrorrr�version_mismatchus�z*register_msgpack.<locals>.version_mismatchc_std��dS)NzKNo decoder installed for msgpack. Please install the msgpack-python libraryrnrorrrrrzs�z'register_msgpack.<locals>.not_available�msgpackzapplication/x-msgpackrri)r��versionr}r~rs�
ValueErrorrjr)r�r�r�r�rrrr|r�register_msgpackbs"
�r�rhc	CsL|turgd�n|}|durH|D]&}zt�|�Wq tyDYq 0q dS)z�Enable 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.
    )rrmr�N)�NOTSETrjrFrK)�choices�choicerrr�enable_insecure_serializers�s	r�cCsH|turdgn|}tjD]}t�|�q|durD|D]}t�|�q4dS)aJDisable 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.
    rhN)r�rjr5rHrF)�allowedr@rrr�disable_insecure_serializers�s
r�zkombu.serializersc
sh�s
tjn��|durdz�fdd�|D�WStyb}z td|jd����WYd}~n
d}~00|S)z�Replace aliases of content_types with full names from registry.

    Raises
    ------
        SerializerNotInstalled: If the serialization method
            requested is not available.
    Ncs h|]}d|vr|n�|�qS)rCr)�.0�n�r<rr�	<setcomp>��z)prepare_accept_content.<locals>.<setcomp>rIr)rjr<rKrrp)Z
content_typesr<�err�r�prepare_accept_content�s�r�)N)@rf�
__future__rr�osrr$�collectionsr�
contextlibr�ior�
exceptionsrr	r
rrZutils.compatr
Zutils.encodingrr�__all__�	frozensetr\rg�platform�
startswithrr_r-Zpickle_load�int�environrQrxr�	Exceptionr*r.r2r3rjrrrrrPrlrtrvr{r�rM�objectr�r�r��eprpr@r�rrrr�<module>sd

�
b
	%