zmc
2023-12-22 9fdbf60165db0400c2e8e6be2dc6e88138ac719a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
U
ß=®dîã@süddlZddlZddlZddlmZddlmZddlmZddlmZddlmZddlm    Z    dd    lm
Z
dd
l m Z dd l m Z dd l mZdd lmZddlmZejeefZejeZejeZejrØddlZGdd„deƒZGdd„deƒZdS)éN)Údatetime)Útimezoneé)Ú base64_decode)Ú base64_encode)Ú bytes_to_int)Ú int_to_bytes)Ú
want_bytes)Ú BadSignature)ÚBadTimeSignature)ÚSignatureExpired)Ú
Serializer)ÚSignercsÆeZdZdZedœdd„Zeedœdd„Zee    dœd    d
„Z
e j dee d e    dœdd„ƒZe j dee deje    efdœdd„ƒZdee eejeje    efe    fdœ‡fdd„ Zdee edœdd„Z‡ZS)ÚTimestampSignerzþWorks 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 tt ¡ƒS)zTReturns the current timestamp. The function must return an
        integer.
        )ÚintÚtime)Úself©rúId:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\itsdangerous/timed.pyÚ get_timestamp!szTimestampSigner.get_timestamp)ÚtsrcCstj|tjd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)rrrrrÚtimestamp_to_datetime'sz%TimestampSigner.timestamp_to_datetime)ÚvaluercCs@t|ƒ}tt| ¡ƒƒ}t|jƒ}|||}||| |¡S)z:Signs the given string and also attaches time information.)r    rrrÚsepZ get_signature)rrÚ    timestamprrrrÚsign1s
 
 zTimestampSigner.signNFz_te.Literal[False])Ú signed_valueÚmax_ageÚreturn_timestamprcCsdS©Nr©rr r!r"rrrÚunsign<szTimestampSigner.unsignTz_te.Literal[True]cCsdSr#rr$rrrr%Esc
s®ztƒ |¡}d}Wn0tk
rD}z|}|jp2d}W5d}~XYnXt|jƒ}||krl|r`|‚td|d‚| |d¡\}}    d}
d} ztt    |    ƒƒ}
Wnt
k
r¨YnX|dk    r|
dk    rz|  |
¡} Wn8t t tfk
r} ztd|d| ‚W5d} ~ XYnXtt|ƒ|| d‚|
dkr.td|d‚|dk    r–| ¡|
} | |krptd| ›d    |›d
||  |
¡d‚| d kr–td| ›d ||  |
¡d‚|rª||  |
¡fS|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.
        Nóztimestamp missing)ÚpayloadrzMalformed timestamp)r'Z date_signedzSignature age z > z secondsrz  < 0 seconds)Úsuperr%r
r'r    rr ÚrsplitrrÚ    ExceptionrÚ
ValueErrorÚOSErrorÚ OverflowErrorÚstrrr )rr r!r"ÚresultZ    sig_errorÚerrZts_bytesZts_intZts_dtÚexcZage©Ú    __class__rrr%Nsb 
 
 
ÿþ
 
 
ý
 
ý)r r!rcCs0z|j||dWdStk
r*YdSXdS)zeOnly validates the given signed value. Returns ``True`` if
        the signature exists and is valid.)r!TFN)r%r
)rr r!rrrÚvalidate¦s
zTimestampSigner.validate)NF)NT)NF)N)Ú__name__Ú
__module__Ú __qualname__Ú__doc__rrrrÚ _t_str_bytesÚbytesrÚtypingÚoverloadÚ
_t_opt_intr%Ú_tÚTupleÚboolÚUnionr4Ú __classcell__rrr2rrs>
 üûü û üûXrcs€eZdZUdZeZejeed<de    ej
edœ‡fdd„ Z de e ee    ejdœd    d
„Zde e e    ejeejfd œd d „Z‡ZS)ÚTimedSerializerzOUses :class:`TimestampSigner` instead of the default
    :class:`.Signer`.
    Údefault_signerN)Úsaltrcst dtƒ |¡¡S)Nz_t.Iterator[TimestampSigner])r>Úcastr(Úiter_unsigners)rrEr2rrrG·szTimedSerializer.iter_unsignersF)Úsr!r"rErc Cs¢t|ƒ}d}| |¡D]z}z:|j||dd\}}| |¡}    |rL|    |fWS|    WStk
rj‚Yqtk
rŽ}
z|
}W5d}
~
XYqXqt t|¡‚dS)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    rGr%Z load_payloadr r
r>rF) rrHr!r"rEZlast_exceptionÚsignerZbase64drr'ÚerrrrrÚloads¿s$ÿ
 
 
zTimedSerializer.loads)rHr!rErcCs|j||d|idS)Nr!)Z load_kwargs)Z_loads_unsafe_impl)rrHr!rErrrÚ loads_unsafeäszTimedSerializer.loads_unsafe)N)NFN)NN)r5r6r7r8rrDr>ÚTypeÚ__annotations__Ú_t_opt_str_bytesÚIteratorrGr9r=r@ÚAnyrKr?rLrBrrr2rrC°s2
ÿþ ûú (üûrC) rr;r>rrÚencodingrrrrr    r1r
r r Ú
serializerr rIrrAr.r:r9ÚOptionalrOrr=Ú TYPE_CHECKINGZtyping_extensionsZ_terrCrrrrÚ<module>s,