
    ]h9x                     B   d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZmZ d dl	m	Z	 d dl
mZmZmZmZ d dlmZmZmZmZ d dlmZ d dlmZmZmZ d dlmZmZmZmZmZm Z  d	d
l!m"Z"m#Z# d	dl$m%Z% d	dl&m'Z' erd dl(m)Z) d dl*m+Z+m,Z,  ejZ                  e.      Z/d Z0d Z1d Z2d Z3d Z4d Z5 G d de       Z6 G d de      Z7 G d de       Z8 G d de      Z9 G d de       Z: G d d e      Z; G d! d"e       Z< G d# d$e      Z= G d% d&e=      Z> G d' d(e=      Z? G d) d*e      Z@y)+    N)SEEK_SETUnsupportedOperation)time)AnyDictOptionalTYPE_CHECKING)	parse_qsl	urlencodeurlparse
urlunparse)format_date_time)
AzureErrorServiceRequestErrorServiceResponseError)BearerTokenCredentialPolicyHeadersPolicy
HTTPPolicyNetworkTraceLoggingPolicyRequestHistorySansIOHTTPPolicy   )AzureSigningErrorStorageHttpChallenge)DEFAULT_OAUTH_SCOPE)LocationMode)TokenCredential)PipelineRequestPipelineResponsec                     t        | t              r| j                  d      } t        j                  |       }|j                  d      S )Nzutf-8)
isinstancestrencodebase64	b64encodedecode)dataencodeds     i/var/www/core.comfia.cic-ware.com/crm/lib/python3.12/site-packages/azure/storage/blob/_shared/policies.pyencode_base64r*   1   s9    ${{7#t$G>>'""    c                 r    | d   | d   | d   | d   f}t        t        d |            }|syt        |      dk  S )NtotalconnectreadstatusFr   )listfiltermin)settingsretry_countss     r)   is_exhaustedr6   9   sL    W%x	':HV<LhW_N`aLt\23L|q  r+   c                 >    | d   r | d   d| d   dz
  | d   d| y y )Nhookcountr   mode)retry_countlocation_mode r=   )r4   kwargss     r)   
retry_hookr?   A   s9    eXg%6%:(SYJZe^de r+   c                     | j                   j                  }d|cxk  rdk  r#n n |dk(  r|t        j                  k(  ry|dk(  ryy|dk\  r|dv ryyy)Ni,  i  i  Ti  F)i  i  )http_responsestatus_coder   	SECONDARY)responser:   r0   s      r)   is_retryrE   K   s`    ##//F
fs S=T\%;%;;S=} Zr+   c                 |   | j                   j                  dd      r| j                  j                  j                  d      r{| j                  j                  j                  dd       xs6 t        t        j                  | j                  j                                     }| j                  j                  d   |k7  ryy)Nvalidate_contentFcontent-md5T)	contextgetrA   headershttp_requestr*   StorageContentValidationget_content_md5body)rD   computed_md5s     r)   is_checksum_retryrQ   `   s    .68;Q;Q;Y;Y;];]^k;l,,4488M s)*B*R*RS[SiSiSnSnSp*qr 	!!))-8LHr+   c                 |    t        |       }|j                  |j                  dz   |z         }|j                         S )N/)path)r   _replacerT   geturl)base_urlstub_urlparseds      r)   urljoinrZ   j   s6    hF__&++"3h">_?F==?r+   c                       e Zd Zd Zy)QueueMessagePolicyc                     |j                   j                  j                  dd       }|r0t        |j                  j
                  |      |j                  _        y y )Nqueue_message_id)rI   optionspoprZ   rL   url)selfrequest
message_ids      r)   
on_requestzQueueMessagePolicy.on_requestr   sL    __,,001CTJ
'.$$(((G  $ r+   N)__name__
__module____qualname__re   r=   r+   r)   r\   r\   p   s    r+   r\   c                   $     e Zd ZdZd fdZ xZS )StorageHeadersPolicyx-ms-client-request-idc                 @   t         t        |   |       t        t	                     }||j
                  j                  d<   |j                  j                  j                  dd       }|xs t        t        j                               |j
                  j                  d<   y )Nz	x-ms-dateclient_request_idrk   )superrj   re   r   r   rL   rK   rI   r_   r`   r"   uuiduuid1)rb   rc   current_time	custom_id	__class__s       r)   re   zStorageHeadersPolicy.on_request}   s}    "D4W='/4@$$[1OO++//0CTJ	AJA_cRVR\R\R^N_$$%=>r+   rc   r   returnN)rf   rg   rh   request_id_header_namere   __classcell__rs   s   @r)   rj   rj   z   s    5` `r+   rj   c                   (     e Zd Zd fd	ZddZ xZS )StorageHostsc                 8    || _         t        t        |           y N)hostsrn   rz   __init__)rb   r}   r>   rs   s      r)   r~   zStorageHosts.__init__   s    
