Format: application/x-python-code
⬇ Download File (6.4 KB)
   1  o
   2  
   3  .'h��@s�ddlmZddlmZddlZddlZddlmZddlm	Z	ddl
   4  mZddl
   5  mZddl
   6  m
   7  Z
   8  dd	l
   9  mZdd
  10  l
  11  mZddlmZddlmZdd
  12  lmZddlmZddlmZddlmZGdd�de�ZGdd�dee�ZdS)�)�annotationsN)�datetime)�timezone�)�
  13  base64_decode)�
  14  base64_encode)�bytes_to_int)�int_to_bytes)�
  15  want_bytes)�BadSignature)�BadTimeSignature)�SignatureExpired)�_TSerialized)�
  16  Serializer)�Signercs~eZdZdZd!dd�Zd"dd	�Zd#d
  17  d�Zej		d$d%dd��Z	ej		d&d'dd��Z			d$d(�fdd�
  18  Z	d)d*dd �Z
  19  �ZS)+�TimestampSignerz�Works like the regular :class:`.Signer` but also records the time
  20      of the signing and can be used to expire signatures. The
  21      :meth:`unsign` method can raise :exc:`.SignatureExpired` if the
  22      unsigning failed because the signature is expired.
  23      �return�intcCstt���S)zTReturns the current timestamp. The function must return an
  24          integer.
  25          )r�time)�self�r�HC:\Users\shubh\Videos\agent\nova\Lib\site-packages\itsdangerous/timed.py�
  26  get_timestampszTimestampSigner.get_timestamp�tsrcCstj|tjd�S)a Convert the timestamp from :meth:`get_timestamp` into an
  27          aware :class`datetime.datetime` in UTC.
  28  
  29          .. versionchanged:: 2.0
  30              The timestamp is returned as a timezone-aware ``datetime``
  31              in UTC rather than a naive ``datetime`` assumed to be UTC.
  32          )�tz)r�
  33  fromtimestampr�utc)rrrrr�timestamp_to_datetime#sz%TimestampSigner.timestamp_to_datetime�value�str | bytes�bytescCs@t|�}tt|����}t|j�}|||}|||�|�S)z:Signs the given string and also attaches time information.)r
  34  rr	r�sepZ
  35  get_signature)rr�	timestampr!rrr�sign-s
  36  
  37  zTimestampSigner.signNF�signed_value�max_age�
  38  int | None�return_timestamp�t.Literal[False]cC�dS�Nr�rr$r%r'rrr�unsign8�zTimestampSigner.unsignT�t.Literal[True]�tuple[bytes, datetime]cCr)r*rr+rrrr,@r-�bool�tuple[bytes, datetime] | bytesc
  39  s�z
  40  t��|�}d}Wnty#}z
  41  |}|jpd}WYd}~nd}~wwt|j�}||vr7|r1|�td|d��|�|d�\}}	d}
  42  d}ztt	|	��}
  43  Wn	t
  44  yTYnw|dur�|
  45  dur{z|�|
  46  �}Wntt
  47  tfyz}ztd|d�|�d}~wwtt|�||d��|
  48  dur�td|d��|dur�|��|
  49  }
  50  |
  51  |kr�td|
  52  �d	|�d
  53  �||�|
  54  �d��|
  55  dkr�td|
  56  �d�||�|
  57  �d��|r�||�|
  58  �fS|S)
  59  a�Works like the regular :meth:`.Signer.unsign` but can also
  60          validate the time. See the base docstring of the class for
  61          the general behavior. If ``return_timestamp`` is ``True`` the
  62          timestamp of the signature will be returned as an aware
  63          :class:`datetime.datetime` object in UTC.
  64  
  65          .. versionchanged:: 2.0
  66              The timestamp is returned as a timezone-aware ``datetime``
  67              in UTC rather than a naive ``datetime`` assumed to be UTC.
  68          N�ztimestamp missing)�payloadrzMalformed timestamp)r3Zdate_signedzSignature age z > z secondsrz < 0 seconds)�superr,rr3r
  69  r!r�rsplitrr�	Exceptionr�
  70  ValueError�OSError�
  71  OverflowError�strrr
  72  )rr$r%r'�resultZ	sig_error�er!rZts_bytesZts_intZts_dt�excZage��	__class__rrr,Hsj��
  73  ������
  74  �cCs*z
  75  |j||d�WdStyYdSw)zeOnly validates the given signed value. Returns ``True`` if
  76          the signature exists and is valid.)r%TF)r,r)rr$r%rrr�validate�s�zTimestampSigner.validate)rr)rrrr)rrrr )NF)r$rr%r&r'r(rr )NT)r$rr%r&r'r.rr/)r$rr%r&r'r0rr1r*)r$rr%r&rr0)�__name__�
  77  __module__�__qualname__�__doc__rrr#�t�overloadr,r@�
  78  __classcell__rrr>rrs"
  79  
  80  
  81  
  82  ��
  83  �XrcsVeZdZUdZeZded<	dd�fd	d
  84  �
  85  Z			dddd�Z		dddd�Z	�Z
  86  S)�TimedSerializerzOUses :class:`TimestampSigner` instead of the default
  87      :class:`.Signer`.
  88      ztype[TimestampSigner]�default_signerN�salt�str | bytes | Noner�cabc.Iterator[TimestampSigner]cst�dt��|��S)NrL)rE�castr4�iter_unsigners)rrJr>rrrN�szTimedSerializer.iter_unsignersF�srr%r&r'r0�t.AnycCs�t|�}d}|�|�D]:}z|j||dd�\}}|�|�}	|r&|	|fWS|	WSty2�tyE}
  89  z|
  90  }WYd}
  91  ~
  92  qd}
  93  ~
  94  wwt�t|��)a�Reverse of :meth:`dumps`, raises :exc:`.BadSignature` if the
  95          signature validation fails. If a ``max_age`` is provided it will
  96          ensure the signature is not older than that time in seconds. In
  97          case the signature is outdated, :exc:`.SignatureExpired` is
  98          raised. All arguments are forwarded to the signer's
  99          :meth:`~TimestampSigner.unsign` method.
 100          NT)r%r')r
 101  rNr,Zload_payloadr
 102  rrErM)rrOr%r'rJZlast_exception�signerZbase64dr"r3�errrrr�loads�s$
 103  �
 104  
 105  ��zTimedSerializer.loads�tuple[bool, t.Any]cCs|j||d|id�S)Nr%)Zload_kwargs)Z_loads_unsafe_impl)rrOr%rJrrr�loads_unsafe�szTimedSerializer.loads_unsafer*)rJrKrrL)NFN)
 106  rOrr%r&r'r0rJrKrrP)NN)rOrr%r&rJrKrrT)rArBrCrDrrI�__annotations__rNrSrUrGrrr>rrH�s
 107  ��(�rH)�
 108  __future__r�collections.abc�abcZcabcr�typingrErr�encodingrrrr	r
 109  r=rrr
 110  �
 111  serializerrrrQrrrHrrrr�<module>s(