
    ,h                        S SK Jr  S SKJr  S SKrS SKrS SKJr  S SKJ	r	  SSK
Jr  SSK
Jr  SSK
Jr  SS	K
Jr  SS
K
Jr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr   " S S\5      r " S S\\   5      rg)    )annotationsN)datetime)timezone   )base64_decode)base64_encode)bytes_to_int)int_to_bytes)
want_bytes)BadSignature)BadTimeSignature)SignatureExpired)_TSerialized)
Serializer)Signerc                     ^  \ rS rSrSrSS jrSS jrSS jr\R                    S       SS jj5       r
\R                    S       SS jj5       r
  S       SU 4S jjjr
SSS	 jjrS
rU =r$ )TimestampSigner   zWorks 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.
c                >    [        [        R                  " 5       5      $ )zDReturns the current timestamp. The function must return an
integer.
)inttime)selfs    J/var/www/auris/envauris/lib/python3.13/site-packages/itsdangerous/timed.pyget_timestampTimestampSigner.get_timestamp   s     499;    c                H    [         R                  " U[        R                  S9$ )zConvert 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   tss     r   timestamp_to_datetime%TimestampSigner.timestamp_to_datetime#   s     %%bX\\::r   c                    [        U5      n[        [        U R                  5       5      5      n[        U R                  5      nX-   U-   nX-   U R                  U5      -   $ )z:Signs the given string and also attaches time information.)r   r   r
   r   sepget_signature)r   value	timestampr%   s       r   signTimestampSigner.sign-   sV    5!!,t/A/A/C"DE	"i'{T//666r   c                    g N r   signed_valuemax_agereturn_timestamps       r   unsignTimestampSigner.unsign8   s     r   c                    g r,   r-   r.   s       r   r2   r3   @   s     "%r   c                  >  [         TU ]  U5      nSn[	        U R
                  5      nXt;  a  U(       a  Ue[        SUS9eUR                  US5      u  pSn
Sn [        [        U	5      5      n
Ub(  U
b   U R                  U
5      n[        [        U5      XS9eU
c
  [        SUS9eUb]  U R!                  5       U
-
  nX:  a!  [#        SU S	U S
3UU R                  U
5      S9eUS:  a  [#        SU S3UU R                  U
5      S9eU(       a  XR                  U
5      4$ U$ ! [         a"  nUnUR                  =(       d    Sn SnAGN4SnAff = f! [         a     Nf = f! [        [        [        4 a  n[        SUS9UeSnAff = f)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   zMalformed timestamp)r6   date_signedzSignature age z > z secondsr   z < 0 seconds)superr2   r   r6   r   r%   r   rsplitr	   r   	Exceptionr"   
ValueErrorOSErrorOverflowErrorstrr   r   )r   r/   r0   r1   result	sig_errorer%   r'   ts_bytests_intts_dtexcage	__class__s                 r   r2   r3   H   s    	&W^L1FI
 " "#6GG --Q/!!%	!-"9:F  ! 66v>E #3y>5TT >"#8%HH $$&/C}&$SEWIX>! $ : :6 B  Qw&$SE6! $ : :6 B  44V<<<G  	&IYY%#F	&.  		 #G];  +-usA   D! E 5E  !
E+EE
EE F5F  Fc                D     U R                  XS9  g! [         a     gf = f)z]Only validates the given signed value. Returns ``True`` if
the signature exists and is valid.)r0   TF)r2   r   )r   r/   r0   s      r   validateTimestampSigner.validate   s*    	KKK6 		s    
r-   )returnr   )r!   r   rK   r   )r'   str | bytesrK   bytes)NF)r/   rL   r0   
int | Noner1   zt.Literal[False]rK   rM   )NT)r/   rL   r0   rN   r1   zt.Literal[True]rK   ztuple[bytes, datetime])r/   rL   r0   rN   r1   boolrK   ztuple[bytes, datetime] | bytesr,   )r/   rL   r0   rN   rK   rO   )__name__
__module____qualname____firstlineno____doc__r   r"   r)   toverloadr2   rI   __static_attributes____classcell__rG   s   @r   r   r      s     ;7 ZZ #-2	!  +	
 
  ZZ #,0	%!% % *	%
 
 % % #!&	V!V V 	V
 
(V Vp r   r   c                     ^  \ rS rSr% Sr\rS\S'    S	   S
U 4S jjjr   S         SS jjr	  S       SS jjr
SrU =r$ )TimedSerializer   zGUses :class:`TimestampSigner` instead of the default
:class:`.Signer`.
ztype[TimestampSigner]default_signerc                L   > [         R                  " S[        TU ]  U5      5      $ )Ncabc.Iterator[TimestampSigner])rU   castr8   iter_unsigners)r   saltrG   s     r   ra   TimedSerializer.iter_unsigners   s!     vv68Nt8TUUr   c                .   [        U5      nSnU R                  U5       H5  n UR                  XSS9u  pxU R                  U5      n	U(       a  X4s  $ U	s  $    [        R                  " [
        U5      e! [         a    e [
         a  n
U
n Sn
A
Mp  Sn
A
ff = f)aV  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)r0   r1   )r   ra   r2   load_payloadr   r   rU   r`   )r   sr0   r1   rb   last_exceptionsignerbase64dr(   r6   errs              r   loadsTimedSerializer.loads   s     qM))$/F%%+]] &3 &" ++G4#"-- 0$ ff\>22 $   %!$%s   ,A3A33BBBc                &    U R                  XSU0S9$ )Nr0   )load_kwargs)_loads_unsafe_impl)r   rf   r0   rb   s       r   loads_unsafeTimedSerializer.loads_unsafe   s     &&qY<P&QQr   r-   r,   )rb   str | bytes | NonerK   r_   )NFN)
rf   rL   r0   rN   r1   rO   rb   rr   rK   zt.Any)NN)rf   rL   r0   rN   rb   rr   rK   ztuple[bool, t.Any])rP   rQ   rR   rS   rT   r   r]   __annotations__ra   rk   rp   rW   rX   rY   s   @r   r[   r[      s     -<N); *.V&V	'V V #!&#'#3#3 #3 	#3
 !#3 
#3P ##'	RR R !	R
 
R Rr   r[   )
__future__r   collections.abcabccabcr   typingrU   r   r   encodingr   r   r	   r
   r   rE   r   r   r   
serializerr   r   rh   r   r   r[   r-   r   r   <module>r{      sZ    "      # # " "    ! ! $ " Qf Qh:Rj. :Rr   