lD*,r+   c                    | j                   |j                  j                  d<   t        |j                  j
                        }t        j                  }| j                   j                         D ]  \  }}|j                  |k(  s|} |j                  j                  j                  dd       }|rzd|j                  j                  d<   || j                   vrt        d|       ||k7  r@|j                  | j                   |         }|j                         |j                  _        |}||j                  j                  d<   y )Nr}   use_locationFretry_to_secondaryz*Attempting to use undefined host location netlocr<   )r}   rI   r_   r   rL   ra   r   PRIMARYitemsr   r`   
ValueErrorrU   rV   )rb   rc   
parsed_urlr<   keyvaluer   updateds           r)   re   zStorageHosts.on_request   s   +/::(g22667
 %,,****, 	$JC  E) #	$
 ..22>4H<AGOO##$894::- #Ml^!\]]},$--TZZ5M-N+2>>+;$$( ,3@0r+   r|   rt   rf   rg   rh   r~   re   rw   rx   s   @r)   rz   rz      s    -Ar+   rz   c                   >     e Zd ZdZddeddf fdZd	dZd
dZ xZS )StorageLoggingPolicyzA policy that logs HTTP request and response to the DEBUG logger.

    This accepts both global configuration, and per-request level with "enable_http_logger"
    logging_enableru   Nc                 ^    |j                  dd      | _        t        t        |   dd|i| y )Nlogging_bodyFr   r=   )r`   r   rn   r   r~   )rb   r   r>   rs   s      r)   r~   zStorageLoggingPolicy.__init__   s/    "JJ~u="D2[.[TZ[r+   c           
         |j                   }|j                  j                  }| j                  xs |j	                  dd      | _        |j	                  d| j
                        rd|j                  d<   t        j                  t        j                        sy 	 |j                  }|j                  }d|v r|j                  |d   d      }t        j                  d|       t        j                  d|j                         t        j                  d	       |j                  j!                         D ]  \  }}|j#                         d
k(  rd}n\|j#                         dk(  rId|v rEt%        |      \  }}	}
}}}t'        t)        |            }d|d<   t+        ||	|
|t-        |      |f      }t        j                  d||        t        j                  d       | j                  r)t        j                  t/        |j0                               y t        j                  d       y y # t2        $ r }t        j                  d|       Y d }~y d }~ww xY w)Nr   Fr   Tsigz	sig=*****zRequest URL: %rzRequest method: %rzRequest headers:authorizationz*****zx-ms-copy-source
    %r: %rzRequest body:z1Hidden body, please use logging_body to show bodyzFailed to log request: %r)rL   rI   r_   r   r`   enable_http_logger_LOGGERisEnabledForloggingDEBUGra   queryreplacedebugmethodrK   r   lowerr   dictr
   r   r   r"   rO   	Exception)rb   rc   rL   r_   log_urlquery_paramsheaderr   schemer   rT   paramsr   fragment	parsed_qserrs                   r)   re   zStorageLoggingPolicy.on_request   s   ++//)) --S^U1S;;')@)@A04GOO,-''6@&**+11L(%ool5.A;OG/92L4G4GH01%1%9%9%?%?%A ?MFE||~8 '+==%5.HPQVEfeX$(5)9$:	+2	%( !+FFD&)T]J^`h+i jMM,>? o.$$MM#l&7&7"89 MM"UVA BB  @93??@s   E0H! 
