
    6i~                     F   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'm(Z( erd dl)m*Z* d dl+m,Z,m-Z-  ej\                  e/      Z0d Z1d Z2d Z3d Z4d Z5d 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@ G d) d*e      ZAy)+    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StorageErrorCode)TokenCredential)PipelineRequestPipelineResponsec                     t        | t              r| j                  d      } t        j                  |       }|j                  d      S )Nzutf-8)
isinstancestrencodebase64	b64encodedecode)dataencodeds     f/home/azureuser/techstart-app/venv/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_exhaustedr7   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>   )r5   kwargss     r*   
retry_hookr@   A   s9    eXg%6%:(SYJZe^de r,   c                 Z   | j                   j                  }d|cxk  rdk  rn n||dk(  r|t        j                  k(  ry|dk(  ry|dk\  rW| j                   j                  j                  d      }|t        j                  t        j                  t        j                  fv ryy|dk\  r|d	v ryyy)
Ni,  i  i  Ti  i  zx-ms-copy-source-error-codeF)i  i  )
http_responsestatus_coder   	SECONDARYheadersgetr   OPERATION_TIMED_OUTINTERNAL_ERRORSERVER_BUSY)responser;   r1   
error_codes       r*   is_retryrL   K   s    ##//F
fs S=T\%;%;;S=S=!//77;;<YZJ 44 // ,, 
 } 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)	contextrF   rB   rE   http_requestr+   StorageContentValidationget_content_md5body)rJ   computed_md5s     r*   is_checksum_retryrV   h   s    .68;Q;Q;Y;Y;];]^k;l,,4488M 
Q^$44X5K5K5P5P5RSR
 !!))-8LHr,   c                 |    t        |       }|j                  |j                  dz   |z         }|j                         S )N/)path)r   _replacerY   geturl)base_urlstub_urlparseds      r*   urljoinr_   s   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)rP   optionspopr_   rQ   url)selfrequest
message_ids      r*   
on_requestzQueueMessagePolicy.on_request{   sH    __,,001CTJ
'.w/C/C/G/G'TG  $ r,   N)__name__
__module____qualname__rj   r>   r,   r*   ra   ra   y   s    Ur,   ra   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_idrp   )superro   rj   r   r   rQ   rE   rP   rd   re   r#   uuiduuid1)rg   rh   current_time	custom_id	__class__s       r*   rj   zStorageHeadersPolicy.on_request   s}    "D4W='/4@$$[1OO++//0CTJ	AJA_cRVR\R\R^N_$$%=>r,   rh   r   returnN)rk   rl   rm   request_id_header_namerj   __classcell__rx   s   @r*   ro   ro      s    5` `r,   ro   c                   (     e Zd Zd fd	ZddZ xZS )StorageHostsc                 8    || _         t        t        |           y N)hostsrs   r   __init__)rg   r   r?   rx   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   rP   rd   r   rQ   rf   r   PRIMARYitemsr   re   
ValueErrorrZ   r[   )rg   rh   
parsed_urlr=   keyvaluer   updateds           r*   rj   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   ry   rk   rl   rm   r   rj   r|   r}   s   @r*   r   r      s    -Ar,   r   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_enablerz   Nc                 ^    |j                  dd      | _        t        t        |   dd|i| y )Nlogging_bodyFr   r>   )re   r   rs   r   r   )rg   r   r?   rx   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)rQ   rP   rd   r   re   enable_http_logger_LOGGERisEnabledForloggingDEBUGrf   queryreplacedebugmethodrE   r   lowerr   dictr
   r   r   r#   rT   	Exception)rg   rh   rQ   rd   log_urlquery_paramsheaderr   schemer   rY   paramsr   fragment	parsed_qserrs                   r*   rj   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)rP   re   r   r   r   r   r   r   rB   rC   rE   r   recompile
