
                           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	m
Z
 d dlmZmZ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 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& d dl'm(Z(m)Z)m*Z* d dl+m,Z, d dl-m.Z.m/Z/m0Z0 d dl1m2Z2 d dl3m4Z4m5Z5m6Z6m7Z7m8Z8 d dl9m:Z:m;Z; d dl<m=Z=m>Z>m?Z? d dl@mAZAmBZB ddlCmDZD dZE G d d      ZF G d d      ZG ed      ZH ed      ZI G d d      ZJy)    )annotationsN)chain)ImportBlockerModuleStash	notBrotlinotZstd
onlyBrotlionlyZstd)mock)	MagicMockMockpatch)urlparse)add_stderr_loggerdisable_warnings)ProxyConfig)InsecureRequestWarningLocationParseErrorTimeoutStateErrorUnrewindableBodyErroris_fp_closed)	_has_ipv6allowed_gai_familycreate_connectionconnection_requires_http_tunnel)_FAILEDTELLmake_headersrewind_body)assert_header_parsing)_TYPE_VERSION_INFO(_is_has_never_check_common_name_reliableresolve_cert_reqsresolve_ssl_versionssl_wrap_socket)_DEFAULT_TIMEOUTTimeout)Url_encode_invalid_chars	parse_url)to_bytesto_str   )clear_warningsi  c                  &   e Zd ZU g dZej
                  j                  ddge      	 	 	 	 	 	 dd       ZddZej
                  j                  dg d      dd       Z	ej
                  j                  dg d	      	 	 	 	 	 	 dd
       Z
