
    q(                       d dl mZ 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	Z	d dl
Z
d dlZd dlmZ d dlmZ d dlmZmZ d dlmZ d dlmZmZ d dlZ	 	 d dlZ	 d dlZdZd d
lm Z  d dl!m"Z" d dl#m$Z$ d dl%m&Z& 	 d dl'm(c m)Z) e
jT                  rd dl+Z+ e
jX                  d      Z- e
jX                  de
j\                  de
j^                  f         Z0 ejb                         dk(  rdZ2ndZ2ddgZ3ddgZ4dZ5dZ6ejn                  jq                  d      sejn                  jq                  d      dk(  rdZ6 e"d      Z9d7d Z:d8d9d!Z; e:d"      Z<e$fd:d#Z=d;d$Z>d<d%Z?d<d&Z@d<d'ZAd<d(ZBd<d)ZCdaDd<d*ZEd<d+ZFd=d,ZG G d- d.ej                        ZI G d/ d0      ZJ G d1 d2e      ZK G d3 d4e      ZL G d5 d6e      ZMy# e$ r d dlZY jw xY w# e$ r dZY xw xY w# e$ r d	ZY w xY w# e$ r dZ)Y kw xY w)>    )annotationsN)Sequencewraps)LoaderMetaPathFinder)
ModuleSpec)
ModuleTypeTracebackTypeTF)util)ConnectionPool)HTTPWarning)ssl__RT
_TestFuncT.)boundWindowsz	127.0.0.0z	240.0.0.0))z::1r   T))z	127.0.0.1r   F))z192.0.2.255r   F))z2001:db8::1r   TgMbP?g?CIGITHUB_ACTIONStrueg      ?dummyc                    	 t        j                  | dt         j                         y# t         j                  $ r Y yw xY w)z:Returns True if the system can resolve host to an address.NTF)socketgetaddrinfo	AF_UNSPECgaierror)hosts    4platform/gsutil/third_party/urllib3/test/__init__.py_can_resolver   T   s8    4v'7'78?? s   %( >>c                    | xs t         j                  }  | t        j                        }	 t	        |d      r |j                  t        j                         y	 y# t        $ r Y yw xY w)z"Detect if ALPN support is enabled.)protocolset_alpn_protocolsTF)r   
SSLContextr   PROTOCOL_TLShasattrr"   ALPN_PROTOCOLSNotImplementedError)ctx_clsctxs     r   has_alpnr*   ]   sh    (G
4,,
-C3,-""4#6#67 .
   s   +A 	A'&A'z
localhost.c                    g }t         j                  D ]#  }t        |d   |       r|j                  |       % |t         j                  d d  y )N   )warningsfilters
issubclassappend)clsnew_filtersfs      r   clear_warningsr4   p   sH    KadC 1  &HQ    c                 L    t                t        j                  dt               y )Nignore)r4   r-   simplefilterr    r5   r   setUpr:   y   s    (K0r5   c                 n    t         j                  j                  t        j                         dk(  d      S )zSkips this test on Windowsr   zTest does not run on Windowsreason)pytestmarkskipifplatformsystemr9   r5   r   
notWindowsrC   ~   s0    ;;Y&-   r5   c                 P    t         j                  j                  t        d u d      S )Nz%only run if brotli library is presentr<   r>   r?   r@   brotlir9   r5   r   
onlyBrotlirG      s(    ;;$F   r5   c                 P    t         j                  j                  t        d ud      S )Nz&only run if a brotli library is absentr<   rE   r9   r5   r   	notBrotlirI      s)    ;;d#K   r5   c                 N    t         j                  j                  t         d      S )Nz3only run if a python-zstandard library is installedr<   r>   r?   r@   HAS_ZSTDr9   r5   r   onlyZstdrM      s&    ;;R   r5   c                 L    t         j                  j                  t        d      S )Nz7only run if a python-zstandard library is not installedr<   rK   r9   r5   r   notZstdrO      s$    ;;H   r5   c                 F    dddfddfd} 	 	 	 	 dd} ||       S )	z-Helps you skip tests that require the networkc                \    t        | dd       t        j                  t        j                  fv S )Nerrno)getattrrR   ENETUNREACHEHOSTUNREACH)errs    r   _is_unreachable_errz-requires_network.<locals>._is_unreachable_err   s/    sGT*/
 
 	
r5   c                     	 t        j                  t        dfd      } | j                          y# t         j                  $ r Y yt
        $ r} |      rY d }~y d }~ww xY w)NP   g-C6?TF)r   create_connectionTARPIT_HOSTclosetimeoutOSError)sockerW   s     r   
