
    ,h                        d dl mZ d dlm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 ddlmZ  G d de      Z G d dee         Zy)    )annotationsN)datetime)timezone   )base64_decode)base64_encode)bytes_to_int)int_to_bytes)
want_bytes)BadSignature)BadTimeSignature)SignatureExpired)_TSerialized)
Serializer)Signerc                       e Zd ZdZd	dZd
dZddZej                  	 	 d	 	 	 	 	 	 	 dd       Z	ej                  	 	 d	 	 	 	 	 	 	 dd       Z		 	 d	 	 	 	 	 	 	 d fdZ	dd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.
    c                <    t        t        j                               S )zTReturns the current timestamp. The function must return an
        integer.
        )inttime)selfs    T/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/itsdangerous/timed.pyget_timestampzTimestampSigner.get_timestamp   s     499;    c                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   tss     r   timestamp_to_datetimez%TimestampSigner.timestamp_to_datetime#   s     %%bX\\::r   c                    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   value	timestampr"   s       r   signzTimestampSigner.sign-   sZ    5!!,t/A/A/C"DE	"i's{T//666r   c                     y N r   signed_valuemax_agereturn_timestamps       r   unsignzTimestampSigner.unsign8   s     r   c                     y r(   r)   r*   s       r   r.   zTimestampSigner.unsign@   s     "%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}~0d}~ww xY w# t        $ r Y w xY w# t        t        t        f$ r}t        d|      |d}~w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   zMalformed timestamp)r1   date_signedzSignature age z > z secondsr   z < 0 seconds)superr.   r   r1   r   r"   r   rsplitr	   r   	Exceptionr    
ValueErrorOSErrorOverflowErrorstrr   r   )r   r+   r,   r-   result	sig_errorer"   r$   ts_bytests_intts_dtexcage	__class__s                 r   r.   zTimestampSigner.unsignH   s    	&W^L1FI
 " f"#6GG --Q/x!!%	!-"9:F  ! 66v>E #3y>5eTT >"#8%HH $$&/CW}&$SEWIX>! $ : :6 B  Qw&$SE6! $ : :6 B  $44V<<<G  	&IYY%#F	&.  		 #G];  +-usA   D# E 1E #	E	,EE		EEF/E==F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    	"")returnr   )r   r   rE   r   )r$   str | bytesrE   bytes)NF)r+   rF   r,   
int | Noner-   zt.Literal[False]rE   rG   )NT)r+   rF   r,   rH   r-   zt.Literal[True]rE   ztuple[bytes, datetime])r+   rF   r,   rH   r-   boolrE   ztuple[bytes, datetime] | bytesr(   )r+   rF   r,   rH   rE   rI   )__name__
__module____qualname____doc__r   r    r&   toverloadr.   rD   __classcell__rB   s   @r   r   r      s     ;7 ZZ #-2	!  +	
 
  ZZ #,0	%!% % *	%
 
 % % #!&	V!V V 	V
 
(Vp r   r   c                  |     e Zd ZU dZeZded<   	 d	 	 	 d fdZ	 	 	 d		 	 	 	 	 	 	 	 	 d
dZ	 	 d	 	 	 	 	 	 	 ddZ	 xZ
S )TimedSerializerzOUses :class:`TimestampSigner` instead of the default
    :class:`.Signer`.
    ztype[TimestampSigner]default_signerc                J    t        j                  dt        |   |            S )Ncabc.Iterator[TimestampSigner])rN   castr3   iter_unsigners)r   saltrB   s     r   rX   zTimedSerializer.iter_unsigners   s!     vv68Nt8TUUr   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   rX   r.   load_payloadr   r   rN   rW   )r   sr,   r-   rY   last_exceptionsignerbase64dr%   r1   errs              r   loadszTimedSerializer.loads   s     qM))$/ 	%F%%+]]w &3 &" ++G4#"I--	%$ ff\>22 $   %!$%s   -A2A22BBBc                .    | j                  ||d|i      S )Nr,   )load_kwargs)_loads_unsafe_impl)r   r\   r,   rY   s       r   loads_unsafezTimedSerializer.loads_unsafe   s!     &&q$Y<P&QQr   r(   )rY   str | bytes | NonerE   rV   )NFN)
r\   rF   r,   rH   r-   rI   rY   rf   rE   zt.Any)NN)r\   rF   r,   rH   rY   rf   rE   ztuple[bool, t.Any])rJ   rK   rL   rM   r   rT   __annotations__rX   ra   re   rP   rQ   s   @r   rS   rS      s     -<N); *.V&V	'V #!&#'#3#3 #3 	#3
 !#3 
#3P ##'	RR R !	R
 
Rr   rS   )
__future__r   collections.abcabccabcr   typingrN   r   r   encodingr   r   r	   r
   r   r@   r   r   r   
serializerr   r   r^   r   r   rS   r)   r   r   <module>ro      sZ    "      # # " "    ! ! $ " Qf Qh:Rj. :Rr   