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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
U
 ý°d!)ã@s˜UddlmZddlZddlZddlmZddlmZddlm    Z    ej
rTddl m Z Gdd    „d    eƒZ e jZd
ed <ejejee fZGd d „d ƒZdS)é)Ú annotationsN)ÚEnum)Úgetdefaulttimeouté)ÚTimeoutStateError)ÚFinalc@seZdZdZdS)Ú _TYPE_DEFAULTéÿÿÿÿN)Ú__name__Ú
__module__Ú __qualname__Útoken©rrúKd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\urllib3/util/timeout.pyrsrzFinal[_TYPE_DEFAULT]Ú_DEFAULT_TIMEOUTc@sØeZdZUdZeZded<deefdddddœdd„Zd    d
œd d „ZeZ    e
dd dœdd„ƒZ e dd    ddœdd„ƒZ e dddœdd„ƒZdd
œdd„Zdd
œdd„Zdd
œdd„Zedd
œdd„ƒZed d
œdd „ƒZdS)!ÚTimeouta€ Timeout configuration.
 
    Timeouts can be defined as a default for a pool:
 
    .. code-block:: python
 
        import urllib3
 
        timeout = urllib3.util.Timeout(connect=2.0, read=7.0)
 
        http = urllib3.PoolManager(timeout=timeout)
 
        resp = http.request("GET", "https://example.com/")
 
        print(resp.status)
 
    Or per-request (which overrides the default for the pool):
 
    .. code-block:: python
 
       response = http.request("GET", "https://example.com/", timeout=Timeout(10))
 
    Timeouts can be disabled by setting all the parameters to ``None``:
 
    .. code-block:: python
 
       no_timeout = Timeout(connect=None, read=None)
       response = http.request("GET", "https://example.com/", timeout=no_timeout)
 
 
    :param total:
        This combines the connect and read timeouts into one; the read timeout
        will be set to the time leftover from the connect attempt. In the
        event that both a connect timeout and a total are specified, or a read
        timeout and a total are specified, the shorter timeout will be applied.
 
        Defaults to None.
 
    :type total: int, float, or None
 
    :param connect:
        The maximum amount of time (in seconds) to wait for a connection
        attempt to a server to succeed. Omitting the parameter will default the
        connect timeout to the system default, probably `the global default
        timeout in socket.py
        <http://hg.python.org/cpython/file/603b4d593758/Lib/socket.py#l535>`_.
        None will set an infinite timeout for connection attempts.
 
    :type connect: int, float, or None
 
    :param read:
        The maximum amount of time (in seconds) to wait between consecutive
        read operations for a response from the server. Omitting the parameter
        will default the read timeout to the system default, probably `the
        global default timeout in socket.py
        <http://hg.python.org/cpython/file/603b4d593758/Lib/socket.py#l535>`_.
        None will set an infinite timeout.
 
    :type read: int, float, or None
 
    .. note::
 
        Many factors can affect the total amount of time for urllib3 to return
        an HTTP response.
 
        For example, Python's DNS resolver does not obey the timeout specified
        on the socket. Other factors that can affect total request time include
        high CPU load, high swap, the program running at a low priority level,
        or other behaviors.
 
        In addition, the read and total timeouts only measure the time between
        read operations on the socket connecting the client and the server,
        not the total amount of time for the request to return a complete
        response. For most requests, the timeout is raised because the server
        has not sent the first byte in the specified time. This is not always
        the case; if a server streams one byte every fifteen seconds, a timeout
        of 20 seconds will not trigger, even though the request will take
        several minutes to complete.
 
        If your goal is to cut off any request after a set amount of wall clock
        time, consider having a second "watcher" thread to cut off a slow
        request.
    Ú _TYPE_TIMEOUTÚDEFAULT_TIMEOUTNÚNone)ÚtotalÚconnectÚreadÚreturncCs4| |d¡|_| |d¡|_| |d¡|_d|_dS)Nrrr)Ú_validate_timeoutÚ_connectÚ_readrÚ_start_connect)ÚselfrrrrrrÚ__init__qszTimeout.__init__Ústr)rcCs(t|ƒj›d|j›d|j›d|j›dS)Nz    (connect=z, read=z, total=ú))Útyper