H! !	I
*II
c                 ~   |j                   j                  d| j                        r=t        j	                  t
        j                        sy 	 t        j                  d|j                  j                         t        j                  d       |j                  j                  j                         D ]  \  }}t        j                  d||        t        j                  d       t        j                  dt        j                        }|j                  j                  j                  d      }|j                  j                  j                  dd	      }|r<|j!                  |      r+|j#                  d
      d   }t        j                  d|       nM|j%                  d      rt        j                  d       n&|j'                  d      rt        j                  d       | j(                  r?|j'                  d      r.t        j                  |j                  j+                                y | j(                  r/	 t        j                  |j                  j-                                y y y # t.        $ r t        j                  d       Y y w xY w# t0        $ r)}	t        j                  dt3        |	             Y d }	~	y d }	~	ww xY w)Nr   zResponse status: %rzResponse headers:r   zResponse content:zattachment; ?filename=["\w.]+zcontent-dispositionzcontent-type =   zFile attachments: %szoctet-streamzBody contains binary data.imagezBody contains image data.textzBody is streamablezFailed to log response: %s)rI   r`   r   r   r   r   r   r   rA   rB   rK   r   recompile
IGNORECASErJ   match	partitionendswith
startswithr   r   rO   r   r   repr)
rb   rc   rD   
res_headerr   patternr   resp_content_typefilenamer   s
             r)   on_responsez StorageLoggingPolicy.on_response   s    0$2I2IJ''6G3X5K5K5W5WX12)1)?)?)G)G)M)M)O C%JMM,
EBC 12**%Er}}U!//77;;<QR$,$:$:$B$B$F$F~WY$Z!gmmF3%//4Q7HMM"8(C&//?MM">?&11':MM"=>$$):)E)Ef)MMM("8"8"="="?@&&<h&<&<&A&A&CD '5 K: & <&:;<  G:DIFFGs=   GJ
 )J
 6-I& &JJ
 JJ
 
	J<J77J<)Frt   rc   r   rD   r   ru   N)	rf   rg   rh   __doc__boolr~   re   r   rw   rx   s   @r)   r   r      s+    
\t \$ \&@P"Gr+   r   c                   &     e Zd Z fdZddZ xZS )StorageRequestHookc                 V    |j                  d      | _        t        t        |           y Nraw_request_hook)rJ   _request_callbackrn   r   r~   rb   r>   rs   s     r)   r~   zStorageRequestHook.__init__  s#    !',>!? $02r+   c                 z    |j                   j                  j                  d| j                        }|r	 ||       y y r   )rI   r_   r`   r   )rb   rc   request_callbacks      r)   re   zStorageRequestHook.on_request  s6    "??22667I4KaKabW% r+   rt   r   rx   s   @r)   r   r     s    3&r+   r   c                   &     e Zd Z fdZddZ xZS )StorageResponseHookc                 V    |j                  d      | _        t        t        |           y )Nraw_response_hook)rJ   _response_callbackrn   r   r~   r   s     r)   r~   zStorageResponseHook.__init__  s#    "(**-@"A!413r+   c                 l   |j                   j                  d      }|&|j                   j                  j                  dd       }|j                   j                  d      }|&|j                   j                  j                  dd       }|j                   j                  d      }|&|j                   j                  j                  dd       }|j                   j                  d      xs0 |j                   j                  j                  d| j                        }| j
                  j                  |      }t        ||j                   j                  j                  d            xs t        |      }|j                  j                  dk(  }|xs | }	|	r||t        |j                  j                  j                  dd	            z  }||j                  j                  j                  d
      }
