Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
retry.cpython-313.pyc288 linesDownload Raw Back to __pycache__
1�

2��jyL��J�SSKJr SSKrSSKrSSKrSSKrSSKrSSKrSSKJ	r	 SSK3Jr SSKJ
r
JrJrJrJrJrJr SSKJr \R,(aSS	KJr SS4KJr SSKJr \R:"\5r"SS
\R@5r!"SS5r"\""S5\"l#g)�)�annotationsN)�	takewhile)�
TracebackType�)�ConnectTimeoutError�
InvalidHeader�
MaxRetryError�
ProtocolError�5ProxyError�ReadTimeoutError�
ResponseError�)�reraise)�Self)�ConnectionPool)�BaseHTTPResponsec�H�\rSrSr%S\S'S\S'S\S'S\S'S\S	'S6rg)�RequestHistory�!�7str | None�method�url�Exception | None�error�8int | None�status�redirect_location�N)�__name__�9__module__�__qualname__�__firstlineno__�__annotations__�__static_attributes__r��XD:\code\apps\devtools\python\user_packages\Python313\site-packages\urllib3/util/retry.pyrr!s����	�O�����!�!r%rc���\rSrSr%Sr\"/SQ5r\"/SQ5r\"/SQ5rSr	Sr10S\S	'S11\S'SS
S
S
S
S
\S
S\	SSS
S\S\124S"SjjrS#Sjr
\S$S%Sjj5rS&SjrS'SjrS(SjrS)SjrS*SjrS+S,SjjrS-SjrS-SjrS.SjrS/S0SjjrS1SjrS2S3SjjrS4S jrS!rg
)5�Retry�)aIRetry configuration.13 14Each retry attempt will create a new Retry object with updated values, so15they can be safely reused.16 17Retries can be defined as a default for a pool:18 19.. code-block:: python20 21    retries = Retry(connect=5, read=2, redirect=5)22    http = PoolManager(retries=retries)23    response = http.request("GET", "https://example.com/")24 25Or per-request (which overrides the default for the pool):26 27.. code-block:: python28 29    response = http.request("GET", "https://example.com/", retries=Retry(10))30 31Retries can be disabled by passing ``False``:32 33.. code-block:: python34 35    response = http.request("GET", "https://example.com/", retries=False)36 37Errors will be wrapped in :class:`~urllib3.exceptions.MaxRetryError` unless38retries are disabled, in which case the causing exception will be raised.39 40:param int total:41    Total number of retries to allow. Takes precedence over other counts.42 43    Set to ``None`` to remove this constraint and fall back on other44    counts.45 46    Set to ``0`` to fail on the first retry.47 48    Set to ``False`` to disable and imply ``raise_on_redirect=False``.49 50:param int connect:51    How many connection-related errors to retry on.52 53    These are errors raised before the request is sent to the remote server,54    which we assume has not triggered the server to process the request.55 56    Set to ``0`` to fail on the first retry of this type.57 58:param int read:59    How many times to retry on read errors.60 61    These errors are raised after the request was sent to the server, so the62    request may have side-effects.63 64    Set to ``0`` to fail on the first retry of this type.65 66:param int redirect:67    How many redirects to perform. Limit this to avoid infinite redirect68    loops.69 70    A redirect is a HTTP response with a status code 301, 302, 303, 307 or71    308.72 73    Set to ``0`` to fail on the first retry of this type.74 75    Set to ``False`` to disable and imply ``raise_on_redirect=False``.76 77:param int status:78    How many times to retry on bad status codes.79 80    These are retries made on responses, where status code matches81    ``status_forcelist``.82 83    Set to ``0`` to fail on the first retry of this type.84 85:param int other:86    How many times to retry on other errors.87 88    Other errors are errors that are not connect, read, redirect or status errors.89    These errors might be raised after the request was sent to the server, so the90    request might have side-effects.91 92    Set to ``0`` to fail on the first retry of this type.93 94    If ``total`` is not set, it's a good idea to set this to 0 to account95    for unexpected edge cases and avoid infinite retry loops.96 97:param Collection allowed_methods:98    Set of uppercased HTTP method verbs that we should retry on.99 100    By default, we only retry on methods which are considered to be101    idempotent (multiple requests with the same parameters end with the102    same state). See :attr:`Retry.DEFAULT_ALLOWED_METHODS`.103 104    Set to a ``None`` value to retry on any verb.105 106:param Collection status_forcelist:107    A set of integer HTTP status codes that we should force a retry on.108    A retry is initiated if the request method is in ``allowed_methods``109    and the response status code is in ``status_forcelist``.110 111    By default, this is disabled with ``None``.112 113:param float backoff_factor:114    A backoff factor to apply between attempts after the second try115    (most errors are resolved immediately by a second try without a116    delay). urllib3 will sleep for::117 118        {backoff factor} * (2 ** ({number of previous retries}))119 120    seconds. If `backoff_jitter` is non-zero, this sleep is extended by::121 122        random.uniform(0, {backoff jitter})123 124    seconds. For example, if the backoff_factor is 0.1, then :func:`Retry.sleep` will125    sleep for [0.0s, 0.2s, 0.4s, 0.8s, ...] between retries. No backoff will ever126    be longer than `backoff_max`.127 128    By default, backoff is disabled (factor set to 0).129 130:param float backoff_max:131    The maximum backoff time (in seconds) between retry attempts.132    This value caps the computed backoff from `backoff_factor`.133 134:param float backoff_jitter:135    Random jitter amount (in seconds) added to the computed backoff.136    Jitter is sampled uniformly from `0` to `backoff_jitter`.137 138:param bool raise_on_redirect: Whether, if the number of redirects is139    exhausted, to raise a MaxRetryError, or to return a response with a140    response code in the 3xx range.141 142:param bool raise_on_status: Similar meaning to ``raise_on_redirect``:143    whether we should raise an exception, or return a response,144    if status falls in ``status_forcelist`` range and retries have145    been exhausted.146 147:param tuple history: The history of the request encountered during148    each call to :meth:`~Retry.increment`. The list is in the order149    the requests occurred. Each list item is of class :class:`RequestHistory`.150 151:param bool respect_retry_after_header:152    Whether to respect Retry-After header on status codes defined as153    :attr:`Retry.RETRY_AFTER_STATUS_CODES` or not.154 155:param Collection remove_headers_on_redirect:156    Sequence of headers to remove from the request when a response157    indicating a redirect is returned before firing off the redirected158    request.159 160:param int retry_after_max: Number of seconds to allow as the maximum for161    Retry-After headers. Defaults to :attr:`Retry.DEFAULT_RETRY_AFTER_MAX`.162    Any Retry-After headers larger than this value will be limited to this163    value.164)�HEAD�GET�PUT�DELETE�OPTIONS�TRACE)i�i�i�)�Cookie�
AuthorizationzProxy-Authorization�xi`Tztyping.Final[int]�DEFAULT_RETRY_AFTER_MAXztyping.ClassVar[Retry]�DEFAULT�165NrT�c�J�XlX lX0lXPlX`lUSLdUSLaSnSnX@lU=(d166 [
5UlXplX�l	X�l167UUlX�lX�l
U
=(d SUlX�l[!SU55UlUUlg)NFrrc3�@# �UHoR5v� M g7f�N)�lower)�.0�hs  r&�	<genexpr>�!Retry.__init__.<locals>.<genexpr>s���4168�9�!�G�G�I�I�9�s�)�total�connect�readr�other�redirect�set�status_forcelist�allowed_methods�backoff_factor�backoff_max�retry_after_max�raise_on_redirect�raise_on_status�history�respect_retry_after_header�	frozenset�remove_headers_on_redirect�backoff_jitter)�selfr?r@rArCrrBrFrErGrHrJrKrLrMrOrPrIs                  r&�__init__�Retry.__init__�s���,�169����	����170��u������H� %�� �
� 0� 9�C�E���.��,��&��.���!2��.���}�"���*D�'�*3�4171�9�4172�+173��'�-��r%c��[S0SUR_SUR_SUR_SUR_SUR174_SUR_SUR_SUR_S	UR_S175UR_SUR_SUR_S
UR_SUR_SUR_SUR _SUR"_6nUR%U5 ['U5"S0UD6$)Nr?r@rArCrrBrFrErGrHrIrJrKrLrOrMrPr)�dictr?r@rArCrrBrFrErGrHrIrJrKrLrOrMrP�update�type)rQ�kw�paramss   r&�new�	Retry.new176s*���177��*�*�178��L�L�179����180��]�]�	181�182�;�;�183��*�*�
184�!�0�0�185�"�2�2�186� �.�.�187��(�(�188�!�0�0�189�#�4�4�190�!�0�0�191��L�L�192�(,�'F�'F�193� (,�'F�'F�!194�" �.�.�#195��(	�
�
�b���D�z�#�F�#�#r%c��UcUbUOURn[U[5(aU$[U5=(a SnU"XS9n[RSX5 U$)z3Backwards-compatibility for the old retries format.N)rCz!Converted retries value: %r -> %r)r4�196isinstancer(�bool�log�debug)�cls�retriesrC�default�new_retriess     r&�from_int�Retry.from_int"sX���?�!(�!4�g�#�+�+�G��g�u�%�%��N���>�*�d���'�5���	�	�5�w�L��r%c197�Z�[[[S[UR5555nUS::agUR198SUS-199--nURS:wa%U[R"5UR--
n[[S[URU555$)z9Formula for computing the current backoff200 201:rtype: float202c��URSL$r9)r)�xs r&�<lambda>�(Retry.get_backoff_time.<locals>.<lambda>=s��A�$7�$7�4�$?r%rrrr6)�len�listr�reversedrLrGrP�random�float�max�minrH)rQ�consecutive_errors_len�
backoff_values   r&�get_backoff_time�Retry.get_backoff_time5s���"%���?��$�,�,�AW�X�
�"203��204"�Q�&���+�+�q�5K�a�5O�/P�Q�
����#�%��V�]�]�_�t�/B�/B�B�B�M��S��C�� 0� 0�-�@�A�B�Br%c�r�[R"SU5(a[U5nOg[RRU5nUc[
SU35e[RRU5nU[R"5-205n[US5nX R:�aURnU$)Nz^\s*[0-9]+\s*$zInvalid Retry-After header: r)�re�match�int�email�utils�parsedate_tzr�	mktime_tz�timerqrI)rQ�retry_after�seconds�retry_date_tuple�206retry_dates     r&�parse_retry_after�Retry.parse_retry_afterHs����8�8�%�{�3�3��+�&�G�$�{�{�7�7��D���'�#�&B�;�-�$P�Q�Q����.�.�/?�@�J� �4�9�9�;�.�G��g�q�/���)�)�)��*�*�G��r%c�b�URRS5nUcgURU5$)z(Get the value of Retry-After in seconds.zRetry-AfterN)�headers�getr��rQ�responser�s   r&�get_retry_after�Retry.get_retry_after]s4���&�&�*�*�=�9������%�%�k�2�2r%c�b�URU5nU(a[R"U5 gg)NTF)r�r�sleepr�s   r&�sleep_for_retry�Retry.sleep_for_retrygs'���*�*�8�4����J�J�{�#��r%c�^�UR5nUS::ag[R"U5 g)Nr)rurr�)rQ�backoffs  r&�_sleep_backoff�Retry._sleep_backoffos&���'�'�)���a�<���207�208�7�r%c��UR(a U(aURU5nU(agUR5 g)aSleep between retry attempts.209 210This method will respect a server's ``Retry-After`` response header211and sleep the duration of the time requested. If that is not present, it212will use an exponential backoff. By default, the backoff factor is 0 and213this method will return immediately.214N)rMr�r�)rQr��slepts   r&r��Retry.sleepus1���*�*�x��(�(��2�E������r%c�d�[U[5(aURn[U[5$)zjErrors when we're fairly sure that the server did not receive the215request, so it should be safe to retry.216)r]r�original_errorr�rQ�errs  r&�_is_connection_error�Retry._is_connection_error�s*���c�:�&�&��$�$�C��#�2�3�3r%c�.�[U[[45$)zoErrors that occur after the request has been started, so we should217assume that the server began processing it.218)r]rr219r�s  r&�_is_read_error�Retry._is_read_error�s���#� 0�-�@�A�Ar%c�d�UR(aUR5UR;agg)ziChecks if a given HTTP method should be retried upon, depending if220it is included in the allowed_methods221FT)rF�upper)rQrs  r&�_is_method_retryable�Retry._is_method_retryable�s&�����F�L�L�N�$�:N�:N�$N��r%c���URU5(dgUR(aX R;ag[UR=(a* UR=(a U=(a X R222;5$)aOIs this method/status code retryable? (Based on allowlists and control223variables such as the number of total retries to allow, whether to224respect the Retry-After header, whether this header is present, and225whether the returned status code is on the list of status codes to226be retried upon on the presence of the aforementioned header)227FT)r�rEr^r?rM�RETRY_AFTER_STATUS_CODES)rQr�status_code�has_retry_afters    r&�is_retry�Retry.is_retry�sl���(�(��0�0��� � �[�4I�4I�%I����J�J�
?��/�/�
?��
?�� =� =�=�	228�	229r%c���URURURURURUR2304Vs/sHnU(dMUPM nnU(dg[
U5S:$s snf)zAre we out of retries?Fr)r?r@rArCrrBrr)rQri�retry_countss   r&�is_exhausted�Retry.is_exhausted�sv��231�232�233�����	�	��
�
�����234�235�
�236����
��	�237����<� �1�$�$��238s�A4�A4c239��URSLaU(a[[U5XF5eURnUbUS-nURnURn	UR240n241URnURnSn
SnSnU(a:URU5(a$USLa[[U5XF5eUbUS-nGOU(aRURU5(a<U	SLdUbURU5(d[[U5XF5eU	bU	S-n	O�U(a	UbUS-nO�U(aEUR5(a0U242bU243S-n244Sn
UR5nU(aUnURnOc[Rn
U(aLUR(a;UbUS-n[RRURS9n
URnUR [#XXNU54-nUR%UUU	U245UUUS9nUR'5(a!U=(d [U
5n[)XRU5Ue[*R-SUU5 U$)	alReturn a new Retry object with incremented retry counters.246 247:param response: A response object, or None, if the server did not248    return a response.249:type response: :class:`~urllib3.response.BaseHTTPResponse`250:param Exception error: An error encountered during the request, or251    None if the response was received successfully.252 253:return: A new ``Retry`` object.254FNr�unknownztoo many redirects)r�)r?r@rArCrrBrLz$Incremented Retry for (url='%s'): %r)r?rrWr@rArCrrBr�r�r��get_redirect_locationr
�
GENERIC_ERROR�SPECIFIC_ERROR�formatrLrrZr�r	r_r`)rQrrr�r�_pool�_stacktracer?r@rArC�status_countrB�causerr�response_redirect_locationrL�	new_retry�reasons                    r&�	increment�Retry.increment�s9��&�:�:���5��$�u�+�u�:�:��255�256�����Q�J�E��,�,���y�y���=�=���{�{���257�258������ ���T�.�.�u�5�5��%���d�5�k�5�>�>��$��1����
�t�*�*�5�1�1��u�}���d�6O�6O�PV�6W�6W��d�5�k�5�>�>��!���	���
�� ���259���
�(�8�8�:�:��#��A�
��(�E�)1�)G�)G�)I�&�)�$>�!��_�_�F�260"�/�/�E��H�O�O��+� �A�%�L�%�4�4�;�;����;�X��!�����,�,��6��7H�I�"261�262���H�H���������263�	��!�!�#�#��2�m�E�2�F���F�3��?��	�	�8�#�y�I��r%c��[U5RSURSURSURSUR264SURS3$)Nz(total=z265, connect=z, read=z, redirect=z	, status=�))rWrr?r@rArCr)rQs r&�__repr__�Retry.__repr__%sV���D�z�"�"�#�7�4�:�:�,�j�����O��I�I�;�k�$�-�-��	�$�+�+��a�
Q�	266r%)rFrGrPrHr@rLrBrJrKrArCrOrMrIrrEr?)$r?�bool | int | Noner@rrArrCr�rrrBrrFztyping.Collection[str] | NonerEztyping.Collection[int] | NonerGrprHrprJr^rKr^rLz!tuple[RequestHistory, ...] | NonerMr^rOztyping.Collection[str]rPrprIrz�return�None)rXz267typing.Anyr�r)TN)rb�Retry | bool | int | NonerCr�rcr�r�r()r�rp)r��strr�rp)r�rr�zfloat | None)r�rr�r^)r�r�r9)r��BaseHTTPResponse | Noner�r�)r��	Exceptionr�r^)rr�r�r^)F)rr�r�rzr�r^r�r^)r�r^)NNNNNN)rrrrr�r�rrr�zConnectionPool | Noner�zTracebackType | Noner�r)r�r�)rr r!r"�__doc__rN�DEFAULT_ALLOWED_METHODSr��"DEFAULT_REMOVE_HEADERS_ON_REDIRECT�DEFAULT_BACKOFF_MAXr3r#rRrZ�classmethodrerur�r�r�r�r�r�r�r�r�r�r�r�r$rr%r&r(r()sU��X�v(�<���268 )��9��*3�:�*�&�269��27��.�6�$�#�$&�"��&*�!� �9P�:>� !�0�"&� $�59�+/�
/� #�6�)--� �--��--��	--�270$�--��
--��--�7�--�8�--��--��--� �--��--�3�--�%)�--� %271�!--�&�'--�(�)--�*272�+--�^$�0�'+�-1�	�*��$��+�	�273274����$C�&�*3���� 4�B��FK�275��276�(+�277�>B�278�	
�279�,%�*"��,0�"&�'+�,0�_��_��_�*�	_�280 �_�%�
_�*�_�281�_�B282r%r(�)$�283__future__rr{�loggingrorxr�typing�	itertoolsr�typesr�284exceptionsrrr	r285rrr
�utilr�
TYPE_CHECKING�typing_extensionsr�connectionpoolrr�r�	getLoggerrr_�286NamedTuplerr(r4rr%r&�<module>r�s���"���
�	��
�������	���&�/�+�
����!��"�V�&�&�"�@287�@288�H�a���
r%
codekingpro/portable-devtools · Team Ai