ej
                  j                  d edd      D  cg c]  }t        |       c}}} dgz         d d       Zd eddd      fd eddd      fd eddd      fd edd      fd eddd      fd edd      fd edddd       fd e       fd ed!      fd" edd#$      fd% ed%!      fd& ed%d'(      fd) ed%d'd*+      fd, ed-d.(      fd eddd      fd/ eddd0d1      fd2 eddd03      fd4 edd5d6d7      fd8 eddd6d7      fd4 edd5d6d7      fgZd9 edd(      fd: edd$      fd; ed<!      fd= edd      fd> eddd      fd? edd@dA      fdB eddCdDd7      fdE eddFdDd7      fdG edddH      fdI eddddJ       fdK eddddLM      fgZej
                  j                  dN eee            ddP       Zej
                  j                  dNe      ddQ       Zej
                  j                  ddOgd; ed<!      fdR ed!      fdS edT!      fdU ed!      fdV ed!      fdW edX!      fg      ddY       ZddZZdd[Zdd\Zdd]Zdd^Zg d_Zej
                  j                  d`e      dda       Zg dbZdcedd<   g deZeez   ZeD  cg c]  }|d   jA                  d      s| c}} Z!ej
                  j                  dfe      ddg       Z"ej
                  j                  dfe!      	 	 	 	 	 	 ddh       Z#ej
                  j                  die      ddj       Z$dk eddddlM      fdm eddn      fdo edddp      fdq edrdst      fdu eddv      fdw eddxdydzd{d|}      fd~ edddd      fd eddddd      fd edddddd      f ejJ                  dddz  z   dz   dd       ejJ                  dddz  z   dDz    eddddz  z   dD      d      gZ&ej
                  j                  dNe&      	 	 	 	 	 	 dd       Z'ddZ(ej
                  j                  d ejJ                  ddiddi e)        e*       g       ejJ                  ddiddi e)        e+       g       ejJ                  ddiddi e,        e*       g       ejJ                  ddiddi e,        e+       g      ddiddifdddgiddif ejJ                  dddddd e)        e*       g       ejJ                  dddddd e)        e+       g       ejJ                  dddddd e,        e*       g       ejJ                  dddddd e,        e+       g      ddiddifddiddifdd5iddifdd5iddifddiddifg      	 	 	 	 	 	 dd       Z-ddZ.ddZ/ddZ0ddZ1ddZ2ddZ3	 	 	 	 	 	 	 	 ddZ4ej
                  j                  dddidfdddǜdfddidfddidfddidfddidfddidfddidfg      	 	 	 	 	 	 dd΄       Z5 e6dϫ      d	dЄ       Z7ddфZ8dd҄Z9 e6dϫ      d	dӄ       Z:ddԄZ;ddՄZ<ddքZ=ddׄZ>dd؄Z?ddلZ@ddڄZAddۄZBdd܄ZCej
                  j                  dddeDg      	 	 	 	 d
d       ZEddZFddZGddZHddZIej
                  j                  dg d      dd       ZJej
                  j                  dg d       e6d       e6d      	 	 	 	 	 	 	 	 dd                     ZK e6d      dd       ZL e6d      dd       ZMddZN e6d       e6d      	 	 	 	 	 	 dd              ZOej
                  j                  ddi dfdi dfdddidfdddidff      	 	 	 	 	 	 	 	 dd       ZPddZQej
                  j                  ddi dfdi dfdi dfdddidfdddidff      	 	 	 	 	 	 	 	 dd       ZRddZSyc c}}} w c c}} w (  TestUtil)-)http://google.com/mailhttp
google.comN)http://google.com/mail/r3   )google.com/mailr3   )http://google.com/r3   )http://google.comr3   )zhttp://www.google.com)r4   zwww.google.comN)zhttp://mail.google.com)r4   zmail.google.comN)zhttp://google.com:8000/mail/r4   r5   @  )zhttp://google.com:8000r:   )zhttps://google.com)httpsr5   N)zhttps://google.com:8000)r<   r5   r;   )z#http://user:password@127.0.0.1:1234)r4   	127.0.0.1  )z'http://google.com/foo=http://bar:42/bazr3   )z'http://google.com?foo=http://bar:42/bazr3   )z'http://google.com#foo=http://bar:42/bazr3   173.194.35.7r4   r@   N)zhttp://173.194.35.7rA   )zhttp://173.194.35.7/testrA   )zhttp://173.194.35.7:80r4   r@   P   )zhttp://173.194.35.7:80/testrB   )[2a00:1450:4001:c01::67]r4   rD   N)zhttp://[2a00:1450:4001:c01::67]rE   )z$http://[2a00:1450:4001:c01::67]/testrE   )z"http://[2a00:1450:4001:c01::67]:80r4   rD   rC   )z'http://[2a00:1450:4001:c01::67]:80/testrF   )z@http://[fedc:ba98:7654:3210:fedc:ba98:7654:3210]:8000/index.htmlr4   z)[fedc:ba98:7654:3210:fedc:ba98:7654:3210]r;   )z.http://[1080:0:0:0:8:800:200c:417a]/index.html)r4   [1080:0:0:0:8:800:200c:417a]N)zhttp://[3ffe:2a00:100:7031::1])r4   z[3ffe:2a00:100:7031::1]N)z"http://[1080::8:800:200c:417a]/foo)r4   z[1080::8:800:200c:417a]N)zhttp://[::192.9.5.5]/ipng)r4   z[::192.9.5.5]N)z+http://[::ffff:129.144.52.38]:42/index.html)r4   z[::ffff:129.144.52.38]*   )z"http://[2010:836b:4179::836b:4179])r4   z[2010:836b:4179::836b:4179]N)zhttp://[a::b%25zone]r4   z[a::b%zone]N)zhttp://[a::b%zone]rJ   )zHTTP://GOOGLE.COM/mail/r3   )zGOogle.COM/mailr3   )zHTTP://GoOgLe.CoM:8000/mail/r:   )z%HTTP://user:password@EXAMPLE.COM:1234)r4   example.comr>   r?   )zHTTP://173.194.35.7rA   )z'HTTP://[2a00:1450:4001:c01::67]:80/testrF   )z@HTTP://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:8000/index.htmlrG   )z/HTTPS://[1080:0:0:0:8:800:200c:417A]/index.html)r<   rH   N)zabOut://eXamPlE.com?info=1)aboutzeXamPlE.comN)z&http+UNIX://%2fvar%2frun%2fSOCKET/path)z	http+unixz%2fvar%2frun%2fSOCKETNurlscheme_host_portc                    t        |      }|\  }}}|j                  xs d|k(  sJ |j                  |j                  cxk(  r|k(  sJ  J |j                  |k(  sJ y )Nr4   )r+   schemehostnamehostport)selfrM   rN   
parsed_urlrP   rR   rS   s          5platform/gsutil/third_party/urllib3/test/test_util.pytest_scheme_host_portzTestUtil.test_scheme_host_port   sg     s^
-d!!+V666""joo======$&&&    c                0    t        d t                     J y N)r*   setrT   s    rV   test_encode_invalid_chars_nonez'TestUtil.test_encode_invalid_chars_none   s    $T351999rX   )
zhttp://google.com:foozhttp://::1/zhttp://::1:80/zhttp://google.com:-80zhttp://google.com:65536u   http://google.com:²²   http://퟿.comu   http://❤️u   http://.comu   http://.comc                v    t        j                  t              5  t        |       d d d        y # 1 sw Y   y xY wrZ   pytestraisesr   r+   rT   rM   s     rV   test_invalid_urlzTestUtil.test_invalid_url   s$    $ ]]-.cN /..   /8zurl, expected_normalized_url))zHTTP://GOOGLE.COM/MAIL/zhttp://google.com/MAIL/)z5http://user@domain.com:password@example.com/~tilde@?@z7http://user%40domain.com:password@example.com/~tilde@?@)z,HTTP://JeremyCline:Hunter2@Example.com:8080/z,http://JeremyCline:Hunter2@example.com:8080/)zHTTPS://Example.Com/?Key=Valuezhttps://example.com/?Key=Value)zHttps://Example.Com/#Fragmentzhttps://example.com/#Fragment)
[::1%zone]rf   )z[::1%25zone]rf   )[::1%25]rg   )z[::Ff%etH0%Ff]/%ab%Afz[::ff%etH0%FF]/%AB%AF)z,http://user:pass@[AaAa::Ff%25etH0%Ff]/%ab%Afz*http://user:pass@[aaaa::ff%etH0%FF]/%AB%AF)z3http://google.com/p[]?parameter[]="hello"#fragment#Ahttp://google.com/p%5B%5D?parameter%5B%5D=%22hello%22#fragment%23)zAhttp://google.com/p%5B%5d?parameter%5b%5D=%22hello%22#fragment%23rh   c                <    t        |      j                  }||k(  sJ y)zEAssert parse_url normalizes the scheme/host, and only the scheme/hostNr+   rM   )rT   rM   expected_normalized_urlactual_normalized_urls       rV   test_parse_url_normalizationz%TestUtil.test_parse_url_normalization   s$    R !*# 2 2$(????rX   charr   !   c           
         dt        t        |            dd  j                  d      j                         z   }t	        d| d| d| d|       }|t        dd|z   d	d
|z   d|z   d|z         k(  sJ y )N%   zhttp://userz@example.com/pathz?queryz	#fragmentr4   userrK   z/pathqueryfragment)authrR   pathru   rv   )hexordzfillupperr+   r)   )rT   rn   percent_charrM   s       rV   +test_control_characters_are_percent_encodedz4TestUtil.test_control_characters_are_percent_encoded   s    c#d)nQR066q9??AB$0fTF)D6R
 c,&<'L(,.
 
 	
 
rX   r2   r4   r5   /mail)rR   rx   r6   /mail/mailr7   r8   /r9   rR   zhttp://google.com?foo foo)rR   rx   ru   )rx   z#?/!google.com/?fooz?/!google.com/?foo)rx   rv   z/foo/foo?bar=bazzbar=baz)rx   ru   z /foo?bar=baz#banana?apple/orangezbanana?apple/orange)rx   ru   rv   z(/redirect?target=http://localhost:61020/redirectztarget=http://localhost:61020/zhttp://google.com:80/rC   )rR   rS   rx   zhttp://google.com:80)rR   rS   zhttp://foo:bar@localhost/zfoo:bar	localhost)rw   rR   rx   zhttp://foo@localhost/?#z/abc/../defz/defzhttp://google.com:zhttp://google.com:/u"   http://Königsgäßchen.de/straßezxn--knigsgchen-b4a3dun.dez/stra%C3%9Fez+http://user@email.com:password@example.com/zuser%40email.com:passwordrK   z http://user":quoted@example.com/zuser%22:quotedu   http://google.com/z	%ED%A0%80u   http://google.com?q=zq=%ED%B0%80u   http://google.com#z	%ED%B0%80)rR   rx   rv   zurl, expected_urlexpected_urlc                    t        |      }||k(  sJ |j                  |j                  cxk(  r|j                  k(  sJ  J y rZ   )r+   rQ   rR   )rT   rM   r   returned_urls       rV   test_parse_urlzTestUtil.test_parse_url5  sF    
 !~|+++$$(9(9N\=N=NNNNNNrX   c                &    ||j                   k(  sJ y rZ   )rM   rT   rM   r   s      rV   test_unparse_urlzTestUtil.test_unparse_url>  s    l&&&&&rX   z/..z/./abc/./def/z	/abc/def/z/.z/./z&/abc/./.././d/././e/.././f/./../../ghiz/ghic                ^    t        |      }||k(  sJ |j                  |j                  k(  sJ y rZ   rj   )rT   rM   r   
actual_urls       rV   "test_parse_and_normalize_url_pathsz+TestUtil.test_parse_and_normalize_url_pathsB  s3     s^
\)))~~!1!1111rX   c                v    t        j                  t              5  t        d       d d d        y # 1 sw Y   y xY w)Nz[::1r`   r\   s    rV   test_parse_url_invalid_IPv6z$TestUtil.test_parse_url_invalid_IPv6S  s#    ]]-.f /..re   c                v    t        j                  t              5  t        d       d d d        y # 1 sw Y   y xY w)Nzhttps://www.google.com:-80/r`   r\   s    rV   test_parse_url_negative_portz%TestUtil.test_parse_url_negative_portW  s$    ]]-.34 /..re   c                <    t        d      }|j                  dk(  sJ y )Nz!https://example.com:0000000000080rC   r+   rS   rc   s     rV   #test_parse_url_remove_leading_zerosz,TestUtil.test_parse_url_remove_leading_zeros[  s    ;<xx2~~rX   c                t    t        d      }|j                  dk(  sJ t        d      }|j                  dk(  sJ y )Nzhttps://example.com:0r   z https://example.com:000000000000r   rc   s     rV   test_parse_url_only_zerosz"TestUtil.test_parse_url_only_zeros_  s8    /0xx1}}:;xx1}}rX   c                R    t        dd      }t        |      |j                  k(  sJ y )Nr4   r5   r   )r)   strrM   )rT   Us     rV   test_Url_strzTestUtil.test_Url_strf  s"    \*1vrX   )	)r2   r   )r6   r   )r8   r   )r9   r   )r   r   )r   r   )r   z/?)r   r   )r   r   zurl, expected_request_uric                <    t        |      }|j                  |k(  sJ y rZ   )r+   request_uri)rT   rM   expected_request_urir   s       rV   test_request_urizTestUtil.test_request_uriv  s      ~''+????rX   ))z http://user:pass@google.com/mailzuser:pass@google.com)z#http://user:pass@google.com:80/mailzuser:pass@google.com:80)zhttp://user@google.com:80/mailzuser@google.com:80)z!http://user:pass@192.168.1.1/pathzuser:pass@192.168.1.1)z$http://user:pass@192.168.1.1:80/pathzuser:pass@192.168.1.1:80)zhttp://user@192.168.1.1:80/pathzuser@192.168.1.1:80)zhttp://user:pass@[::1]/pathzuser:pass@[::1])zhttp://user:pass@[::1]:80/pathzuser:pass@[::1]:80)zhttp://user@[::1]:80/pathzuser@[::1]:80)zhttp://user:pass@localhost/pathzuser:pass@localhost)z"http://user:pass@localhost:80/pathzuser:pass@localhost:80)zhttp://user@localhost:80/pathzuser@localhost:80zlist[tuple[str, str | None]]url_authority_map))r2   r5   )zhttp://google.com:80/mailzgoogle.com:80)zhttp://192.168.0.1/pathz192.168.0.1)zhttp://192.168.0.1:80/pathz192.168.0.1:80)zhttp://[::1]/pathz[::1])zhttp://[::1]:80/pathz[::1]:80)zhttp://localhostr   )zhttp://localhost:80zlocalhost:80)zgoogle.com/foobarr5   )google.com:12345r   )r   Nzurl, expected_authorityc                8    t        |      j                  |k(  sJ y rZ   )r+   	authorityrT   rM   expected_authoritys      rV   test_authorityzTestUtil.test_authority  s    ~''+====rX   c                8    t        |      j                  |k(  sJ y)z7Validate this matches the behavior of urlparse().netlocN)r   netlocr   s      rV   $test_authority_matches_urllib_netlocz-TestUtil.test_authority_matches_urllib_netloc  s    
 }##'9999rX   zurl, expected_netlocc                8    t        |      j                  |k(  sJ y rZ   )r+   r   )rT   rM   expected_netlocs      rV   test_netloczTestUtil.test_netloc  s    ~$$777rX   zhttp://google.com#@evil.com/z
