U a@sddlZddlZddlZddlmZddlmZddlmZddlmZddlmZddlm Z dd lm Z dd l m Z dd l m Z dd l mZdd lmZddlmZejeefZejeZejeZejrddlZGdddeZGdddeZdS)N)datetime)timezone) base64_decode) base64_encode) bytes_to_int) int_to_bytes) want_bytes) BadSignature)BadTimeSignature)SignatureExpired) Serializer)SignercseZdZdZedddZeedddZee dd d Z e j dee d e dddZe j dee deje efdddZdee eejeje efe fdfdd Zdee edddZZS)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. )returncCs ttS)zTReturns the current timestamp. The function must return an integer. )inttime)selfrSC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-w3tduf5e\itsdangerous\timed.py get_timestamp!szTimestampSigner.get_timestamp)tsrcCstj|tjdS)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)rrrrrtimestamp_to_datetime'sz%TimestampSigner.timestamp_to_datetime)valuercCs@t|}tt|}t|j}|||}||||S)z:Signs the given string and also attaches time information.)r rrrsepZ get_signature)rr timestamprrrrsign1s   zTimestampSigner.signNFz_te.Literal[False]) signed_valuemax_agereturn_timestamprcCsdSNrrr r!r"rrrunsign<szTimestampSigner.unsignTz_te.Literal[True]cCsdSr#rr$rrrr%Esc sjzt|}d}Wn0tk rD}z|}|jp2d}W5d}~XYnXt|j}||krl|r`|td|d||d\}} d} d} ztt | } Wnt k rYnX|dk r| dk r| | } tt ||| d| dkrtd|d|dk rR| | } | |kr,td| d |d || | d| d krRtd| d || | d|rf|| | 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. Nztimestamp missing)payloadr)r'Z date_signedzMalformed timestampzSignature age z > z secondsrz < 0 seconds)superr%r r'r rr rsplitrr Exceptionrstrrr ) rr r!r"resultZ sig_errorerrZts_bytesZts_intZts_dtZage __class__rrr%NsR          )r r!rcCs0z|j||dWdStk r*YdSXdS)zeOnly validates the given signed value. Returns ``True`` if the signature exists and is valid.)r!TFN)r%r )rr r!rrrvalidates zTimestampSigner.validate)NF)NT)NF)N)__name__ __module__ __qualname____doc__rrrr _t_str_bytesbytesrtypingoverload _t_opt_intr%_tTupleboolUnionr0 __classcell__rrr.rrs>    QrcseZdZUdZeZejeed<de ej edfdd Z de e ee ejdd d Zde e e ejeejfd d d ZZS)TimedSerializerzOUses :class:`TimestampSigner` instead of the default :class:`.Signer`. default_signerN)saltrcstdt|S)Nz_t.Iterator[TimestampSigner])r:castr(iter_unsigners)rrAr.rrrCszTimedSerializer.iter_unsignersF)sr!r"rArc Cst|}d}||D]z}z:|j||dd\}}||} |rL| |fWS| WStk rjYqtk r} z| }W5d} ~ XYqXqtt|dS)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 rCr%Z load_payloadr r r:rB) rrDr!r"rAZlast_exceptionsignerZbase64drr'errrrrloadss$   zTimedSerializer.loads)rDr!rArcCs|j||d|idS)Nr!)Z load_kwargs)Z_loads_unsafe_impl)rrDr!rArrr loads_unsafeszTimedSerializer.loads_unsafe)N)NFN)NN)r1r2r3r4rr@r:Type__annotations___t_opt_str_bytesIteratorrCr5r9r<AnyrGr;rHr>rrr.rr?s2   (r?) rr7r:rrencodingrrrrr excr r r serializerr rErr=r+r6r5OptionalrKrr9 TYPE_CHECKINGZtyping_extensionsZ_terr?rrrrs,