rrr©rrrrÚ__repr__|szTimeout.__repr__z float | None)ÚtimeoutrcCs|tkrtƒS|S)N)rr)r$rrrÚresolve_default_timeout‚szTimeout.resolve_default_timeout)ÚvalueÚnamerc    Cs¦|dks|tkr|St|tƒr&tdƒ‚z t|ƒWn*ttfk
r\td||fƒd‚YnXz|dkrxtd||fƒ‚Wn&tk
r td||fƒd‚YnX|S)a³Check that a timeout attribute is valid.
 
        :param value: The timeout value to validate
        :param name: The name of the timeout attribute to validate. This is
            used to specify in error messages.
        :return: The validated and casted version of the given value.
        :raises ValueError: If it is a numeric value less than or equal to
            zero, or the type is not an integer, float, or None.
        NzDTimeout cannot be a boolean value. It must be an int, float or None.z>Timeout value %s was %s, but it must be an int, float or None.rzdAttempted to set %s timeout to %s, but the timeout cannot be set to a value less than or equal to 0.)rÚ
isinstanceÚboolÚ
ValueErrorÚfloatÚ    TypeError)Úclsr&r'rrrr†s@ 
ÿ ÿÿýþÿÿÿýzTimeout._validate_timeoutcCs t||dS)aCreate a new Timeout from a legacy timeout value.
 
        The timeout value used by httplib.py sets the same timeout on the
        connect(), and recv() socket requests. This creates a :class:`Timeout`
        object that sets the individual timeouts to the ``timeout`` value
        passed to this function.
 
        :param timeout: The legacy timeout value.
        :type timeout: integer, float, :attr:`urllib3.util.Timeout.DEFAULT_TIMEOUT`, or None
        :return: Timeout object
        :rtype: :class:`Timeout`
        )rr)r)r-r$rrrÚ
from_float°szTimeout.from_floatcCst|j|j|jdS)aCreate a copy of the timeout object
 
        Timeout properties are stored per-pool but each request needs a fresh
        Timeout object to ensure each one has its own start/stop configured.
 
        :return: a copy of the timeout object
        :rtype: :class:`Timeout`
        )rrr)rrrrr"rrrÚcloneÀs z Timeout.cloner+cCs"|jdk    rtdƒ‚t ¡|_|jS)zÃStart the timeout clock, used during a connect() attempt
 
        :raises urllib3.exceptions.TimeoutStateError: if you attempt
            to start a timer that has been started already.
        Nz'Timeout timer has already been started.©rrÚtimeÚ    monotonicr"rrrÚ start_connectÎs
 
zTimeout.start_connectcCs |jdkrtdƒ‚t ¡|jS)aGets the time elapsed since the call to :meth:`start_connect`.
 
        :return: Elapsed time in seconds.
        :rtype: float
        :raises urllib3.exceptions.TimeoutStateError: if you attempt
            to get duration for a timer that hasn't been started.
        Nz:Can't get connect duration for timer that has not started.r0r"rrrÚget_connect_durationÙs
 
ÿzTimeout.get_connect_durationcCs8|jdkr|jS|jdks$|jtkr*|jSt|j|jƒS)a!Get the value to use when setting a connection timeout.
 
        This will be a positive float or integer, the value None
        (never timeout), or the default system timeout.
 
        :return: Connect timeout.
        :rtype: int, float, :attr:`Timeout.DEFAULT_TIMEOUT` or None
        N)rrrÚminr"rrrÚconnect_timeoutçs
 
 
zTimeout.connect_timeoutcCsŒ|jdk    rT|jtk    rT|jdk    rT|jtk    rT|jdkr8|jStdt|j| ¡|jƒƒS|jdk    r||jtk    r|td|j| ¡ƒS| |j¡SdS)a{Get the value for the read timeout.
 
        This assumes some time has elapsed in the connection timeout and
        computes the read timeout appropriately.
 
        If self.total is set, the read timeout is dependent on the amount of
        time taken by the connect timeout. If the connection time has not been
        established, a :exc:`~urllib3.exceptions.TimeoutStateError` will be
        raised.
 
        :return: Value to use for the read timeout.
        :rtype: int, float or None
        :raises urllib3.exceptions.TimeoutStateError: If :meth:`start_connect`
            has not yet been called on this object.
        Nr)rrrrÚmaxr5r4r%r"rrrÚ read_timeoutùsÿþýü
zTimeout.read_timeout)r
r r Ú__doc__rrÚ__annotations__rr#Ú__str__Ú staticmethodr%Ú classmethodrr.r/r3r4Úpropertyr6r8rrrrrs*
U ü ) r)Ú
__future__rr1ÚtypingÚenumrÚsocketrÚ
exceptionsrÚ TYPE_CHECKINGZtyping_extensionsrrr rr:ÚOptionalÚUnionr+rrrrrrÚ<module>s