@evil.com/z0http://127.0.0.1%0d%0aConnection%3a%20keep-alivez)127.0.0.1%0d%0aconnection%3a%20keep-aliveu   http://google.com/ＮＮ/abcz/%EF%BC%AE%EF%BC%AE/abcz*javascript:a='@google.com:12345/';alert(0)
javascriptza='@google.com:12345/';alert(0))rP   rx   z//google.com/a/b/cz/a/b/cu&   http://ヒ:キ@ヒ.abc.ニ/ヒ?キ#ワzxn--pdk.abc.xn--idkz%E3%83%92:%E3%82%ADz
/%E3%83%92z	%E3%82%ADz	%E3%83%AF)rR   rw   rx   ru   rv   z110.251.0.83:7777?a=1 HTTP/1.1
X-injected: headerz10.251.0.83ia  z(a=1%20HTTP/1.1%0D%0AX-injected:%20header)rR   rS   rx   ru   z>http://127.0.0.1:6379?
SET test failure12
:8080/test/?test=ar=   i  z4%0D%0ASET%20test%20failure12%0D%0A:8080/test/?test=a)rP   rR   rS   rx   ru   zZhttps://user:pass@xdavidhu.me\test.corp.google.com:8080/path/to/something?param=value#hashr<   z	user:passzxdavidhu.mez//%5Ctest.corp.google.com:8080/path/to/somethingzparam=valuehash)rP   rw   rR   rx   ru   rv   zhttps://@i'  [Fz"Tons of '@' causing backtracking 1)idzhttps://user:zuser:z%40i'  )rP   rw   rR   z"Tons of '@' causing backtracking 2c                    |du r.t        j                  t              5  t        |       d d d        y t        |      |k(  sJ y # 1 sw Y   y xY w)NFr`   r   s      rV   test_url_vulnerabilitiesz!TestUtil.test_url_vulnerabilities  sE     5 12# 32 S>\111 32s   AAc                v    t        j                  t              5  t        d       d d d        y # 1 sw Y   y xY w)Ns   https://www.google.com/)ra   rb   	TypeErrorr+   r\   s    rV   test_parse_url_bytes_type_errorz(TestUtil.test_parse_url_bytes_type_error  s#    ]]9%01 &%%re   zkwargs, expectedaccept_encodingTaccept-encodingzgzip,deflate,br,zstd)markszgzip,deflate,brzgzip,deflate,zstdzgzip,deflatezfoo,barbarbanana)r   
user_agent)r   
user-agentr   r   
keep_alive
connectionz
keep-alive
basic_authauthorizationzBasic Zm9vOmJhcg==proxy_basic_authzproxy-authorizationdisable_cachezcache-controlzno-cachec                $    t        di ||k(  sJ y )N )r   )rT   kwargsexpecteds      rV   test_make_headerszTestUtil.test_make_headers  s    t %f%111rX   c                    t        j                  d      }|j                         dk(  sJ |j                         dk(  sJ t        |d       |j                         dk(  sJ y )N	   test datarX      s   data)ioBytesIOreadr    rT   bodys     rV   test_rewind_bodyzTestUtil.test_rewind_bodyL  sZ    zz,'yy{l*** yy{c!!! 	D!yy{g%%%rX   c                    t        j                  d      }|j                          t        }t	        j
                  t              5  t        ||       d d d        y # 1 sw Y   y xY w)Nr   )r   r   r   r   ra   rb   r   r    )rT   r   body_poss      rV   test_rewind_body_failed_tellz%TestUtil.test_rewind_body_failed_tellW  sC    zz,'		 ]]01h' 211s   AA$c                J   t        j                  d      }|j                          t        j                  t
              5  t        |d        d d d        t        j                  t
              5  t        |t                      d d d        y # 1 sw Y   AxY w# 1 sw Y   y xY w)Nr   r   )r   r   r   ra   rb   
ValueErrorr    objectr   s     rV   test_rewind_body_bad_positionz&TestUtil.test_rewind_body_bad_position`  sf    zz,'		 ]]:&t, ']]:&vx0 '& '&&&s   B.BBB"c                     G d dt         j                        }t        j                  t              5  t         |       d       d d d        y # 1 sw Y   y xY w)Nc                      e Zd ZdddZy)6TestUtil.test_rewind_body_failed_seek.<locals>.BadSeekc                    t         rZ   )OSError)rT   offsetwhences      rV   seekz;TestUtil.test_rewind_body_failed_seek.<locals>.BadSeek.seekl  s    rX   N)r   )r   intr   r   returnztyping.NoReturn)__name__
__module____qualname__r   r   rX   rV   BadSeekr   k  s    rX   r   rs   r   )r   StringIOra   rb   r   r    )rT   r   s     rV   test_rewind_body_failed_seekz%TestUtil.test_rewind_body_failed_seekj  s9    	bkk 	 ]]01	A. 211s   AAc                    t        t        j                        }t        j                  d      }||j                  v sJ |j                  d       |j                  |       y )N)levelurllib3zTesting add_stderr_logger)r   loggingINFO	getLoggerhandlersdebugremoveHandler)rT   handlerloggers      rV   test_add_stderr_loggerzTestUtil.test_add_stderr_loggerr  sM    #',,7""9-&//)))01W%rX   c                `   t        j                  d      5 }t                t        j                  dt               t        j
                  dt               t        |      dk(  sJ t                t        j
                  dt               t        |      dk(  sJ 	 d d d        y # 1 sw Y   y xY w)NT)recorddefaultzThis is a test.r.   )warningscatch_warningsr/   simplefilterr   warnlenr   )rT   ws     rV   test_disable_warningszTestUtil.test_disable_warningsz  s{    $$D1Q!!)-CDMM+-CDq6Q;;MM+-CDq6Q;; 211s   BB$$B-c                X    t         |_        |j                          t         |z   |_        |S )z*Make some time pass for the timeout object)TIMEOUT_EPOCHreturn_valuestart_connect)rT   secondstimeout	time_mocks       rV   _make_time_passzTestUtil._make_time_pass  s*     "/	!.!8	rX   zkwargs, messagetotalz	less thanrs   )connectr  r   r  zcannot be a booleanzless than or equalzint, float or Nonez1.0c                z    t        j                  t        |      5  t        di | d d d        y # 1 sw Y   y xY w)Nmatchr   )ra   rb   r   r(   )rT   r   messages      rV   test_invalid_timeoutszTestUtil.test_invalid_timeouts  s)      ]]:W5f 655   1:ztime.monotonicc                   t        d      }| j                  d||      }|j                  dk(  sJ |j                  dk(  sJ t        dd      }|j                  dk(  sJ t               }|j                  t        k(  sJ t        dd	      }| j                  d
||      }|j                  d
k(  sJ t        dd	      }| j                  d||      }|j                  dk(  sJ t        dd	      }|j                  dk(  sJ t        d d d       }|j                  J |j                  J |j
                  J t        d
      }|j
                  d