IGNORECASErF   match	partitionendswith
startswithr   r   rT   r   r   repr)
rg   rh   rJ   
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<)Fry   rh   r   rJ   r    rz   N)	rk   rl   rm   __doc__boolr   rj   r   r|   r}   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)rF   _request_callbackrs   r   r   rg   r?   rx   s     r*   r   zStorageRequestHook.__init__  s#    !',>!? $02r,   c                 z    |j                   j                  j                  d| j                        }|r	 ||       y y r   )rP   rd   re   r   )rg   rh   request_callbacks      r*   rj   zStorageRequestHook.on_request  s6    "??22667I4KaKabW% r,   ry   r   r}   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)rF   _response_callbackrs   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   rX   rP   )rP   rF   rd   re   r   nextsendrL   rV   rB   rC   intrE   splitrQ   hasattr)rg   rh   r   r   r   r   rJ   
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 
H_H_HcHc!8!8I
 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,   )rh   r   rz   r    )rk   rl   rm   r   r   r|   r}   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 )rR   zA simple policy that sends the given headers
    with the request.

    This will overwrite any headers already defined in the request.
    zContent-MD5r?   rz   Nc                 *    t         t        |           y r   )rs   rR   r   r   s     r*   r   z!StorageContentValidation.__init__Z  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,   r0   r   c                  &     j                  d      S )Ni   )r0   )r(   s   r*   <lambda>z:StorageContentValidation.get_content_md5.<locals>.<lambda>k  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*   rS   z(StorageContentValidation.get_content_md5]  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 )NrN   FGETvalidate_content_md5)rP   rd   re   rQ   r   r+   rR   rS   r(   rE   header_name)rg   rh   rN   rU   s       r*   rj   z#StorageContentValidation.on_requestv  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 )	NrN   FrO   r   z!MD5 mismatch. Expected value is 'z', computed value is 'z'.)rJ   )	rP   rF   rB   rE   r+   rR   rS   rT   r   )rg   rh   rJ   rU   s       r*   r   z$StorageContentValidation.on_response~  s     2E:x?U?U?]?]?a?abo?p"??../EF -(889O9O9T9T9VWKL %%--m<L ;H<R<R<Z<Z[h<i;j k..:^2? &33  M	 @q:r,   ry   r   )rk   rl   rm   r   r   r   r   staticmethodrS   rj   r   r|   r}   s   @r*   rR   rR   Q  s@      K9 9 9  0?r,   rR   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?   rz   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)	re   r   r   read_retriesstatus_retriesr   rs   r   r   r   s     r*   r   zStorageRetryPolicy.__init__  sq    #ZZr:%zz/1="JJ|Q7$jj;"(**-A5"I $02r,   r5   rh   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   rf   r   r   rD   rZ   rF   r[   )rg   r5   rh   rf   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)a  
        Configure the retry settings for the request.
        
        :param request: A pipeline request object.
        :type request: ~azure.core.pipeline.PipelineRequest
        :return: A dictionary containing the retry settings.
        :rtype: Dict[str, Any]
        Nr0   r  r  r   r   r   r=   r   r@   r   )r.   r/   r0   r1   retry_secondaryr;   r   r9   body_positionr:   history)r   rQ   rT   r   r   r   rP   rd   re   r   r   r  r  r   r   r   )rg   rh   r  rd   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)zFormula for computing the current backoff.
        Should be calculated by child class.

        :param Dict[str, Any] settings: The configurable values pertaining to the backoff time.
        :return: The backoff time.
        :rtype: float
        r   r>   )rg   r5   s     r*   get_backoff_timez#StorageRetryPolicy.get_backoff_time  s     r,   c                 X    | j                  |      }|r|dk  ry|j                  |       y)ab  Sleep for the backoff time.
        
        :param Dict[str, Any] settings: The configurable values pertaining to the sleep operation.
        :param transport: The transport to use for sleeping.
        :type transport:
            ~azure.core.pipeline.transport.AsyncioBaseTransport or
            ~azure.core.pipeline.transport.BaseTransport
        r   N)r  sleep)rg   r5   	transportbackoffs       r*   r  zStorageRetryPolicy.sleep  s,     ''1'A+ r,   rJ   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 request: A pipeline request object.
        :type request: ~azure.core.pipeline.PipelineRequest
        :param response: A pipeline response object.
        :type response: ~azure.core.pipeline.PipelineResponse or None
        :param error: An error encountered during the request, or
            None if the response was received successfully.
        :type error: ~azure.core.exceptions.AzureError or None
        :return: Whether the retry attempts are exhausted.
        :rtype: bool
        r.   r   r/   r  )r  r0   r1   )rB   )PUTr  r  Fr:   T)r"   r   appendr   r   r7   r   r
  rT   r   r   r   r   r   )rg   r5   rh   rJ   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)a  Send the request with retry logic.
        
        :param request: A pipeline request object.
        :type request: ~azure.core.pipeline.PipelineRequest
        :return: A pipeline response object.
        :rtype: ~azure.core.pipeline.PipelineResponse
        TNr;   )rh   rJ   )rh   rJ   r  )rh   r  r  )r  r   r   rL   rV   r  rQ   rB   r@   r  rP   r  r   r"   r   r=   )rg   rh   retries_remainingrJ   retry_settingsr   s         r*   r   zStorageRetryPolicy.send)  sh    !//899>>'2HnV&<=ARS[A\(,&0D0DxOeOe )7 )% )"*G4H4HS[SiSiqu 

>7??3L3LM  )$*8*CHY'/=f/E,  c#45$(NN>7K_K_gjN$k!$~w7K7KVZbefJJ~w/H/HI	s   B(C0 0	E69A0E1/E11E6)NN)rk   rl   rm   r   r   __annotations__r   r   r   r   r#   r
  r  floatr  r  r   r   r  r   r|   r}   s   @r*   r   r     s     $,O)+;3 3 3+S#X +IZ +_c +"
): 
tCH~ 
>c3h E !$ 26&*:sCx.: #: -.	:
 
