|
Server : Apache System : Linux cvar2.toservers.com 3.10.0-962.3.2.lve1.5.73.el7.x86_64 #1 SMP Wed Aug 24 21:31:23 UTC 2022 x86_64 User : njnconst ( 1116) PHP Version : 8.4.18 Disable Function : NONE Directory : /proc/self/root/usr/lib/python2.7/site-packages/itsdangerous/ |
Upload File : |
�
-/�_c @ s� d d l Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m Z d d l
m Z d � Z d
e
f d � � YZ d S( i����Ni ( t text_type( t json( t
want_bytes( t
BadPayload( t BadSignature( t Signerc C s t | j i � t � S( s5 Checks whether a serializer generates text or binary.( t
isinstancet dumpsR ( t
serializer( ( s? /tmp/pip-install-sTXtzD/itsdangerous/itsdangerous/serializer.pyt is_text_serializer s t
Serializerc B s� e Z d Z e Z e Z i e j d 6g Z d d d d d d d � Z d d � Z d � Z
d d � Z d d � Z d d � Z d d � Z d d
� Z d d � Z d d � Z d d d
� Z d � Z RS( s� 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.
t
digest_methodt itsdangerousc C s� t | � | _ t | � | _ | d k r6 | j } n | | _ t | � | _ | d k rf | j } n | | _ | px i | _ | d k r� t
| j p� d � } n | | _ | p� i | _
d S( N( ( R t
secret_keyt saltt Nonet default_serializerR R t default_signert signert
signer_kwargst listt default_fallback_signerst fallback_signerst serializer_kwargs( t selfR
R R R R R R ( ( s? /tmp/pip-install-sTXtzD/itsdangerous/itsdangerous/serializer.pyt __init__P s
c C s� | d k r! | j } | j } n t | � } y) | rH | j d � } n | j | � SWn% t k
r} } t d d | �� n Xd S( s 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.
s utf-8sS Could not load the payload because an exception occurred on unserializing the data.t original_errorN( R R R t decodet loadst ExceptionR ( R t payloadR t is_textt e( ( s? /tmp/pip-install-sTXtzD/itsdangerous/itsdangerous/serializer.pyt load_payloadi s c C s t | j j | | j � � S( s� 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 t obj( ( s? /tmp/pip-install-sTXtzD/itsdangerous/itsdangerous/serializer.pyt dump_payload� s c C s4 | d k r | j } n | j | j d | | j �S( s� Creates a new instance of the signer to be used. The default
implementation uses the :class:`.Signer` base class.
R N( R R R R
R ( R R ( ( s? /tmp/pip-install-sTXtzD/itsdangerous/itsdangerous/serializer.pyt make_signer� s c c s� | d k r | j } n | j | � Vxv | j D]k } t | � t k rZ | } | j } n* t | � t k r{ | \ } } n | j } | | j d | | �Vq0 Wd S( s� Iterates over all signers to be tried for unsigning. Starts
with the configured signer, then constructs each signer
specified in ``fallback_signers``.
R N(
R R R$ R t typet dictR t tupleR R
( R R t fallbackt kwargs( ( s? /tmp/pip-install-sTXtzD/itsdangerous/itsdangerous/serializer.pyt iter_unsigners� s c C sL t | j | � � } | j | � j | � } | j rH | j d � } n | S( s� Returns a signed string serialized with the internal
serializer. The return value can be either a byte or unicode
string depending on the format of the internal serializer.
s utf-8( R R# R$ t signR R ( R R"