k(  sJ y )N   r  r   )r
  r  r  rs   )r  r  
      )r  r   r   )r  r   r  )r(   r  read_timeoutconnect_timeoutr'   r  rT   time_monotonicr  s      rV   test_timeoutzTestUtil.test_timeout  s   " &&w. ' 
 ##q(((&&!+++1-&&!+++)&&*:::: +&&w. ' 
 ##q((( +&&w. ' 
 ##q(((+##q(((4>&&...##+++}}$$$!*}}!!!rX   c                    t               }t        dd      5  |j                  dk(  sJ 	 ddd       t        dd      5  |j                  dk(  sJ 	 ddd       y# 1 sw Y   2xY w# 1 sw Y   yxY w)z>The timeout default is resolved when read_timeout is accessed.z&urllib3.util.timeout.getdefaulttimeoutrs   )r  Nr  )r(   r   r  rT   r  s     rV   test_timeout_default_resolvez%TestUtil.test_timeout_default_resolve  sl    );!L''1,,, M ;!L''1,,, ML ML MLs   A A(A%(A1c                |    t        ddd      }t        |      dk(  sJ t        dd d      }t        |      dk(  sJ y )Nr.   rs   r  )r  r   r  z#Timeout(connect=1, read=2, total=3)z&Timeout(connect=1, read=None, total=3))r(   r   r"  s     rV   test_timeout_strzTestUtil.test_timeout_str  sD    !!157|DDDD!$a87|GGGGrX   c                   t         |_        t        d      }t        j                  t
              5  |j                          d d d        |j                          t        j                  t
              5  |j                          d d d        t         dz   |_        |j                         dk(  sJ t         dz   |_        |j                         dk(  sJ y # 1 sw Y   xY w# 1 sw Y   \xY w)Nr  r  rs   %   )r  r  r(   ra   rb   r   get_connect_durationr	  r  s      rV   test_timeout_elapsedzTestUtil.test_timeout_elapsed  s    &3#"]],-((* . 	]],-!!# . '4a&7#++-222&3b&8#++-333 .- .-s   C3CCC(c                <     G d d      }t         |             sJ y )Nc                      e Zd Zedd       Zy)ETestUtil.test_is_fp_closed_object_supports_closed.<locals>.ClosedFilec                     yNTr   r\   s    rV   closedzLTestUtil.test_is_fp_closed_object_supports_closed.<locals>.ClosedFile.closed      rX   Nr   ztyping.Literal[True])r   r   r   propertyr/  r   rX   rV   
ClosedFiler,         rX   r3  r   )rT   r3  s     rV   (test_is_fp_closed_object_supports_closedz1TestUtil.test_is_fp_closed_object_supports_closed      	 	
 JL)))rX   c                <     G d d      }t         |             sJ y )Nc                      e Zd Zedd       Zy)ATestUtil.test_is_fp_closed_object_has_none_fp.<locals>.NoneFpFilec                     y rZ   r   r\   s    rV   fpzDTestUtil.test_is_fp_closed_object_has_none_fp.<locals>.NoneFpFile.fp  r0  rX   Nr   Noner   r   r   r2  r;  r   rX   rV   