_has_routez$requires_network.<locals>._has_route   sX    
	++[",=vFDJJL~~ 	 	"1%		s!   ,0 A A AAA c                d     t               d fd       }t        j                  t        |      S )z,Skip test exuction if network is unreachablec                 d    t                 a t         st        j                  d        | i |S )Nz5Can't run the test because the network is unreachable)_requires_network_has_router>   skip)argskwargsra   r3   s     r   wrapperz<requires_network.<locals>._skip_if_no_route.<locals>.wrapper   s3     +2.8l+.STd%f%%r5   )rf   
typing.Anyrg   ri   returnri   )r   typingcastr   )r3   rh   ra   s   ` r   _skip_if_no_routez+requires_network.<locals>._skip_if_no_route   s.     
q	& 
	& {{:w//r5   c                     d fd}|S )z2Mark a decorator with the "requires_internet" markc                N    t         j                  j                   |             S N)r>   r?   requires_network)r3   	decorators    r   rh   zGrequires_network.<locals>._decorator_requires_internet.<locals>.wrapper   s    ;;//	!==r5   )r3   r   rj   ri   r9   )rr   rh   s   ` r   _decorator_requires_internetz6requires_network.<locals>._decorator_requires_internet   s    
	> r5   )rV   	Exceptionrj   bool)rj   ru   )r3   r   rj   r   )rr   )typing.Callable[[_TestFuncT], _TestFuncT]rj   rv   r9   )rm   rs   ra   rW   s     @@r   rq   rq      s5    
0<	2 ((9::r5   c                 N    t         j                  j                  t         d      S )z2Test requires successful resolving of 'localhost.'zCan't resolve localhost.r<   )r>   r?   r@   RESOLVES_LOCALHOST_FQDNr9   r5   r   resolvesLocalhostFQDNry      s'    ;;##)   r5   c                0     t               d fd       }|S )Nc                     t         st        j                  d        | i |S t        j                           | i |}t        j                          |S )Nz'pyopenssl not available, skipping test.)	pyopensslr>   re   inject_into_urllib3extract_from_urllib3)rf   rg   resulttests      r   rh   zwithPyOpenSSL.<locals>.wrapper   sO    KKAB(((%%'t&v&&&(r5   )rf   ri   rg   ri   rj   r   r   )r   rh   s   ` r   withPyOpenSSLr      s     
4[  Nr5   c                  (     e Zd Zd fdZddZ xZS )_ListHandlerc                0    t         |           g | _        y rp   )super__init__records)self	__class__s    r   r   z_ListHandler.__init__   s    02r5   c                :    | j                   j                  |       y rp   )r   r0   )r   records     r   emitz_ListHandler.emit   s    F#r5   rj   None)r   zlogging.LogRecordrj   r   )__name__
__module____qualname__r   r   __classcell__r   s   @r   r   r      s    3$r5   r   c                  z     e Zd Zej                  fd fdZedd       Zd	dZd	dZ	ddZ
	 	 	 	 	 	 	 	 d
dZ xZS )LogRecorderc                N    t         |           || _        t               | _        y rp   )r   r   _targetr   _handler)r   targetr   s     r   r   zLogRecorder.__init__   s    $r5   c                .    | j                   j                  S rp   )r   r   r   s    r   r   zLogRecorder.records   s    }}$$$r5   c                N    | j                   j                  | j                         y rp   )r   
addHandlerr   r   s    r   installzLogRecorder.install   s    .r5   c                N    | j                   j                  | j                         y rp   )r   removeHandlerr   r   s    r   	uninstallzLogRecorder.uninstall   s    ""4==1r5   c                :    | j                          | j                  S rp   )r   r   r   s    r   	__enter__zLogRecorder.__enter__  s    ||r5   c                $    | j                          y)NF)r   )r   exc_type	exc_value	tracebacks       r   __exit__zLogRecorder.__exit__  s     	r5   )r   zlogging.Loggerrj   r   )rj   zlist[logging.LogRecord]r   )r   ztype[BaseException] | Noner   zBaseException | Noner   zTracebackType | Nonerj   ztyping.Literal[False])r   r   r   loggingrootr   propertyr   r   r   r   r   r   r   s   @r   r   r      s]    07 '
 % %/2, ( (	
 
r5   r   c                  $    e Zd ZddZddZddZy)ImportBlockerLoaderc                    || _         y rp   )	_fullnamer   fullnames     r   r   zImportBlockerLoader.__init__  s	    !r5   c                     t        d| d      Nz
import of z is blocked)ImportErrorr   s     r   load_modulezImportBlockerLoader.load_module  s    Jxj<==r5   c                4    t        d| j                   d      r   )r   r   r   modules     r   exec_modulezImportBlockerLoader.exec_module  s    Jt~~&6kBCCr5   N)r   strrj   r   )r   r   rj   r
   )r   r
   rj   r   )r   r   r   r   r   r   r9   r5   r   r   r     s    ">Dr5   r   c                  H    e Zd ZdZddZ	 d	 	 	 	 	 ddZ	 d	 	 	 	 	 	 	 d	dZy)
