U eG@sddlmZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl m Z mZmZmZmZmZmZddlmZejrdd lmZdd lmZeeZGd d d ejZGd ddZ e de _!dS)) annotationsN) takewhile) TracebackType)ConnectTimeoutError InvalidHeader MaxRetryError ProtocolError ProxyErrorReadTimeoutError ResponseError)reraise)ConnectionPool)BaseHTTPResponsec@s6eZdZUded<ded<ded<ded<ded<d S) RequestHistory str | NonemethodurlException | Noneerror int | Nonestatusredirect_locationN)__name__ __module__ __qualname____annotations__rr@/opt/hc_python/lib/python3.8/site-packages/urllib3/util/retry.pyrs rc@seZdZUdZeddddddgZedd d gZed d gZd Zde d<ddddddeddeddddedfdddddddddddddddddddd Z d!dd"d#d$Z e dUd%dd%dd&d'd(Z dd)d*d+Zd,dd-d.d/Zd0d1d2d3d4Zd0dd2d5d6Zdd)d7d8ZdVd9dd2d:d;Zdd?Zdsz!Retry.__init__..)r0r1r2rr4r3setr6r5r7r8r9r:r;r< frozensetr=r>)selfr0r1r2r3rr4r5r6r7r8r9r:r;r<r=r>rrr__init__s*   zRetry.__init__z typing.Any)kwr?cKs`t|j|j|j|j|j|j|j|j|j |j |j |j |j |j|j|jd}||t|f|S)N)r0r1r2r3rr4r5r6r7r8r9r:r;r=r<r>)dictr0r1r2r3rr4r5r6r7r8r9r:r;r=r<r>updatetype)rGrIparamsrrrnews( z Retry.newzRetry | bool | int | None)retriesr3defaultr?cCsR|dkr|dk r|n|j}t|tr(|St|o2d}|||d}td|||S)z3Backwards-compatibility for the old retries format.N)r3z!Converted retries value: %r -> %r)r* isinstancer r.logdebug)clsrOr3rP new_retriesrrrfrom_int s   zRetry.from_int)r?cCsltttddt|j}|dkr(dS|jd|d}|jdkrV|t|j7}tt dt |j |S)zIFormula for computing the current backoff :rtype: float cSs |jdkSr@)r)xrrr%z(Retry.get_backoff_time..r rrr,) lenlistrreversedr;r7r>randomr-maxminr8)rGconsecutive_errors_len backoff_valuerrrget_backoff_times zRetry.get_backoff_timestr) retry_afterr?cCs^td|rt|}n:tj|}|dkr8td|tj|}|t}t |d}|S)Nz^\s*[0-9]+\s*$zInvalid Retry-After header: r) rematchintemailutils parsedate_tzr mktime_tztimer^)rGrdsecondsretry_date_tuple retry_daterrrparse_retry_after0s      zRetry.parse_retry_afterrz float | None)responser?cCs"|jd}|dkrdS||S)z(Get the value of Retry-After in seconds.z Retry-AfterN)headersgetrprGrqrdrrrget_retry_afterAs zRetry.get_retry_aftercCs ||}|rt|dSdS)NTF)rurlsleeprtrrrsleep_for_retryKs   zRetry.sleep_for_retrycCs"|}|dkrdSt|dS)Nr)rbrlrv)rGbackoffrrr_sleep_backoffSszRetry._sleep_backoffzBaseHTTPResponse | NonecCs(|jr|r||}|rdS|dS)aBSleep between retry attempts. This method will respect a server's ``Retry-After`` response header and sleep the duration of the time requested. If that is not present, it will use an exponential backoff. By default, the backoff factor is 0 and this method will return immediately. N)r<rwry)rGrqsleptrrrrvYs  z Retry.sleep Exception)errr?cCst|tr|j}t|tS)zzErrors when we're fairly sure that the server did not receive the request, so it should be safe to retry. )rQr original_errorrrGr|rrr_is_connection_erroris zRetry._is_connection_errorcCst|ttfS)zErrors that occur after the request has been started, so we should assume that the server began processing it. )rQr r r~rrr_is_read_errorqszRetry._is_read_error)rr?cCs|jr||jkrdSdS)zyChecks if a given HTTP method should be retried upon, depending if it is included in the allowed_methods FT)r5upper)rGrrrr_is_method_retryablewszRetry._is_method_retryableFrg)r status_codehas_retry_afterr?cCs@||sdS|jr"||jkr"dSt|jo<|jo<|o<||jkS)awIs this method/status code retryable? (Based on allowlists and control variables such as the number of total retries to allow, whether to respect the Retry-After header, whether this header is present, and whether the returned status code is on the list of status codes to be retried upon on the presence of the aforementioned header) FT)rr6r.r0r<RETRY_AFTER_STATUS_CODES)rGrrrrrris_retrys zRetry.is_retrycCs:dd|j|j|j|j|j|jfD}|s.dSt|dkS)zAre we out of retries?cSsg|] }|r|qSrr)rBrWrrr sz&Retry.is_exhausted..Fr)r0r1r2r3rr4r_)rG retry_countsrrr is_exhausteds zRetry.is_exhaustedrrzConnectionPool | NonezTracebackType | None)rrrqr_pool _stacktracer?c Cs|jdkr|rtt||||j}|dk r4|d8}|j}|j} |j} |j} |j} d} d}d}|r||r|dkrtt|||n|dk r|d8}n|r| |r| dks|dks| |stt|||n| dk r| d8} n|r| dk r| d8} n||r:| r:| dk r| d8} d} | }|r2|}|j}ns(   $    m