NoneFpFiler9    r4  rX   r?  r   )rT   r?  s     rV   $test_is_fp_closed_object_has_none_fpz-TestUtil.test_is_fp_closed_object_has_none_fp  r6  rX   c                <     G d d      }t         |             rJ y )Nc                      e Zd Zedd       Zy)8TestUtil.test_is_fp_closed_object_has_fp.<locals>.FpFilec                     yr.  r   r\   s    rV   r;  z;TestUtil.test_is_fp_closed_object_has_fp.<locals>.FpFile.fp  r0  rX   Nr1  r>  r   rX   rV   FpFilerC    r4  rX   rE  r   )rT   rE  s     rV   test_is_fp_closed_object_has_fpz(TestUtil.test_is_fp_closed_object_has_fp  s!    	 	
  ))))rX   c                     G d d      }t        j                  t              5  t         |              d d d        y # 1 sw Y   y xY w)Nc                      e Zd Zy)STestUtil.test_is_fp_closed_object_has_neither_fp_nor_closed.<locals>.NotReallyAFileN)r   r   r   r   rX   rV   NotReallyAFilerI    s    rX   rJ  )ra   rb   r   r   )rT   rJ  s     rV   2test_is_fp_closed_object_has_neither_fp_nor_closedz;TestUtil.test_is_fp_closed_object_has_neither_fp_nor_closed  s1    	 	 ]]:&)* '&&s	   >Ac                b    t        dd      5  t        d      rJ 	 d d d        y # 1 sw Y   y xY w)Nsocket.has_ipv6F::1)r   r   r\   s    rV   !test_has_ipv6_disabled_on_compilez*TestUtil.test_has_ipv6_disabled_on_compile  s*    $e, '''' -,,s   %.c                    t        dd      5  t        d      5 }|j                  }t        t        d            |_        t        d      rJ 	 d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)NrM  Tsocket.socketzNo IPv6 here!)side_effectrN  )r   r  r   	Exceptionbindr   rT   r   instances      rV   test_has_ipv6_enabled_but_failsz(TestUtil.test_has_ipv6_enabled_but_fails  sa    $d+'4,, $?1K L$U++++ ( ,+'' ,+s"   A+4AA+A(	$A++A4c                    t        dd      5  t        d      5 }|j                  }d|j                  _        t        d      sJ 	 d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)NrM  TrQ  rN  )r   r  rT  r   rU  s      rV   !test_has_ipv6_enabled_and_workingz*TestUtil.test_has_ipv6_enabled_and_working  sY    $d+'4,,-1* ''' ( ,+'' ,+s"   A"+AA"A	A""A+c                    t        dd      5  t               t        j                  k(  sJ 	 d d d        y # 1 sw Y   y xY w)N urllib3.util.connection.HAS_IPV6T)r   r   socket	AF_UNSPECr\   s    rV   test_ip_family_ipv6_enabledz$TestUtil.test_ip_family_ipv6_enabled  s0    5t<%'6+;+;;;; =<<   5>c                    t        dd      5  t               t        j                  k(  sJ 	 d d d        y # 1 sw Y   y xY w)Nr[  F)r   r   r\  AF_INETr\   s    rV   test_ip_family_ipv6_disabledz%TestUtil.test_ip_family_ipv6_disabled  s.    5u=%'6>>999 >==r_  headerss   fooNc                v    t        j                  t              5  t        |       d d d        y # 1 sw Y   y xY wrZ   )ra   rb   r   r!   )rT   rc  s     rV   <test_assert_header_parsing_throws_typeerror_with_non_headerszETestUtil.test_assert_header_parsing_throws_typeerror_with_non_headers"  s$     ]]9%!'* &%%re   c                $    t        d d d       rJ y )N)	proxy_urlproxy_configdestination_schemer   r\   s    rV   -test_connection_requires_http_tunnel_no_proxyz6TestUtil.test_connection_requires_http_tunnel_no_proxy)  s     2$
 	
 
 
