
    2Bf                     V   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 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dlmZ ddlmZ ej&                  eef   Zej.                  e   Zej.                  e   Zej6                  rd dlZ G d de      Z G d de      Zy)    N)datetime)timezone   )base64_decode)base64_encode)bytes_to_int)int_to_bytes)
want_bytes)BadSignature)BadTimeSignature)SignatureExpired)
Serializer)Signerc                   N    e Zd ZdZdefdZdedefdZdede	fdZ
ej                  	 	 dded	ed
dde	fd       Zej                  	 	 dded	ed
ddej                   e	ef   fd       Z	 	 dded	ed
edej$                  ej                   e	ef   e	f   f fdZdded	edefdZ xZS )TimestampSignerzWorks like the regular :class:`.Signer` but also records the time
    of the signing and can be used to expire signatures. The
    :meth:`unsign` method can raise :exc:`.SignatureExpired` if the
    unsigning failed because the signature is expired.
    returnc                 <    t        t        j                               S )zTReturns the current timestamp. The function must return an
        integer.
        )inttime)selfs    R/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/itsdangerous/timed.pyget_timestampzTimestampSigner.get_timestamp!   s     499;    tsc                 L    t        j                  |t        j                        S )a   Convert the timestamp from :meth:`get_timestamp` into an
        aware :class`datetime.datetime` in UTC.

        .. versionchanged:: 2.0
            The timestamp is returned as a timezone-aware ``datetime``
            in UTC rather than a naive ``datetime`` assumed to be UTC.
        )tz)r   fromtimestampr   utc)r   r   s     r   timestamp_to_datetimez%TimestampSigner.timestamp_to_datetime'   s     %%bX\\::r   valuec                     t        |      }t        t        | j                                     }t        | j                        }||z   |z   }||z   | j                  |      z   S )z:Signs the given string and also attaches time information.)r
   r   r	   r   sepget_signature)r   r    	timestampr"   s       r   signzTimestampSigner.sign1   sZ    5!!,t/A/A/C"DE	"i's{T//666r   signed_valuemax_agereturn_timestampz_te.Literal[False]c                      y N r   r&   r'   r(   s       r   unsignzTimestampSigner.unsign<        	r   z_te.Literal[True]c                      y r*   r+   r,   s       r   r-   zTimestampSigner.unsignE   r.   r   c                    	 t         |   |      }d}t	        | j
                        }||vr|r|t        d|      |j                  |d      \  }}	d}
d}	 t        t        |	            }
|*|
| j                  |
      }t        t        |      ||      |
t        d|      |b| j                         |
z
  }||kD  r$t        d| d	| d
|| j                  |
            |dk  r!t        d| d|| j                  |
            |r|| j                  |
      fS |S # t        $ r}|}|j                  xs d}Y d}~/d}~ww xY w# t        $ r Y w xY w)a  Works like the regular :meth:`.Signer.unsign` but can also
        validate the time. See the base docstring of the class for
        the general behavior. If ``return_timestamp`` is ``True`` the
        timestamp of the signature will be returned as an aware
        :class:`datetime.datetime` object in UTC.

        .. versionchanged:: 2.0
            The timestamp is returned as a timezone-aware ``datetime``
            in UTC rather than a naive ``datetime`` assumed to be UTC.
        Nr   ztimestamp missing)payloadr   )r1   date_signedzMalformed timestampzSignature age z > z secondsr   z < 0 seconds)superr-   r   r1   r
   r"   r   rsplitr   r   	Exceptionr   strr   r   )r   r&   r'   r(   result	sig_errorer"   r    ts_bytests_intts_dtage	__class__s                r   r-   zTimestampSigner.unsignN   s    	&W^L1FI
 " f"#6GG --Q/x!'+	!-"9:F  !226:"3y>5eTT >"#8%HH $$&/CW}&$SEWIX>! $ : :6 B  Qw&$SE6! $ : :6 B  $44V<<<y  	&IYY%#F	&.  		s)   D" E "	E+EE	EEc                 J    	 | j                  ||       y# t        $ r Y yw xY w)zeOnly validates the given signed value. Returns ``True`` if
        the signature exists and is valid.)r'   TF)r-   r   )r   r&   r'   s      r   validatezTimestampSigner.validate   s,    	KKgK6 		s    	"")NF)NTr*   )__name__
__module____qualname____doc__r   r   r   r   _t_str_bytesbytesr%   typingoverload
_t_opt_intr-   _tTupleboolUnionr@   __classcell__r>   s   @r   r   r      sB    s  ; ; ;7, 75 7 __ #16	"  /	
 
  __ #04	"  .	
 
%/	"  #!&	O"O O 	O
 
"((5(?+U2	3Ob\ J RV r   r   c                        e Zd ZU dZeZej                  e   ed<   	 dde	dej                  e   f fdZ	 	 	 ddededede	dej                  f
d	Z	 	 ddedede	dej"                  eej                  f   fd
Z xZS )TimedSerializerzOUses :class:`TimestampSigner` instead of the default
    :class:`.Signer`.
    default_signersaltr   c                 J    t        j                  dt        |   |            S )Nz_t.Iterator[TimestampSigner])rJ   castr3   iter_unsigners)r   rS   r>   s     r   rV   zTimedSerializer.iter_unsigners   s!     ww5uw7Md7STTr   sr'   r(   c                 &   t        |      }d}| j                  |      D ]6  }	 |j                  ||d      \  }}| j                  |      }	|r|	|fc S |	c S  t        j                  t
        |      # t        $ r  t
        $ r}
|
}Y d}
~
ld}
~
ww xY w)a  Reverse of :meth:`dumps`, raises :exc:`.BadSignature` if the
        signature validation fails. If a ``max_age`` is provided it will
        ensure the signature is not older than that time in seconds. In
        case the signature is outdated, :exc:`.SignatureExpired` is
        raised. All arguments are forwarded to the signer's
        :meth:`~TimestampSigner.unsign` method.
        NT)r'   r(   )r
   rV   r-   load_payloadr   r   rJ   rU   )r   rW   r'   r(   rS   last_exceptionsignerbase64dr$   r1   errs              r   loadszTimedSerializer.loads   s     qM))$/ 	%F%%+]]w &3 &" ++G4#"I--	%$ gglN33 $   %!$%s   -A2A22BBBc                 .    | j                  ||d|i      S )Nr'   )load_kwargs)_loads_unsafe_impl)r   rW   r'   rS   s       r   loads_unsafezTimedSerializer.loads_unsafe   s!     &&q$Y<P&QQr   r*   )NFN)NN)rA   rB   rC   rD   r   rR   rJ   Type__annotations___t_opt_str_bytesIteratorrV   rE   rI   rL   Anyr^   rK   rb   rN   rO   s   @r   rQ   rQ      s     0?NBGGO,> (,U$U	_	%U #!&!%#4#4 #4 	#4
 #4 
#4P #!%	RR R 	R
 
$,	Rr   rQ   ) r   rG   rJ   r   r   encodingr   r   r   r	   r
   excr   r   r   
serializerr   r[   r   rM   r6   rF   rE   Optionalre   r   rI   TYPE_CHECKINGtyping_extensions_ter   rQ   r+   r   r   <module>ro      s         # # " "    ! ! " xxU
#;;|, [[
#Lf L^:Rj :Rr   