Файловый менеджер - Редактировать - /opt/imh-python/lib/python3.9/site-packages/itsdangerous/__pycache__/serializer.cpython-39.pyc
Ðазад
a g�h�! � @ sl d dl Z ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z ddl mZ d d � ZG dd� de �ZdS ) � N� )� text_type)�json)� want_bytes)� BadPayload)�BadSignature)�Signerc C s t | �i �t�S )z5Checks whether a serializer generates text or binary.)� isinstance�dumpsr )� serializer� r ��/root/rpmbuild/BUILDROOT/imh-python39-modules-3.9.7-92.el8.x86_64/opt/imh-python/lib/python3.9/site-packages/itsdangerous/serializer.py�is_text_serializer s r c @ s� e Zd ZdZeZeZdej igZ ddd�Zddd�Zd d � Z ddd�Zd d d�Zd!dd�Zd"dd�Zd#dd�Zd$dd�Zd%dd�Zd&dd�Zdd� ZdS )'� Serializera� This class provides a serialization interface on top of the signer. It provides a similar API to json/pickle and other modules but is structured differently internally. If you want to change the underlying implementation for parsing and loading you have to override the :meth:`load_payload` and :meth:`dump_payload` functions. This implementation uses simplejson if available for dumping and loading and will fall back to the standard library's json module if it's not available. You do not need to subclass this class in order to switch out or customize the :class:`.Signer`. You can instead pass a different class to the constructor as well as keyword arguments as a dict that should be forwarded. .. code-block:: python s = Serializer(signer_kwargs={'key_derivation': 'hmac'}) You may want to upgrade the signing parameters without invalidating existing signatures that are in use. Fallback signatures can be given that will be tried if unsigning with the current signer fails. Fallback signers can be defined by providing a list of ``fallback_signers``. Each item can be one of the following: a signer class (which is instantiated with ``signer_kwargs``, ``salt``, and ``secret_key``), a tuple ``(signer_class, signer_kwargs)``, or a dict of ``signer_kwargs``. For example, this is a serializer that signs using SHA-512, but will unsign using either SHA-512 or SHA1: .. code-block:: python s = Serializer( signer_kwargs={"digest_method": hashlib.sha512}, fallback_signers=[{"digest_method": hashlib.sha1}] ) .. versionchanged:: 0.14: The ``signer`` and ``signer_kwargs`` parameters were added to the constructor. .. versionchanged:: 1.1.0: Added support for ``fallback_signers`` and configured a default SHA-512 fallback. This fallback is for users who used the yanked 1.0.0 release which defaulted to SHA-512. Z digest_method� itsdangerousNc C sz t |�| _t |�| _|d u r"| j}|| _t|�| _|d u r@| j}|| _|pLi | _|d u rft | j pbd�}|| _|pri | _d S )Nr ) r � secret_key�salt�default_serializerr r �default_signer�signer� signer_kwargs�list�default_fallback_signers�fallback_signers�serializer_kwargs)�selfr r r r r r r r r r �__init__P s zSerializer.__init__c C sn |du r| j }| j}nt|�}z|r.|�d�}|�|�W S tyh } ztd|d��W Y d}~n d}~0 0 dS )a Loads the encoded object. This function raises :class:`.BadPayload` if the payload is not valid. The ``serializer`` parameter can be used to override the serializer stored on the class. The encoded ``payload`` should always be bytes. N�utf-8zSCould not load the payload because an exception occurred on unserializing the data.)�original_error)r r �decode�loads� Exceptionr )r �payloadr Zis_text�er r r �load_payloadi s �zSerializer.load_payloadc C s t | jj|fi | j���S )z�Dumps the encoded object. The return value is always bytes. If the internal serializer returns text, the value will be encoded as UTF-8. )r r r r )r �objr r r �dump_payload� s zSerializer.dump_payloadc C s( |du r| j }| j| jfd|i| j��S )z�Creates a new instance of the signer to be used. The default implementation uses the :class:`.Signer` base class. Nr )r r r r )r r r r r �make_signer� s zSerializer.make_signerc c sv |du r| j }| �|�V | jD ]P}t|�tu r<|}| j}nt|�tu rR|\}}n| j}|| jfd|i|��V q dS )z�Iterates over all signers to be tried for unsigning. Starts with the configured signer, then constructs each signer specified in ``fallback_signers``. Nr ) r r'