rX   c                |    t        d      }t        d dd d       }d}t        |||      rJ d}t        |||      sJ y )Nzhttp://proxy:8080Fssl_contextuse_forwarding_for_httpsassert_hostnameassert_fingerprintr4   r<   r+   r   r   rT   proxyrh  ri  s       rV   /test_connection_requires_http_tunnel_http_proxyz8TestUtil.test_connection_requires_http_tunnel_http_proxy.  s`    -."%* #	
 $2<!3
 	
 
 %.ulDVWWWrX   c                Z    t        d      }t        d dd d       }d}t        |||      rJ y )Nzhttps://proxy:8443Frl  r4   rq  rr  s       rV   0test_connection_requires_http_tunnel_https_proxyz9TestUtil.test_connection_requires_http_tunnel_https_proxy>  sJ    ./"%* #	
 $2<!3
 	
 
 
rX   c                    ddl m} t        j                         }|j	                  d       |j                  d       t        |j                  |             y )Nr   )clients   Content-Type: multipart/encrypted;protocol="application/HTTP-SPNEGO-session-encrypted";boundary="Encrypted Boundary"
Server: Microsoft-HTTPAPI/2.0
Date: Fri, 16 Aug 2019 19:28:01 GMT
Content-Length: 1895


)r4   rx  r   r   writer   r!   parse_headers)rT   rx  
header_msgs      rV   0test_assert_header_parsing_no_error_on_multipartz9TestUtil.test_assert_header_parsing_no_error_on_multipartK  sD    ZZ\
,	
 	f22:>?rX   rR   )z
.localhostz...@ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttc                    t        j                  t        d| d      5  t        |df       d d d        y # 1 sw Y   y xY w)NzFailed to parse: 'z', label empty or too longr  rC   )ra   rb   r   r   )rT   rR   s     rV   /test_create_connection_with_invalid_idna_labelsz8TestUtil.test_create_connection_with_invalid_idna_labelsX  s<    ]]&tf,FG
 tRj)	
 
 