|
r2t        |
j                  dd      d   j                  dd      d         }n9|}n6|	r4|2|t        |j                  j                  j                  dd	            z  }||fD ]<  }t        |d      s||j                   d<   ||j                   d<   ||j                   d<   > |r ||       ||j                   d<   |S )Ndata_stream_totaldownload_stream_currentupload_stream_currentresponse_callbackr   r:   i  zContent-Lengthr   zContent-Range r   rS   rI   )rI   rJ   r_   r`   r   nextsendrE   rQ   rA   rB   intrK   splitrL   hasattr)rb   rc   r   r   r   r   rD   
will_retryis_auth_errorshould_update_countscontent_rangepipeline_objs               r)   r   zStorageResponseHook.send  s   #OO//0CD$ ' 7 7 ; ;<OQU V")//"5"56O"P"*&-oo&=&=&A&AB[]a&b# ' 3 34K L ($+OO$;$;$?$?@WY]$^!#OO//0CD VOO##''(;T=T=TU 	 99>>'*h(?(?(C(CF(KLkPabjPk
 ..::cA$.$?-@$;$G#s8+A+A+I+I+M+MN^`a+b'cc# ( ( 6 6 > > B B? S (+M,?,?Q,G,J,P,PQTVW,XYZ,[(\%(?%!&;&G!S)>)>)F)F)J)JK[]^)_%``!$h/ 	VL|Y/<M$$%89BY$$%>?@U$$%<=		V
 h'3DGOO/0r+   )rc   r   ru   r   )rf   rg   rh   r~   r   rw   rx   s   @r)   r   r     s    4(r+   r   c                   P     e Zd ZdZdZdeddf fdZed        Zd
dZ	dd	Z
 xZS )rM   zA simple policy that sends the given headers
    with the request.

    This will overwrite any headers already defined in the request.
    zContent-MD5r>   ru   Nc                 *    t         t        |           y r|   )rn   rM   r~   r   s     r)   r~   z!StorageContentValidation.__init__Q  s    &68r+   c                      xs d t        j                         }t         t              r!|j	                          |j                         S t         d      r_d}	  j                         }t         fdd      D ]  }|j	                  |        	  j                  |t               |j                         S t        d      #  Y [xY w# t        t        f$ r}t        d      |d }~ww xY w)Nr+   r/   r   c                  &     j                  d      S )Ni   )r/   )r'   s   r)   <lambda>z:StorageContentValidation.get_content_md5.<locals>.<lambda>b  s    diio r+   z4Data should be bytes or a seekable file-like object.)hashlibmd5r!   bytesupdater   telliterseekr   AttributeErrorIOErrorr   digest)r'   r   poschunkexcs   `    r)   rN   z(StorageContentValidation.get_content_md5T  s     {skkmdE"JJt  zz| T6"Ciik 5s; "

5!"b		#x( zz| STT
 #G, b !WX^aabs$   C C
 C
C*C%%C*c                 l   |j                   j                  j                  dd      }|r}|j                  j                  dk7  rdt        t        j                  |j                  j                              }||j                  j                  | j                  <   ||j                   d<   ||j                   d<   y )NrG   FGETvalidate_content_md5)rI   r_   r`   rL   r   r*   rM   rN   r'   rK   header_name)rb   rc   rG   rP   s       r)   re   z#StorageContentValidation.on_requestm  s    "??22667I5Q 4 4 ; ;u D()A)Q)QRYRfRfRkRk)lmL=IG  (()9)9:6BGOO23.>*+r+   c                    |j                   j                  dd      r|j                  j                  j                  d      r|j                   j                  d      xs6 t	        t
        j                  |j                  j                                     }|j                  j                  d   |k7  r5t        d|j                  j                  d    d| d|j                        y y y )	NrG   FrH   r   z!MD5 mismatch. Expected value is 'z', computed value is 'z'.)rD   )	rI   rJ   rA   rK   r*   rM   rN   rO   r   )rb   rc   rD   rP   s       r)   r   z$StorageContentValidation.on_responseu  s     2E:x?U?U?]?]?a?abo?p"??../EF g6FFxG]G]GbGbGdef %%--m<L 78N8N8V8VWd8e7f g**6r;%33  M @q:r+   rt   r   )rf   rg   rh   r   r   r   r~   staticmethodrN   re   r   rw   rx   s   @r)   rM   rM   I  s@    
  K9 9 9  0?	r+   rM   c                        e Zd ZU dZeed<   	 eed<   	 eed<   	 eed<   	 eed<   	 dedd	f fd
Zde	e
ef   dddd	fdZddde	e
ef   fdZde	e
ef   defdZd Z	 	 dde	e
ef   ddded   dee   def
dZd Z xZS )StorageRetryPolicyzS
    The base class for Exponential and Linear retries containing shared code.
    total_retriesconnect_retries
retry_readretry_statusr   r>   ru   Nc                    |j                  dd      | _        |j                  dd      | _        |j                  dd      | _        |j                  dd      | _        |j                  dd      | _        t        t        | #          y )	Nretry_total
   retry_connect   r   r   r   F)	r`   r   r   read_retriesstatus_retriesr   rn   r   r~   r   s     r)   r~   zStorageRetryPolicy.__init__  sq    #ZZr:%zz/1="JJ|Q7$jj;"(**-A5"I $02r+   r4   rc   r   c                 f   |d   rt        |d   j                               rt        |j                        }|d   t        j
                  k(  rt        j                  |d<   nt        j
                  |d<   |j                  |d   j                  |d               }|j                         |_        yyy)a  
        A function which sets the next host location on the request, if applicable.

        :param Dict[str, Any]] settings: The configurable values pertaining to the next host location.
        :param PipelineRequest request: A pipeline request object.
        r}   r:   r   N)
