4V=jddlmZddlmZddlZddlZddlmZddlm Z ddl m Z ddl m Z ddl m Z dd l mZdd l mZdd lmZdd lmZdd lmZddlmZddlmZddlmZGddeZGddeeZdS)) annotationsN)datetime)timezone) base64_decode) base64_encode) bytes_to_int) int_to_bytes) want_bytes) BadSignature)BadTimeSignature)SignatureExpired) _TSerialized) Serializer)SignerceZdZdZddZddZdd Zej dd dZ ej d!d"dZ dd#fd Z d$d%dZ xZ 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. returnintcBttjS)zTReturns the current timestamp. The function must return an integer. )rtime)selfs @C:\PYTHON\_runtimes\venv\Lib\site-packages\itsdangerous/timed.py get_timestampzTimestampSigner.get_timestamps49;;tsrcBtj|tjS)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 fromtimestamprutc)rrs rtimestamp_to_datetimez%TimestampSigner.timestamp_to_datetime#s%bX\::::rvalue str | bytesbytesct|}tt|}t|j}||z|z}||z||zS)z:Signs the given string and also attaches time information.)r rr rsep get_signature)rr" timestampr&s rsignzTimestampSigner.sign-sj5!!!,t/A/A/C/C"D"DEE "" i's{T//6666rNF signed_valuemax_age int | Nonereturn_timestampt.Literal[False]cdSNrr*r+r-s runsignzTimestampSigner.unsign8s rTt.Literal[True]tuple[bytes, datetime]cdSr0r1r2s rr3zTimestampSigner.unsign@s "%rbooltuple[bytes, datetime] | bytesc t|}d}n"#t$r}|}|jpd}Yd}~nd}~wwxYwt |j}||vr|r|t d|||d\}} d} d} tt| } n#t$rYnwxYw|i| H | | } n1#tttf$r} t d|| d} ~ wwxYwt t||| | t d||x|| z } | |kr,t#d| d |d || | | d kr)t#d| d || | |r|| | fS|S) aWorks 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. Nrztimestamp missing)payloadrzMalformed timestamp)r: date_signedzSignature age z > z secondsrz < 0 seconds)superr3r r:r r&r rsplitr r Exceptionr! ValueErrorOSError OverflowErrorstrrr)rr*r+r-result sig_errorer&r"ts_bytests_intts_dtexcage __class__s rr3zTimestampSigner.unsignHsu  &WW^^L11FII & & &IY%#FFFFFF &"" f   "#6GGG G --Q//x!!% !-"9"9::FF    D   ! 66v>>EE"G];+-u#3y>>5eTTT T >"#8%HHH H  $$&&/CW}}&>S>>W>>>! $ : :6 B B Qww&6S666! $ : :6 B B  =$44V<<< < s>#' A AAB11 B>=B>CD 3DD cX |||dS#t$rYdSwxYw)zeOnly validates the given signed value. Returns ``True`` if the signature exists and is valid.)r+TF)r3r )rr*r+s rvalidatezTimestampSigner.validatesD  KK gK 6 6 64   55 s  )))rr)rrrr)r"r#rr$)NF)r*r#r+r,r-r.rr$)NT)r*r#r+r,r-r4rr5)r*r#r+r,r-r7rr8r0)r*r#r+r,rr7) __name__ __module__ __qualname____doc__rr!r)toverloadr3rM __classcell__rKs@rrrs     ;;;;7777Z#-2 ZZ#,0 %%%%Z%#!& VVVVVVVprrcVeZdZUdZeZded< ddfd Z dddZ dddZ xZ S)TimedSerializerzOUses :class:`TimestampSigner` instead of the default :class:`.Signer`. ztype[TimestampSigner]default_signerNsaltstr | bytes | Nonercabc.Iterator[TimestampSigner]cltjdt|S)Nr[)rRcastr<iter_unsigners)rrYrKs rr^zTimedSerializer.iter_unsignerss*v68N8Nt8T8TUUUrFsr#r+r,r-r7t.AnycFt|}d}||D]a} |||d\}}||} |r| |fcS| cS#t$rt $r } | }Yd} ~ Zd} ~ wwxYwt jt |)aReverse 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 r^r3 load_payloadrr rRr]) rr_r+r-rYlast_exceptionsignerbase64dr(r:errs rloadszTimedSerializer.loadss qMM))$// % %F %%+]]w&3&&"++G44#."I----#    % % %!$ %f\>222s5A&"A&&B:BBtuple[bool, t.Any]c6|||d|iS)Nr+) load_kwargs)_loads_unsafe_impl)rr_r+rYs r loads_unsafezTimedSerializer.loads_unsafes$ &&q$Yrus"""""" ############"""""""""""" !!!!!!!!!!!!$$$$$$""""""QQQQQfQQQh:R:R:R:R:Rj.:R:R:R:R:Rr