ImportBlockerz
    Block Imports

    To be placed on ``sys.meta_path``. This ensures that the modules
    specified cannot be imported, even if they are a builtin.
    c                    || _         y rp   )namestoblock)r   r   s     r   r   zImportBlocker.__init__$  s
    (r5   Nc                6    || j                   v rt        |      S y rp   )r   r   )r   r   paths      r   find_modulezImportBlocker.find_module'  s      t(((&x00r5   c                l    | j                  ||      }|y t        j                  j                  ||      S rp   )r   	importlibr   spec_from_loader)r   r   r   r   loaders        r   	find_speczImportBlocker.find_spec.  s5     !!(D1>~~..x@@r5   )r   r   rj   r   rp   )r   r   r   z#typing.Sequence[bytes | str] | Nonerj   zLoader | None)r   r   r   zSequence[bytes | str] | Noner   zModuleType | Nonerj   zModuleSpec | None)r   r   r   __doc__r   r   r   r9   r5   r   r   r     se    ) JN#F	 %)	
A
A +
A "	
A
 

Ar5   r   c                  J    e Zd ZdZej
                  f	 	 	 	 	 ddZddZddZy)ModuleStashz
    Stashes away previously imported modules

    If we reimport a module the data from coverage is lost, so we reuse the old
    modules
    c                .    || _         || _        i | _        y rp   )	namespacemodules_data)r   r   r   s      r   r   zModuleStash.__init__C  s     #,.
r5   c                   | j                   | j                  v r<| j                  j                  | j                         | j                  | j                   <   t	        | j                  j                               D ]I  }|j                  | j                   dz         s"| j                  j                  |      | j                  |<   K y N.)r   r   popr   listkeys
startswithr   s     r   stashzModuleStash.stashJ  s    >>T\\))-)9)9$..)IDJJt~~&4<<,,./F  #!56%)\\%5%5f%=

6" 0r5   c                ^   | j                   j                  | j                  d        t        | j                   j	                               D ]<  }|j                  | j                  dz         s"| j                   j                  |       > | j                   j                  | j                         y r   )r   r   r   r   r   r   updater   r   s     r   r   zModuleStash.popR  sw    .4<<,,./F  #!56  ( 0 	DJJ'r5   N)r   r   r   zdict[str, ModuleType]rj   r   r   )	r   r   r   r   sysr   r   r   r   r9   r5   r   r   r   ;  s9     @C{{//'</	/>(r5   r   )r   r   rj   ru   rp   )r(   ztype[ssl.SSLContext] | Nonerj   ru   )r1   ztype[Warning]rj   r   r   )rj   rv   )r   typing.Callable[..., _RT]rj   r   )N
__future__r   rR   importlib.utilr   r   osrA   r   r   rk   r-   collections.abcr   	functoolsr   importlib.abcr   r   importlib.machineryr	   typesr
   r   r>   
brotlicffirF   r   	zstandard_unused_module_zstdrL   urllib3r   urllib3.connectionpoolr   urllib3.exceptionsr   urllib3.utilr   urllib3.contrib.pyopensslcontribr|   TYPE_CHECKINGsslTypeVarr   CallableAnyr   rB   r[   VALID_SOURCE_ADDRESSESINVALID_SOURCE_ADDRESSESSHORT_TIMEOUTLONG_TIMEOUTenvironget
DUMMY_POOLr   r*   rx   r4   r:   rC   rG   rI   rM   rO   rd   rq   ry   r   Handlerr   r   r   r   r   r9   r5   r   <module>r      s   "    	   
   $  0 * + #+ H  1 * 11 
 fnnUV^^LVZZ0PQ

 8??	!K K -.GH  89ST  ::>>$2::>>*:;vELG$

  '|4  )4 &1
 # .;b$7?? $ <D& DAN A>(. (I	   F
  H  IsN   F5 G 7	G! 5	G>G GG GGGG!G,+G,