allvaluesr   ra   r   r   rC   rU   rJ   rV   )rb   r4   rc   ra   r   s        r)   _set_next_host_locationz*StorageRetryPolicy._set_next_host_location  s     GXg%6%=%=%?!@7;;'C<#7#77#/#9#9 #/#7#7 ll(7*;*?*?@P*QlRG!..*GK "Ar+   c                    d }t        |j                  j                  d      r%	 |j                  j                  j                         }|j                  j                  }|j                  d| j                        |j                  d| j                        |j                  d| j                        |j                  d| j                        |j                  d| j                        |j                  dt        j                        |j                  dd       |j                  d	d       |d
g dS # t        t
        f$ r Y w xY w)Nr/   r   r   r   r   r   r<   r}   r?   r   )r-   r.   r/   r0   retry_secondaryr:   r}   r8   body_positionr9   history)r   rL   rO   r   r   r   rI   r_   r`   r   r   r   r  r   r   r   )rb   rc   r  r_   s       r)   configure_retriesz$StorageRetryPolicy.configure_retries  s   7'',,f5 ' 4 4 9 9 > > @ //))[[0B0BC{{?D4H4HIKKd.?.?@kk.$2E2EF&{{+?AXAXYKK1E1EF[[$/KKd3*
 	
	 #$89 s   $D, ,D>=D>c                      y)z Formula for computing the current backoff.
        Should be calculated by child class.

        :param Dict[str, Any] settings: The configurable values pertaining to the backoff time.
        :returns: The backoff time.
        :rtype: float
        r   r=   )rb   r4   s     r)   get_backoff_timez#StorageRetryPolicy.get_backoff_time  s     r+   c                 X    | j                  |      }|r|dk  ry |j                  |       y )Nr   )r  sleep)rb   r4   	transportbackoffs       r)   r  zStorageRetryPolicy.sleep  s*    ''1'A+ r+   rD   r   errorc                    |dxx   dz  cc<   |r=t        |t              r-|dxx   dz  cc<   |d   j                  t        ||             nm|r=t        |t              r-|dxx   dz  cc<   |d   j                  t        ||             n.|r,|dxx   dz  cc<   |d   j                  t        ||             t        |      s|j                  d	vr|d
   r| j                  ||       |j                  r@t        |j                  d      r*|d   y	 |j                  j                  |d   t               |dxx   dz  cc<   yy# t        t        f$ r Y yw xY w)a  Increment the retry counters.

        :param Dict[str, Any] settings: The configurable values pertaining to the increment operation.
        :param PipelineRequest request: A pipeline request object.
        :param Optional[PipelineResponse] response: A pipeline response object.
        :param Optional[AzureError] error: An error encountered during the request, or
            None if the response was received successfully.
        :returns: Whether the retry attempts are exhausted.
        :rtype: bool
        r-   r   r.   r	  )r  r/   r0   )rA   )PUTr  r  Fr9   T)r!   r   appendr   r   r6   r   r  rO   r   r   r   r   r   )rb   r4   rc   rD   r  s        r)   	incrementzStorageRetryPolicy.increment  sU     	QZ':; Y1$Y&&~gU'KLz%)=> V!Y&&~gU'KL
 "a'"#**>'QY+Z[H%~~W,:K1L,,Xw? ||f =O,4 !LL%%h&?J W" -j9 ! !s   #E EEc                    d}d }| j                  |      }|r	 | j                  j                  |      }t        ||d         st	        |      rt| j                  ||j                  |j                        }|rJt        ||j                  |j                  d        | j                  ||j                  j                         	 |d   r|d   |j                  d<   |d   |j                  _        |S # t        $ r}}t        |t              r | j                  ||j                  |      }|rEt        ||j                  d |       | j                  ||j                  j                         Y d }~Y|d }~ww xY w)NTr:   )rc   rD   )rc   rD   r  )rc   r  r	  )r
  r   r   rE   rQ   r  rL   rA   r?   r  rI   r  r   r!   r   r<   )rb   rc   retries_remainingrD   retry_settingsr   s         r)   r   zStorageRetryPolicy.send	  su    //899>>'2HnV&<=ARS[A\(,& ' 4 4!)!7!7 )7 )9% )"*$+$8$8%-%;%;"&	(
 

>7??3L3LM  )$*8*CHY'/=f/E,#  c#45$(NN"G,@,@ %3 %M!$& ' 4 4!%!	#
 JJ~w/H/HI	s   B(C0 0	E69A0E1/E11E6)NN)rf   rg   rh   r   r   __annotations__r   r   r~   r   r"   r  r
  floatr  r  r   r   r  r   rw   rx   s   @r)   r   r     s     $,O)+;3 3 3+S#X +IZ +_c +"
): 
tCH~ 
.c3h E ! 26&*	6S#X6"6 -.6 
#	6
 
6p&r+   r   c                        e Zd ZU dZeed<   	 eed<   	 eed<   	 	 	 	 	 	 ddededededededd	f fd
Zde	e
ef   defdZ xZS )ExponentialRetryzExponential retry.initial_backoffincrement_baserandom_jitter_ranger   r   r>   ru   Nc                 \    || _         || _        || _        t        t        |   d||d| y)a  
        Constructs an Exponential retry object. The initial_backoff is used for
        the first retry. Subsequent retries are retried after initial_backoff +
        increment_power^retry_count seconds.

        :param int initial_backoff:
            The initial backoff interval, in seconds, for the first retry.
        :param int increment_base:
            The base, in seconds, to increment the initial_backoff by after the
            first retry.
        :param int retry_total:
            The maximum number of retry attempts.
        :param bool retry_to_secondary:
            Whether the request should be retried to secondary, if able. This should
            only be enabled of RA-GRS accounts are used and potentially stale data
            can be handled.
        :param int random_jitter_range:
            A number in seconds which indicates a range to jitter/randomize for the back-off interval.
            For example, a random_jitter_range of 3 results in the back-off interval x to vary between x+3 and x-3.
        r   r   Nr=   )r  r  r  rn   r  r~   )rb   r  r  r   r   r  r>   rs   s          r)   r~   zExponentialRetry.__init__=  sC    8  /,#6 . 	V#8J	VNT	Vr+   r4   c                    t        j                         }| j                  |d   dk(  rdnt        | j                  |d         z   }|| j
                  kD  r|| j
                  z
  nd}|| j
                  z   }|j                  ||      S )aT  
        Calculates how long to sleep before retrying.

        :param Dict[str, Any]] settings: The configurable values pertaining to get backoff time.
        :returns:
            A float indicating how long to wait before retrying the request,
            or None to indicate no retry should be performed.
        :rtype: float
        r9   r   )randomRandomr  powr  r  uniform)rb   r4   random_generatorr  random_range_startrandom_range_ends         r)   r  z!ExponentialRetry.get_backoff_time_  s     "==?&&x/@A/E!3tObObdlmtduKvwCJTMeMeCeWt'?'??kl"T%=%==''(:<LMMr+   )   r   r   Fr   rf   rg   rh   r   r   r  r   r   r~   r   r"   r  r  rw   rx   s   @r)   r  r  2  s    Hd &(#(#$ V" V V  V !	 V
 ! V  V 
 VDNc3h NE Nr+   r  c                   z     e Zd ZU dZeed<   	 eed<   	 	 	 	 	 ddedededededd	f fd
Zde	e
ef   defdZ xZS )LinearRetryzLinear retry.r  r  r  r   r   r>   ru   Nc                 N    || _         || _        t        t        |   d||d| y)a  
        Constructs a Linear retry object.

        :param int backoff:
            The backoff interval, in seconds, between retries.
        :param int retry_total:
            The maximum number of retry attempts.
        :param bool retry_to_secondary:
            Whether the request should be retried to secondary, if able. This should
            only be enabled of RA-GRS accounts are used and potentially stale data
            can be handled.
        :param int random_jitter_range:
            A number in seconds which indicates a range to jitter/randomize for the back-off interval.
            For example, a random_jitter_range of 3 results in the back-off interval x to vary between x+3 and x-3.
        r!  Nr=   )r  r  rn   r-  r~   )rb   r  r   r   r  r>   rs   s         r)   r~   zLinearRetry.__init__x  s9    , #6 k4) 	V#8J	VNT	Vr+   r4   c                     t        j                         }| j                  | j                  kD  r| j                  | j                  z
  nd}| j                  | j                  z   }|j	                  ||      S )aT  
        Calculates how long to sleep before retrying.

        :param Dict[str, Any]] settings: The configurable values pertaining to the backoff time.
        :returns:
            A float indicating how long to wait before retrying the request,
            or None to indicate no retry should be performed.
        :rtype: float
        r   )r#  r$  r  r  r&  )rb   r4   r'  r(  r)  s        r)   r  zLinearRetry.get_backoff_time  sj     "==? ||d666 "\\D,D,DD<= 	<<$*B*BB''(:<LMMr+   )r*  r   Fr   r+  rx   s   @r)   r-  r-  p  s    <d  #(#$	VVV !V !	V
 V 
V6Nc3h NE Nr+   r-  c                   H     e Zd ZdZdddededdf fdZd	d
dddefdZ xZ	S )"StorageBearerTokenCredentialPolicyzO Custom Bearer token credential policy for following Storage Bearer challenges 
credentialr   audiencer>   ru   Nc                 0    t        t        | 
  ||fi | y r|   )rn   r1  r~   )rb   r2  r3  r>   rs   s       r)   r~   z+StorageBearerTokenCredentialPolicy.__init__  s    0$@X`Y_`r+   rc   r   rD   r   c                     	 |j                   j                  j                  d      }t        |      }|j
                  t        z   }| j                  |||j                         y# t        $ r Y yw xY w)NzWWW-AuthenticateF)	tenant_idT)	rA   rK   rJ   r   r   resource_idr   authorize_requestr6  )rb   rc   rD   auth_header	challengescopes         r)   on_challengez/StorageBearerTokenCredentialPolicy.on_challenge  ss    	"0088<<=OPK,[9I %%(;;w9L9LM  		s   0A$ $	A0/A0)
rf   rg   rh   r   r"   r   r~   r   r<  rw   rx   s   @r)   r1  r1    sK    Ya#4 a as aW[ a
$5 
AS 
X\ 
r+   r1  )Ar$   r   r   r#  r   ro   ior   r   r   typingr   r   r   r	   urllib.parser
   r   r   r   wsgiref.handlersr   azure.core.exceptionsr   r   r   azure.core.pipeline.policiesr   r   r   r   r   r   authenticationr   r   	constantsr   modelsr   azure.core.credentialsr   azure.core.pipeline.transportr   r   	getLoggerrf   r   r*   r6   r?   rE   rQ   rZ   r\   rj   rz   r   r   r   rM   r   r  r-  r1  r=   r+   r)   <module>rI     s/       	  -  5 5  . W W  D *  6 '

H
%#!f*) 	`= 	`6A# A@TG4 TGn	&) 	&.* .b5/ 5pn nb;N) ;N|3N$ 3Nl)D r+   