s	   7A )za.example.comz
localhost.z[dead::beef]z[dead::beef%en5]z[dead::beef%en5.]zsocket.getaddrinforQ  c                L    dg|_         t               |_         t        |df       y )N)NNNNNrC   )r  r   r   )rT   r\  getaddrinforR   s       rV   -test_create_connection_with_valid_idna_labelsz6TestUtil.test_create_connection_with_valid_idna_labels`  s&     %C#C "f4*%rX   c                    g |_         t        j                  t        d      5  t	        d       d d d        y # 1 sw Y   y xY w)Nz!getaddrinfo returns an empty listr  rK   rC   )r  ra   rb   r   r   rT   r  s     rV   test_create_connection_errorz%TestUtil.test_create_connection_errors  s/    #% ]]7*MN12 ONNs	   8Ac                    t        j                         |_        t        j                  t         j                        5  t        d       d d d        y # 1 sw Y   y xY w)Nr  )r\  gaierrorrR  ra   rb   r   r  s     rV   test_dnsresolver_forced_errorz&TestUtil.test_dnsresolver_forced_errory  s6    "(//"3]]6??+12 ,++s   AAc                    t        j                  t        j                        5  t	        d       d d d        y # 1 sw Y   y xY w)N)zbadhost.invalidrC   )ra   rb   r\  r  r   r\   s    rV   test_dnsresolver_expected_errorz(TestUtil.test_dnsresolver_expected_error  s)    ]]6??+ 56	 ,++s	   9Ac                    d}|j                   |j                  |j                  d|fg|_        t	               x|_        }t        d       |j                  d   d   dk(  sJ |j                  j                  |       y )N)za::brC   r   rI   r   )
a::b%ifacerC   r   r  )	AF_INET6SOCK_STREAMIPPROTO_TCPr  r   r   	call_argsr  assert_called_once_with)rT   r\  r  fake_scoped_sa6	fake_socks        rV   'test_create_connection_with_scoped_ipv6z0TestUtil.test_create_connection_with_scoped_ipv6  s     . """"$
  +4+5i,-$$Q'*l:::11/BrX   zinput,params,expectedtests   testencodingzutf-8asciic                &    t        |fi ||k(  sJ y rZ   )r-   rT   inputparamsr   s       rV   test_to_strzTestUtil.test_to_str  s     e&v&(222rX   c                z    t        j                  t        d      5  t        d       d d d        y # 1 sw Y   y xY wNznot expecting type intr  r.   )ra   rb   r   r-   r\   s    rV   test_to_str_errorzTestUtil.test_to_str_error  s%    ]]9,DE1I FEEr     és   éc                &    t        |fi ||k(  sJ y rZ   )r,   r  s       rV   test_to_byteszTestUtil.test_to_bytes  s     ((H444rX   c                z    t        j                  t        d      5  t        d       d d d        y # 1 sw Y   y xY wr  )ra   rb   r   r,   r\   s    rV   test_to_bytes_errorzTestUtil.test_to_bytes_error  s%    ]]9,DEQK FEEr  )rM   r   rN   ztuple[str, str, int | None]r   r=  r<  )rM   r   r   r=  )rM   r   rk   r   r   r=  )rn   r   r   r=  )rM   r   r   r)   r   r=  )rM   r   r   r   r   r=  )rM   r   r   
str | Noner   r=  )rM   r   r   r  r   r=  )rM   r   r   ztyping.Literal[False] | Urlr   r=  )r   zdict[str, bool | str]r   dict[str, str]r   r=  )r
  r   r  r(   r  r   r   r(   )r   zdict[str, int | bool]r  r   r   r=  )r  r   r   r=  )rc  zbytes | object | Noner   r=  )rR   r   r   r=  )r\  r   r  r   rR   r   r   r=  )r  r   r   r=  )r\  r   r  r   r   r=  )r  bytes | strr  r  r   r   r   r=  )r  r  r  r  r   bytesr   r=  )Tr   r   r   url_host_mapra   markparametrizerW   r]   rd   rm   rangechrr~   r)   parse_url_host_map%non_round_tripping_parse_url_host_mapr   r   r   r   r   r   r   r   r   request_uri_mapr   r   __annotations__url_netloc_mapcombined_netloc_authority_map
startswithurl_authority_with_schemes_mapr   r   r   paramurl_vulnerabilitiesr   r   r	   r
   r   r   r   r   r   r   r   r   r  r  r  r   r   r#  r%  r)  r5  r@  rF  rK  rO  rW  rY  r^  rb  r   re  rj  rt  rv  r|  r  r  r  r  r  r  r  r  r  r  ).0ir  us   0000rV   r1   r1   2   s   XLt [[e%78,G''*E'	' H': [[	
"#" [[&!	
$J@@14@	@K$J@ [[VeD$6G%H6Gc!f6G%HF8%ST
 U
  
"3vLw#OP	"C\$QR	!3vLv#NO	C\@A	s63GH	c&|<=	 #f<bPU"VW	SU	csm	6J KL	&!"	&	:;.V97LM	

 7Z'GH	

 
s63GH	 #f<bs"ST	V,R!HI (Y[sC	
 
!#f5{QT"UV'Y[sC	
A$P 
cr$%	crB'(	()	s6=>	FC HI 18~N	
 :8}SVW	

 /-ML	

 
$Sl%UV(\-H	

 '\[I	
;!-)F [[ "GHO	O
 [[02DE' F' [[	 CV,-CSM"c{343C=!CSM"5s7GH	
22
5
O [[8/J@ K@73 N %6$F!
 1&0aAaDOOF4K0&" [[68UV> W> [[68VW::,6:	: X: [[3^D8 E8 +\\J	
 ?HI	
 1\0IJ	
 9|*KL	
 
s8DE 5**!!$
	
 B"@		
 Q L		
 j "F#
	
 	#+&,3	

 	sU{+m;-"
 4	
QQf [[02EF22&A2	2 G22 [[FLL"D)"$:;!|XZ0
 FLL"D)"$56!|WY/
 FLL"D)"$78 {HJ/
 FLL"D)"N3 {GI.
  +.?-KL%03Di2PQFLL$(A$:(S!|XZ0
 FLL$(A$5XN!|WY/
 FLL$(A$7xP {HJ/
 FLL$(A$2(K {GI.
 H%h'?@D!L,#?@I&:N(OP#Y/&(<= t$
&CDe3	
6n2+27E2	2o6n2
	&(1/&%,9=	 [[r]K(R(+6b\;'!67d^23^12e_23e_23		
+69	 '" '"R-H 4 4***+(,(<: [[Yv(>?+,+	+ @+

X 
@ [[V%DE* F* [[	
	  
?&&.7&?B&	&  !	&  3 !3
  3 !37  
?CC.7C	C  !C, [[R b&!z7+V4z7+V4		
3 3*83DG3	33
 [[b'"R!2{#j'*G4j'*G4	
	5 5*85DI5	5	5
I &I@&s   ,bb br1   c            	         e Zd ZdZej
                  j                  ddej                  fej                  ej                  fej                  ej                  fdej                  fdej                  fg      	 	 	 	 	 	 dd       Z
ej
                  j                  dej                  ej                  fdej                  fd	ej                  fej                  ej                  fg      dd
       ZddZ ed      	 	 	 	 dd       ZddZddZddZ	 	 	 	 	 	 ddZddZddZej
                  j                  dg d      	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Zy)TestUtilSSLz#Test utils that use an SSL backend.zcandidate, requirementsNREQUIREDCERT_REQUIREDc                $    t        |      |k(  sJ y rZ   )r$   )rT   	candidaterequirementss      rV   test_resolve_cert_reqsz"TestUtilSSL.test_resolve_cert_reqs  s     !+|;;;rX   zcandidate, versionPROTOCOL_TLSv1TLSv1c                $    t        |      |k(  sJ y rZ   )r%   )rT   r  versions      rV   test_resolve_ssl_versionz$TestUtilSSL.test_resolve_ssl_version  s     #9-888rX   c                    t               }t               }t        ||d       |j                  j                  dd        y )Nz/path/to/certfile)rm  sockcertfile)r   r&   load_cert_chainr  rT   r\  mock_contexts      rV   )test_ssl_wrap_socket_loads_the_cert_chainz5TestUtilSSL.test_ssl_wrap_socket_loads_the_cert_chain  s:    v$6<O	
 	$$<<=PRVWrX   z(urllib3.util.ssl_.create_urllib3_contextc                v    t               }t        |t        j                         |j	                  d dd        y )N)	cert_reqsrs   )ciphers)r   r&   sslr  r  )rT   create_urllib3_contextr\  s      rV   (test_ssl_wrap_socket_creates_new_contextz4TestUtilSSL.test_ssl_wrap_socket_creates_new_context  s0     #*;*;<66tQ6MrX   c                    t               }t               }t        |d|       |j                  j                  dd d        y )Nz/path/to/pem)rm  ca_certsr  r   r&   load_verify_locationsr  r  s      rV   +test_ssl_wrap_socket_loads_verify_locationsz7TestUtilSSL.test_ssl_wrap_socket_loads_verify_locations  s8    vL>PVW**BBD$	
rX   c                    t               }t               }t        |d|       |j                  j                  d dd        y )Nz/path/to/pems)rm  ca_cert_dirr  r  r  s      rV   2test_ssl_wrap_socket_loads_certificate_directoriesz>TestUtilSSL.test_ssl_wrap_socket_loads_certificate_directories  s<    v$/	
 	**BB/4	
rX   c                    t               }t               }t        |d|       |j                  j                  d d d       y )NzTOTALLY PEM DATA)rm  ca_cert_datar  r  r  s      rV   +test_ssl_wrap_socket_loads_certificate_dataz7TestUtilSSL.test_ssl_wrap_socket_loads_certificate_data  s>    v$3EF	
 	**BB$*	
rX   c                    t               }t        d      5 }t        |||       d d d        ||fS # 1 sw Y   |fS xY w)Nzwarnings.warn)rm  r  server_hostname)r   r   r&   )rT   r  r  r  r  s        rV   _wrap_socket_and_mock_warnz&TestUtilSSL._wrap_socket_and_mock_warn  sK     v?#t( / $ T!! $ T!!s   1=c                    t               }| j                  |d      \  }}|j                  j                  |d       |j	                          y)zDTest that a warning is not made if server_hostname is an IP address.z8.8.8.8r  Nr   r  wrap_socketr  assert_not_calledrT   r  contextr  s       rV   +test_ssl_wrap_socket_sni_ip_address_no_warnz7TestUtilSSL.test_ssl_wrap_socket_sni_ip_address_no_warn  sD    v77iH33D)3T rX   c                    t               }| j                  |d      \  }}|j                  j                  |d       |j	                          y)z@Test that a warning is not made if server_hostname is not given.Nr  r  r  s       rV   %test_ssl_wrap_socket_sni_none_no_warnz1TestUtilSSL.test_ssl_wrap_socket_sni_none_no_warn$  sD    v77dC33D$3O rX   zgopenssl_version, openssl_version_number, implementation_name, version_info, pypy_version_info, reliable))OpenSSL 1.1.1cpythonr  	   r  NT)r   r  r  NT)r  r  pypy)r  r  r  )r  r  r  F)r  r  r  )r        )r  r  r  T)r  r  r  r  r  rs   NT)zLibreSSL 2.8.3r  r  )r  r  r   NF)zOpenSSL 1.1.0r  r  r  NFc                ,    t        |||||      |k(  sJ y rZ   )r#   )rT   openssl_versionopenssl_version_numberimplementation_nameversion_infopypy_version_inforeliables          rV   ,test_is_has_never_check_common_name_reliablez8TestUtilSSL.test_is_has_never_check_common_name_reliable+  s/    8 5&#! 		
rX   )r  zint | str | Noner  r   r   r=  )r  z	int | strr  r   r   r=  r<  )r  zmock.MagicMockr   r=  )r  rQ  r  r  r   ztuple[Mock, MagicMock])r  r   r  r   r  r   r  r"   r  z_TYPE_VERSION_INFO | Noner  boolr   r=  )r   r   r   __doc__ra   r  r  r  r  	CERT_NONEr  r  PROTOCOL_SSLv23r  r  r   r  r  r  r  r  r  r  r  r   rX   rV   r  r    s   -[[!3$$%]]CMM* 1 12**+c//0	
	<)<9<<	<	<
 [[!3!34s112c(()  #"5"56		
99X 56N&4N	N 7N



"!
"4>
"	
"!! [[q	
$

 !$
 !	

 )
 5
 
 

%$
rX   r  idnar   c                  8    e Zd Zedd       Zedd       ZddZy)TestUtilWithoutIdnac                    t         j                  j                  dd        t        j	                          t         j
                  j                  dt               y )Nr  r   )sysmodulespopmodule_stashstash	meta_pathinsertidna_blockerclss    rV   setup_classzTestUtilWithoutIdna.setup_classW  s4    %Q-rX   c                r    t         j                  j                  t               t        j                          y rZ   )r  r  remover  r  r
  r  s    rV   teardown_classz"TestUtilWithoutIdna.teardown_class^  s     \*rX   c                    d}t        j                  t        d|       5  t        |       d d d        y # 1 sw Y   y xY w)Nr^   zFailed to parse: r  r`   rc   s     rV   test_parse_url_without_idnaz/TestUtilWithoutIdna.test_parse_url_without_idnac  s2    !]]-7H5NOcN POOs   6?Nr<  )r   r   r   classmethodr  r  r  r   rX   rV   r  r  V  s-    . .  rX   r  )K
__future__r   r   r   r\  r  r  typingr   	itertoolsr   r  r   r   r   r   r	   r
   unittestr   unittest.mockr   r   r   urllib.parser   ra   r   r   r   urllib3.connectionr   urllib3.exceptionsr   r   r   r   urllib3.utilr   urllib3.util.connectionr   r   r   urllib3.util.proxyr   urllib3.util.requestr   r   r    urllib3.util.responser!   urllib3.util.ssl_r"   r#   r$   r%   r&   urllib3.util.timeoutr'   r(   urllib3.util.urlr)   r*   r+   urllib3.util.utilr,   r-   r   r/   r  r1   r  r  r  r  r   rX   rV   <module>r*     s    " 	   
 
    U U  0 0 !  7 *  & T T > G G 7  ; B B . 
 P PfJ
 J
Z V$9% rX   