#: 
:x%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?   rz   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$  rs   r!  r   )rg   r"  r#  r  r   r$  r?   rx   s          r*   r   zExponentialRetry.__init__\  s9    :  /,#6 .x;[mxqwxr,   r5   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 )aR  
        Calculates how long to sleep before retrying.

        :param Dict[str, Any] settings: The configurable values pertaining to get backoff time.
        :return:
            A float indicating how long to wait before retrying the request,
            or None to indicate no retry should be performed.
        :rtype: float
        r:   r   )randomRandomr"  powr#  r$  uniform)rg   r5   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  rk   rl   rm   r   r   r  r   r   r   r   r#   r  r  r|   r}   s   @r*   r!  r!  Q  s    Hd  "#(#$ y y  y 	 y
 ! y ! y  y 
 y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?   rz   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$  rs   r2  r   )rg   r  r  r   r$  r?   rx   s         r*   r   zLinearRetry.__init__  s/    . #6 k4)skVhslrsr,   r5   c                     t        j                         }| j                  | j                  kD  r| j                  | j                  z
  nd}| j                  | j                  z   }|j	                  ||      S )aR  
        Calculates how long to sleep before retrying.

        :param Dict[str, Any] settings: The configurable values pertaining to the backoff time.
        :return:
            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+  )rg   r5   r,  r-  r.  s        r*   r  zLinearRetry.get_backoff_time  sh     "==? IMW[WoWoHoT\\D,D,DDuv<<$*B*BB''(:<LMMr,   )r/  r  Fr  r0  r}   s   @r*   r2  r2    s    <d #(#$tt t !	t
 !t t 
t6Nc3h NE Nr,   r2  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 )"StorageBearerTokenCredentialPolicyzMCustom Bearer token credential policy for following Storage Bearer challenges
credentialr   audiencer?   rz   Nc                 0    t        t        | 
  ||fi | y r   )rs   r6  r   )rg   r7  r8  r?   rx   s       r*   r   z+StorageBearerTokenCredentialPolicy.__init__  s    0$@X`Y_`r,   rh   r   rJ   r    c                     	 |j                   j                  j                  d      }t        |      }|j
                  t        z   }| j                  |||j                         y# t        $ r Y yw xY w)a  Handle the challenge from the service and authorize the request.
        
        :param request: The request object.
        :type request: ~azure.core.pipeline.PipelineRequest
        :param response: The response object.
        :type response: ~azure.core.pipeline.PipelineResponse        
        :return: True if the request was authorized, False otherwise.
        :rtype: bool
        zWWW-AuthenticateF)	tenant_idT)	rB   rE   rF   r   r   resource_idr   authorize_requestr;  )rg   rh   rJ   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)
rk   rl   rm   r   r#   r   r   r   rA  r|   r}   s   @r*   r6  r6    sK    Wa#4 a as aW[ a$5 AS X\ r,   r6  )Br%   r   r   r(  r   rt   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   r   azure.core.credentialsr   azure.core.pipeline.transportr   r    	getLoggerrk   r   r+   r7   r@   rL   rV   r_   ra   ro   r   r   r   r   rR   r   r!  r2  r6  r>   r,   r*   <module>rN     s1       	  -  5 5  . W W  D * 26 '

H
%#!f:U) U	`= 	`6A# A@TG4 TGn	&) 	&/* /d9/ 9xA AH;N) ;N|2N$ 2Nj)D r,   