
    E d                     N   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j        rd dlZ G d de          Z G d de          ZdS )    N)datetime)timezone   )base64_decode)base64_encode)bytes_to_int)int_to_bytes)
want_bytes)BadSignature)BadTimeSignature)SignatureExpired)
Serializer)Signerc                   :    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                 B    t          t          j                              S )zTReturns the current timestamp. The function must return an
        integer.
        )inttime)selfs    [C:\Users\ChattiNader\Documents\MyHotelMatch\api\dev\Lib\site-packages\itsdangerous/timed.pyget_timestampzTimestampSigner.get_timestamp!   s     49;;    tsc                 B    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          |                                                     }t          | j                  }||z   |z   }||z   |                     |          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   sj    5!!!,t/A/A/C/C"D"DEE	""i's{T//6666r   NFsigned_valuemax_agereturn_timestampz_te.Literal[False]c                     d S N r   r&   r'   r(   s       r   unsignzTimestampSigner.unsign<   	     	r   Tz_te.Literal[True]c                     d S r*   r+   r,   s       r   r-   zTimestampSigner.unsignE   r.   r   c                    	 t                                          |          }d}n"# t          $ r}|}|j        pd}Y d}~nd}~ww xY wt	          | j                  }||vr|r|t          d|          |                    |d          \  }}	d}
d}	 t          t          |	                    }
n# t          $ r Y nw xY w|i|
H	 |                     |
          }n1# t          t          t          f$ r}t          d|          |d}~ww xY wt          t          |          ||          |
t          d|          |x|                                 |
z
  }||k    r,t#          d| d	| d
||                     |
                    |dk     r)t#          d| d||                     |
                    |r||                     |
          fS |S )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.unsignN   su    	&WW^^L11FII 	& 	& 	&IY%#FFFFFF	& "" f  "#6GGGG --Q//x!'+	!-"9"9::FF 	 	 	D	
  ! 66v>>EE"G];    +-u   #3y>>5eTTTT >"#8%HHHH $$&&/CW}}&>S>>W>>>! $ : :6 B B    Qww&6S666! $ : :6 B B     	=$44V<<<<s>   #' 
AAAB1 1
B>=B>C D
3DD
c                 X    	 |                      ||           dS # t          $ r Y dS 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   sD    	KKgK6664 	 	 	55	s    
)))NF)NTr*   )__name__
__module____qualname____doc__r   r   r   r   _t_str_bytesbytesr%   typingoverload
_t_opt_intr-   _tTupleboolUnionrD   __classcell__rB   s   @r   r   r      s         s        ; ; ; ; ; ;7, 75 7 7 7 7 _ #16	 "  /	
 
   _ _ #04	 "  .	
 
%/	"   _ #!&	V V"V V 	V
 
"(5(?+U2	3V V V V V Vp \ 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_signerNsaltr   c                 l    t          j        dt                                          |                    S )Nz_t.Iterator[TimestampSigner])rN   castr3   iter_unsigners)r   rW   rB   s     r   rZ   zTimedSerializer.iter_unsigners   s*     w5uww7M7Md7S7STTTr   Fsr'   r(   c                 F   t          |          }d}|                     |          D ]a}	 |                    ||d          \  }}|                     |          }	|r|	|fc S |	c S # t          $ r  t
          $ r}
|
}Y d}
~
Zd}
~
ww xY wt          j        t
          |          )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
   rZ   r-   load_payloadr   r   rN   rY   )r   r[   r'   r(   rW   last_exceptionsignerbase64dr$   r1   errs              r   loadszTimedSerializer.loads   s     qMM))$// 	% 	%F%%+]]w &3 & &" ++G44# ."I----#     % % %!$% glN333s   5A&"A&&B:BBc                 6    |                      ||d|i          S )Nr'   )load_kwargs)_loads_unsafe_impl)r   r[   r'   rW   s       r   loads_unsafezTimedSerializer.loads_unsafe   s$     &&q$Y<P&QQQr   r*   )NFN)NN)rE   rF   rG   rH   r   rV   rN   Type__annotations___t_opt_str_bytesIteratorrZ   rI   rM   rP   Anyrb   rO   rf   rR   rS   s   @r   rU   rU      sD          0?NBGO,>>> (,U U$U	_	%U U U U U U #!&!%#4 #4#4 #4 	#4
 #4 
#4 #4 #4 #4P #!%	R RR R 	R
 
$,	R R R R R R R Rr   rU   ) r   rK   rN   r   r   encodingr   r   r   r	   r
   r@   r   r   r   
serializerr   r_   r   rQ   r9   rJ   rI   Optionalri   r   rM   TYPE_CHECKINGtyping_extensions_ter   rU   r+   r   r   <module>rr      s                     # # # # # # # # # # # # " " " " " " " " " " " "                   ! ! ! ! ! ! ! ! ! ! ! ! " " " " " "      xU
#;|, [
 $####S S S S Sf S S Sl:R :R :R :R :Rj :R :R :R :R :Rr   