
                           S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SK	J
r
  S SKJrJrJrJrJrJr  S SKJr  S SKJrJrJr  S SKJr  S SKrS SKJrJr  S S	KJr  S S
K J!r!J"r"J#r#J$r$  S SK%J&r&  S SK'J(r(J)r)J*r*  S SK+J,r,  S SK-J.r.J/r/J0r0  S SK1J2r2  S SK3J4r4J5r5J6r6J7r7J8r8  S SK9J:r:J;r;  S SK<J=r=J>r>J?r?  S SK@JArAJBrB  SSKCJDrD  SrE " S S5      rF " S S5      rG\" S5      rH\" S5      rI " S S5      rJg)    )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                  h   \ rS rSr% / SQr\R                  R                  SS/\5            SS j5       rSS jr	\R                  R                  S/ SQ5      GS S j5       r
\R                  R                  S	/ S
Q5            GSS j5       r\R                  R                  S\" SS5       V VVs/ s H  n[        U5      PM     snnn S/-   5      GSS j5       rS\" SSSS94S\" SSSS94S\" SSSS94S\" SSS94S\" SSSS94S\" SSS94S\" SSSS S!94S\" 5       4S\" SS"94S#\" SS$S%94S&\" S&S"94S'\" S&S(S)94S*\" S&S(S+S,94S-\" S.S/S)94S\" SSSS94S0\" SSS1SS294S3\" SSS1S494S5\" SS6S7SS894S9\" SS S7SS894S5\" SS6S7SS894/rS:\" SSS)94S;\" SSS%94S<\" S=S"94S>\" SSS94S?\" SSSS94S@\" SSASBS94SC\" SSDSESS894SF\" SSGSESS894SH\" SSSIS94SJ\" SSSSKS!94SL\" SSSSMSN94/r\R                  R                  SO\" \\5      5      GSSQ j5       r\R                  R                  SO\5      GSSR j5       r\R                  R                  SSP/S<\" S=S"94SS\" SS"94ST\" SUS"94SV\" SS"94SW\" SS"94SX\" SYS"94/5      GSSZ j5       rSS[ jrSS\ jrSS] jrSS^ jrSS_ jr/ S`Qr\R                  R                  Sa\5      GSSb j5       r/ ScQrSd\Se'   / SfQr\\-   r \  V Vs/ s H  o3S   RC                  S5      (       d  M  UPM!     snn r"\R                  R                  Sg\ 5      GSSh j5       r#\R                  R                  Sg\"5            GSSi j5       r$\R                  R                  Sj\5      GSSk j5       r%Sl\" SSSSmSN94Sn\" SSoS94Sp\" SSSqS94Sr\" SsStSu94Sv\" SSwS94Sx\" SSySzS{S|S}S~94S\" SSSSS94S\" SSSSSS94S\" SSSSSSS94\RL                  " SSS-  -   S-   SSS9\RL                  " SSS-  -   SE-   \" SSSS-  -   SES9SS9/r'\R                  R                  SO\'5            GSS j5       r(SS jr)\R                  R                  S\RL                  " SS0SS0\*" 5       \+" 5       /S9\RL                  " SS0SS0\*" 5       \," 5       /S9\RL                  " SS0SS0\-" 5       \+" 5       /S9\RL                  " SS0SS0\-" 5       \," 5       /S9SS0SS04SS S/0SS04\RL                  " SSS.SSS.\*" 5       \+" 5       /S9\RL                  " SSS.SSS.\*" 5       \," 5       /S9\RL                  " SSS.SSS.\-" 5       \+" 5       /S9\RL                  " SSS.SSS.\-" 5       \," 5       /S9SS0SS04SS0SS04SS60SS04SS60SS04SS0SS04/5            GSS j5       r.SS jr/SS jr0SS jr1SS jr2SS jr3SS jr4        GS	S jr5\R                  R                  SSS0S4SSS.S4SS0S4SS0S4SS0S4SS0S4SS 0S4SS0S4/5            GS
S j5       r6\7" S5      GSS j5       r8SS jr9SS jr:\7" S5      GSS j5       r;SS jr<SS jr=SS jr>SS jr?SS jr@SS jrASS jrBSS jrCSS jrD\R                  R                  SSS\E/5          GSS j5       rFSS jrGSS jrHSS jrISS jrJ\R                  R                  S/ SQ5      GSS j5       rK\R                  R                  S/ SQ5      \7" S5      \7" S5              GSS j5       5       5       rL\7" S5      GSS j5       rM\7" S5      GSS j5       rNSS jrO\7" S5      \7" S5            GSS j5       5       rP\R                  R                  SS0 S4S0 S4SSS0S4SSS0S445              GSS j5       rQSS jrR\R                  R                  SS0 S4S0 S4S0 S4SSS0S4SSS0S445              GSS j5       rSSS jrTSrUgs  snnn f s  snn f (  TestUtil2   )-)http://google.com/mailhttp
google.comN)http://google.com/mail/r4   )google.com/mailr4   )http://google.com/r4   )http://google.comr4   )zhttp://www.google.com)r5   zwww.google.comN)zhttp://mail.google.com)r5   zmail.google.comN)zhttp://google.com:8000/mail/r5   r6   @  )zhttp://google.com:8000r;   )zhttps://google.com)httpsr6   N)zhttps://google.com:8000)r=   r6   r<   )z#http://user:password@127.0.0.1:1234)r5   	127.0.0.1  )z'http://google.com/foo=http://bar:42/bazr4   )z'http://google.com?foo=http://bar:42/bazr4   )z'http://google.com#foo=http://bar:42/bazr4   173.194.35.7r5   rA   N)zhttp://173.194.35.7rB   )zhttp://173.194.35.7/testrB   )zhttp://173.194.35.7:80r5   rA   P   )zhttp://173.194.35.7:80/testrC   )[2a00:1450:4001:c01::67]r5   rE   N)zhttp://[2a00:1450:4001:c01::67]rF   )z$http://[2a00:1450:4001:c01::67]/testrF   )z"http://[2a00:1450:4001:c01::67]:80r5   rE   rD   )z'http://[2a00:1450:4001:c01::67]:80/testrG   )z@http://[fedc:ba98:7654:3210:fedc:ba98:7654:3210]:8000/index.htmlr5   z)[fedc:ba98:7654:3210:fedc:ba98:7654:3210]r<   )z.http://[1080:0:0:0:8:800:200c:417a]/index.html)r5   [1080:0:0:0:8:800:200c:417a]N)zhttp://[3ffe:2a00:100:7031::1])r5   z[3ffe:2a00:100:7031::1]N)z"http://[1080::8:800:200c:417a]/foo)r5   z[1080::8:800:200c:417a]N)zhttp://[::192.9.5.5]/ipng)r5   z[::192.9.5.5]N)z+http://[::ffff:129.144.52.38]:42/index.html)r5   z[::ffff:129.144.52.38]*   )z"http://[2010:836b:4179::836b:4179])r5   z[2010:836b:4179::836b:4179]N)zhttp://[a::b%25zone]r5   z[a::b%zone]N)zhttp://[a::b%zone]rK   )zHTTP://GOOGLE.COM/mail/r4   )zGOogle.COM/mailr4   )zHTTP://GoOgLe.CoM:8000/mail/r;   )z%HTTP://user:password@EXAMPLE.COM:1234)r5   example.comr?   r@   )zHTTP://173.194.35.7rB   )z'HTTP://[2a00:1450:4001:c01::67]:80/testrG   )z@HTTP://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:8000/index.htmlrH   )z/HTTPS://[1080:0:0:0:8:800:200c:417A]/index.html)r=   rI   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                    [        U5      nUu  pEnUR                  =(       d    SU:X  d   eUR                  UR                  s=:X  a  U:X  d   e   eUR                  U:X  d   eg )Nr5   )r+   schemehostnamehostport)selfrN   rO   
parsed_urlrQ   rS   rT   s          5platform/gsutil/third_party/urllib3/test/test_util.pytest_scheme_host_portTestUtil.test_scheme_host_port   se     s^
-d!!+V666""joo======$&&&    c                2    [        S [        5       5      b   eg N)r*   setrU   s    rW   test_encode_invalid_chars_none'TestUtil.test_encode_invalid_chars_none   s    $T351999rZ   )
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                    [         R                  " [        5         [        U5        S S S 5        g ! , (       d  f       g = fr\   pytestraisesr   r+   rU   rN   s     rW   test_invalid_urlTestUtil.test_invalid_url   s$    $ ]]-.cN /..   0
>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]rj   )z[::1%25zone]rj   )[::1%25]rk   )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%23rl   c                <    [        U5      R                  nX2:X  d   eg)zEAssert parse_url normalizes the scheme/host, and only the scheme/hostNr+   rN   )rU   rN   expected_normalized_urlactual_normalized_urls       rW   test_parse_url_normalization%TestUtil.test_parse_url_normalization   s!    R !*# 2 2$???rZ   charr   !   c           
         S[        [        U5      5      SS  R                  S5      R                  5       -   n[	        SU SU SU SU 35      nU[        SSU-   S	S
U-   SU-   SU-   S9:X  d   eg )N%   zhttp://userz@example.com/pathz?queryz	#fragmentr5   userrL   z/pathqueryfragment)authrS   pathrz   r{   )hexordzfillupperr+   r)   )rU   rs   percent_charrN   s       rW   +test_control_characters_are_percent_encoded4TestUtil.test_control_characters_are_percent_encoded   s    c#d)nQR066q9??AB$0fTF)D6R
 c,&<'L(,.
 
 	
 
rZ   r3   r5   r6   /mail)rS   r}   r7   /mail/mailr8   r9   /r:   rS   zhttp://google.com?foo foo)rS   r}   rz   )r}   z#?/!google.com/?fooz?/!google.com/?foo)r}   r{   z/foo/foo?bar=bazzbar=baz)r}   rz   z /foo?bar=baz#banana?apple/orangezbanana?apple/orange)r}   rz   r{   z(/redirect?target=http://localhost:61020/redirectztarget=http://localhost:61020/zhttp://google.com:80/rD   )rS   rT   r}   zhttp://google.com:80)rS   rT   zhttp://foo:bar@localhost/zfoo:bar	localhost)r|   rS   r}   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:passwordrL   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)rS   r}   r{   zurl, expected_urlexpected_urlc                    [        U5      nX2:X  d   eUR                  UR                  s=:X  a  UR                  :X  d   e   eg r\   )r+   rR   rS   )rU   rN   r   returned_urls       rW   test_parse_urlTestUtil.test_parse_url5  sD    
 !~+++$$(9(9N\=N=NNNNNNrZ   c                &    XR                   :X  d   eg r\   )rN   rU   rN   r   s      rW   test_unparse_urlTestUtil.test_unparse_url>  s    &&&&&rZ   z/..z/./abc/./def/z	/abc/def/z/.z/./z&/abc/./.././d/././e/.././f/./../../ghiz/ghic                `    [        U5      nX2:X  d   eUR                  UR                  :X  d   eg r\   rn   )rU   rN   r   
actual_urls       rW   "test_parse_and_normalize_url_paths+TestUtil.test_parse_and_normalize_url_pathsB  s1     s^
)))~~!1!1111rZ   c                    [         R                  " [        5         [        S5        S S S 5        g ! , (       d  f       g = f)Nz[::1rc   r^   s    rW   test_parse_url_invalid_IPv6$TestUtil.test_parse_url_invalid_IPv6S  s#    ]]-.f /..ri   c                    [         R                  " [        5         [        S5        S S S 5        g ! , (       d  f       g = f)Nzhttps://www.google.com:-80/rc   r^   s    rW   test_parse_url_negative_port%TestUtil.test_parse_url_negative_portW  s$    ]]-.34 /..ri   c                >    [        S5      nUR                  S:X  d   eg )Nz!https://example.com:0000000000080rD   r+   rT   rf   s     rW   #test_parse_url_remove_leading_zeros,TestUtil.test_parse_url_remove_leading_zeros[  s    ;<xx2~~rZ   c                x    [        S5      nUR                  S:X  d   e[        S5      nUR                  S:X  d   eg )Nzhttps://example.com:0r   z https://example.com:000000000000r   rf   s     rW   test_parse_url_only_zeros"TestUtil.test_parse_url_only_zeros_  s8    /0xx1}}:;xx1}}rZ   c                N    [        SSS9n[        U5      UR                  :X  d   eg )Nr5   r6   r   )r)   strrN   )rU   Us     rW   test_Url_strTestUtil.test_Url_strf  s"    \*1vrZ   )	)r3   r   )r7   r   )r9   r   )r:   r   )r   r   )r   r   )r   z/?)r   r   )r   r   zurl, expected_request_uric                >    [        U5      nUR                  U:X  d   eg r\   )r+   request_uri)rU   rN   expected_request_urir   s       rW   test_request_uriTestUtil.test_request_uriv  s      ~''+????rZ   ))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))r3   r6   )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/foobarr6   )google.com:12345r   )r   Nzurl, expected_authorityc                :    [        U5      R                  U:X  d   eg r\   )r+   	authorityrU   rN   expected_authoritys      rW   test_authorityTestUtil.test_authority  s    ~''+====rZ   c                :    [        U5      R                  U:X  d   eg)z7Validate this matches the behavior of urlparse().netlocN)r   netlocr   s      rW   $test_authority_matches_urllib_netloc-TestUtil.test_authority_matches_urllib_netloc  s    
 }##'9999rZ   zurl, expected_netlocc                :    [        U5      R                  U:X  d   eg r\   )r+   r   )rU   rN   expected_netlocs      rW   test_netlocTestUtil.test_netloc  s    ~$$777rZ   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))rQ   r}   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)rS   r|   r}   rz   r{   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)rS   rT   r}   rz   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)rQ   rS   rT   r}   rz   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)rQ   r|   rS   r}   rz   r{   zhttps://@i'  [Fz"Tons of '@' causing backtracking 1)idzhttps://user:zuser:z%40i'  )rQ   r|   rS   z"Tons of '@' causing backtracking 2c                    USL a/  [         R                  " [        5         [        U5        S S S 5        g [        U5      U:X  d   eg ! , (       d  f       g = f)NFrc   r   s      rW   test_url_vulnerabilities!TestUtil.test_url_vulnerabilities  sE     5 12# 32 S>\111 32s   A
Ac                    [         R                  " [        5         [        S5        S S S 5        g ! , (       d  f       g = f)Ns   https://www.google.com/)rd   re   	TypeErrorr+   r^   s    rW   test_parse_url_bytes_type_error(TestUtil.test_parse_url_bytes_type_error  s#    ]]9%01 &%%ri   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                &    [        S0 UD6U:X  d   eg )N )r   )rU   kwargsexpecteds      rW   test_make_headersTestUtil.test_make_headers  s    t %f%111rZ   c                    [         R                  " S5      nUR                  5       S:X  d   eUR                  5       S:X  d   e[        US5        UR                  5       S:X  d   eg )N	   test datarZ      s   data)ioBytesIOreadr    rU   bodys     rW   test_rewind_bodyTestUtil.test_rewind_bodyL  sZ    zz,'yy{l*** yy{c!!! 	D!yy{g%%%rZ   c                    [         R                  " S5      nUR                  5         [        n[        R
                  " [        5         [        X5        S S S 5        g ! , (       d  f       g = f)Nr   )r   r   r   r   rd   re   r   r    )rU   r   body_poss      rW   test_rewind_body_failed_tell%TestUtil.test_rewind_body_failed_tellW  sA    zz,'		 ]]01' 211s   A
A*c                X   [         R                  " S5      nUR                  5         [        R                  " [
        5         [        US S9  S S S 5        [        R                  " [
        5         [        U[        5       S9  S S S 5        g ! , (       d  f       ND= f! , (       d  f       g = f)Nr   r   )r   r   r   rd   re   
ValueErrorr    objectr   s     rW   test_rewind_body_bad_position&TestUtil.test_rewind_body_bad_position`  sf    zz,'		 ]]:&t, ']]:&vx0 '& '&&&s   B
.B

B
B)c                     " S S[         R                  5      n[        R                  " [        5         [        U" 5       SS9  S S S 5        g ! , (       d  f       g = f)Nc                  "    \ rS rSrSSS jjrSrg)6TestUtil.test_rewind_body_failed_seek.<locals>.BadSeekik  c                    [         er\   )OSError)rU   offsetwhences      rW   seek;TestUtil.test_rewind_body_failed_seek.<locals>.BadSeek.seekl  s    rZ   r   N)r   )r   intr   r  returnztyping.NoReturn)__name__
__module____qualname____firstlineno__r   __static_attributes__r   rZ   rW   BadSeekr   k  s     rZ   r  rx   r   )r   StringIOrd   re   r   r    )rU   r  s     rW   test_rewind_body_failed_seek%TestUtil.test_rewind_body_failed_seekj  s9    	bkk 	 ]]01	A. 211s   A
Ac                    [        [        R                  S9n[        R                  " S5      nXR                  ;   d   eUR                  S5        UR                  U5        g )N)levelurllib3zTesting add_stderr_logger)r   loggingINFO	getLoggerhandlersdebugremoveHandler)rU   handlerloggers      rW   test_add_stderr_loggerTestUtil.test_add_stderr_loggerr  sK    #',,7""9-//)))01W%rZ   c                p   [         R                  " SS9 n[        5         [         R                  " S[        5        [         R
                  " S[        5        [        U5      S:X  d   e[        5         [         R
                  " S[        5        [        U5      S:X  d   e S S S 5        g ! , (       d  f       g = f)NT)recorddefaultzThis is a test.r.   )warningscatch_warningsr/   simplefilterr   warnlenr   )rU   ws     rW   test_disable_warningsTestUtil.test_disable_warningsz  s{    $$D1Q!!)-CDMM+-CDq6Q;;MM+-CDq6Q;; 211s   BB''
B5c                X    [         Ul        UR                  5         [         U-   Ul        U$ )z*Make some time pass for the timeout object)TIMEOUT_EPOCHreturn_valuestart_connect)rU   secondstimeout	time_mocks       rW   _make_time_passTestUtil._make_time_pass  s*     "/	!.!8	rZ   zkwargs, messagetotalz	less thanrx   )connectr-  r   r/  zcannot be a booleanzless than or equalzint, float or Nonez1.0c                    [         R                  " [        US9   [        S0 UD6  S S S 5        g ! , (       d  f       g = f)Nmatchr   )rd   re   r   r(   )rU   r   messages      rW   test_invalid_timeoutsTestUtil.test_invalid_timeouts  s)      ]]:W5f 655   /
=ztime.monotonicc                   [        SS9nU R                  SX!S9nUR                  S:X  d   eUR                  S:X  d   e[        SSS9nUR                  S:X  d   e[        5       nUR                  [        :X  d   e[        SSS	9nU R                  S
X!S9nUR                  S
:X  d   e[        SSS	9nU R                  SX!S9nUR                  S:X  d   e[        SSS	9nUR                  S:X  d   e[        S S S S9nUR                  b   eUR                  b   eUR
                  b   e[        S
5      nUR
                  S
:X  d   eg )N   r-  r   )r(  r)  r*  rx   )r-  r/  
      )r-  r   r   )r-  r   r/  )r(   r+  read_timeoutconnect_timeoutr'   r-  rU   time_monotonicr)  s      rW   test_timeoutTestUtil.test_timeout  s   " &&w ' 
 ##q(((&&!+++1-&&!+++)&&*:::: +&&w ' 
 ##q((( +&&w ' 
 ##q(((+##q(((4>&&...##+++}}$$$!*}}!!!rZ   c                    [        5       n[        SSS9   UR                  S:X  d   e SSS5        [        SSS9   UR                  S:X  d   e SSS5        g! , (       d  f       N5= f! , (       d  f       g= f)z>The timeout default is resolved when read_timeout is accessed.z&urllib3.util.timeout.getdefaulttimeoutrx   )r&  Nr8  )r(   r   r<  rU   r)  s     rW   test_timeout_default_resolve%TestUtil.test_timeout_default_resolve  sl    );!L''1,,, M ;!L''1,,, ML ML MLs   AA)
A&)
A7c                t    [        SSSS9n[        U5      S:X  d   e[        SS SS9n[        U5      S:X  d   eg )Nr.   rx   r8  )r/  r   r-  z#Timeout(connect=1, read=2, total=3)z&Timeout(connect=1, read=None, total=3))r(   r   rC  s     rW   test_timeout_strTestUtil.test_timeout_str  sD    !!157|DDDD!$a87|GGGGrZ   c                   [         Ul        [        SS9n[        R                  " [
        5         UR                  5         S S S 5        UR                  5         [        R                  " [
        5         UR                  5         S S S 5        [         S-   Ul        UR                  5       S:X  d   e[         S-   Ul        UR                  5       S:X  d   eg ! , (       d  f       N= f! , (       d  f       Nh= f)Nr8  r9  rx   %   )r%  r&  r(   rd   re   r   get_connect_durationr'  r>  s      rW   test_timeout_elapsedTestUtil.test_timeout_elapsed  s    &3#"]],-((* . 	]],-!!# . '4a&7#++-222&3b&8#++-333 .- .-s   C2C%
C"%
C3c                F     " S S5      n[        U" 5       5      (       d   eg )Nc                  (    \ rS rSr\SS j5       rSrg)ETestUtil.test_is_fp_closed_object_supports_closed.<locals>.ClosedFilei  c                    gNTr   r^   s    rW   closedLTestUtil.test_is_fp_closed_object_supports_closed.<locals>.ClosedFile.closed      rZ   r   Nr  ztyping.Literal[True])r  r  r  r  propertyrS  r  r   rZ   rW   
ClosedFilerP         rZ   rX  r   )rU   rX  s     rW   (test_is_fp_closed_object_supports_closed1TestUtil.test_is_fp_closed_object_supports_closed  !    	 	
 JL))))rZ   c                F     " S S5      n[        U" 5       5      (       d   eg )Nc                  (    \ rS rSr\SS j5       rSrg)ATestUtil.test_is_fp_closed_object_has_none_fp.<locals>.NoneFpFilei  c                    g r\   r   r^   s    rW   fpDTestUtil.test_is_fp_closed_object_has_none_fp.<locals>.NoneFpFile.fp  rU  rZ   r   Nr  Noner  r  r  r  rW  ra  r  r   rZ   rW   
NoneFpFiler_    rY  rZ   rf  r   )rU   rf  s     rW   $test_is_fp_closed_object_has_none_fp-TestUtil.test_is_fp_closed_object_has_none_fp  r\  rZ   c                F     " S S5      n[        U" 5       5      (       a   eg )Nc                  (    \ rS rSr\SS j5       rSrg)8TestUtil.test_is_fp_closed_object_has_fp.<locals>.FpFilei  c                    grR  r   r^   s    rW   ra  ;TestUtil.test_is_fp_closed_object_has_fp.<locals>.FpFile.fp  rU  rZ   r   NrV  re  r   rZ   rW   FpFilerk    rY  rZ   rn  r   )rU   rn  s     rW   test_is_fp_closed_object_has_fp(TestUtil.test_is_fp_closed_object_has_fp  s$    	 	
  )))))rZ   c                     " S S5      n[         R                  " [        5         [        U" 5       5        S S S 5        g ! , (       d  f       g = f)Nc                      \ rS rSrSrg)STestUtil.test_is_fp_closed_object_has_neither_fp_nor_closed.<locals>.NotReallyAFilei  r   N)r  r  r  r  r  r   rZ   rW   NotReallyAFilers    s    rZ   rt  )rd   re   r   r   )rU   rt  s     rW   2test_is_fp_closed_object_has_neither_fp_nor_closed;TestUtil.test_is_fp_closed_object_has_neither_fp_nor_closed  s1    	 	 ]]:&)* '&&s	   ?
Ac                v    [        SS5         [        S5      (       a   e S S S 5        g ! , (       d  f       g = f)Nsocket.has_ipv6F::1)r   r   r^   s    rW   !test_has_ipv6_disabled_on_compile*TestUtil.test_has_ipv6_disabled_on_compile  s-    $e, ''''' -,,s   *
8c                   [        SS5         [        S5       nUR                  n[        [        S5      S9Ul        [        S5      (       a   e S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)Nrx  Tsocket.socketzNo IPv6 here!)side_effectry  )r   r&  r   	Exceptionbindr   rU   r   instances      rW   test_has_ipv6_enabled_but_fails(TestUtil.test_has_ipv6_enabled_but_fails  sd    $d+'4,, $?1K L$U+++++ ( ,+'' ,+s"   A26A!A2!
A/	+A22
B c                    [        SS5         [        S5       nUR                  nSUR                  l        [        S5      (       d   e S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)Nrx  Tr}  ry  )r   r&  r  r   r  s      rW   !test_has_ipv6_enabled_and_working*TestUtil.test_has_ipv6_enabled_and_working  s\    $d+'4,,-1* '''' ( ,+'' ,+s"   A,0A
A,
A)	%A,,
A:c                    [        SS5         [        5       [        R                  :X  d   e S S S 5        g ! , (       d  f       g = f)N urllib3.util.connection.HAS_IPV6T)r   r   socket	AF_UNSPECr^   s    rW   test_ip_family_ipv6_enabled$TestUtil.test_ip_family_ipv6_enabled  s0    5t<%'6+;+;;;; =<<	   6
Ac                    [        SS5         [        5       [        R                  :X  d   e S S S 5        g ! , (       d  f       g = f)Nr  F)r   r   r  AF_INETr^   s    rW   test_ip_family_ipv6_disabled%TestUtil.test_ip_family_ipv6_disabled  s.    5u=%'6>>999 >==r  headerss   fooNc                    [         R                  " [        5         [        U5        S S S 5        g ! , (       d  f       g = fr\   )rd   re   r   r!   )rU   r  s     rW   <test_assert_header_parsing_throws_typeerror_with_non_headersETestUtil.test_assert_header_parsing_throws_typeerror_with_non_headers"  s$     ]]9%!'* &%%ri   c                (    [        S S S S9(       a   eg )N)	proxy_urlproxy_configdestination_schemer   r^   s    rW   -test_connection_requires_http_tunnel_no_proxy6TestUtil.test_connection_requires_http_tunnel_no_proxy)  s     2$
 	
 
 
rZ   c                    [        S5      n[        S SS S S9nSn[        XU5      (       a   eSn[        XU5      (       d   eg )Nzhttp://proxy:8080Fssl_contextuse_forwarding_for_httpsassert_hostnameassert_fingerprintr5   r=   r+   r   r   rU   proxyr  r  s       rW   /test_connection_requires_http_tunnel_http_proxy8TestUtil.test_connection_requires_http_tunnel_http_proxy.  sd    -."%* #	
 $2!3
 
 	
 
 %.uDVWWWWrZ   c                \    [        S5      n[        S SS S S9nSn[        XU5      (       a   eg )Nzhttps://proxy:8443Fr  r5   r  r  s       rW   0test_connection_requires_http_tunnel_https_proxy9TestUtil.test_connection_requires_http_tunnel_https_proxy>  sM    ./"%* #	
 $2!3
 
 	
 
 
rZ   c                    SSK Jn  [        R                  " 5       nUR	                  S5        UR                  S5        [        UR                  U5      5        g )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


)r5   r  r   r   writer   r!   parse_headers)rU   r  
header_msgs      rW   0test_assert_header_parsing_no_error_on_multipart9TestUtil.test_assert_header_parsing_no_error_on_multipartK  sD    ZZ\
,	
 	f22:>?rZ   rS   )z
.localhostz...@ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttc                    [         R                  " [        SU S3S9   [        US45        S S S 5        g ! , (       d  f       g = f)NzFailed to parse: 'z', label empty or too longr1  rD   )rd   re   r   r   )rU   rS   s     rW   /test_create_connection_with_invalid_idna_labels8TestUtil.test_create_connection_with_invalid_idna_labelsX  s<    ]]&tf,FG
 tRj)	
 
 
s	   5
A)za.example.comz
localhost.z[dead::beef]z[dead::beef%en5]z[dead::beef%en5.]zsocket.getaddrinfor}  c                L    S/Ul         [        5       Ul         [        US45        g )N)NNNNNrD   )r&  r   r   )rU   r  getaddrinforS   s       rW   -test_create_connection_with_valid_idna_labels6TestUtil.test_create_connection_with_valid_idna_labels`  s&     %C#C "f4*%rZ   c                    / Ul         [        R                  " [        SS9   [	        S5        S S S 5        g ! , (       d  f       g = f)Nz!getaddrinfo returns an empty listr1  rL   rD   )r&  rd   re   r   r   rU   r  s     rW   test_create_connection_error%TestUtil.test_create_connection_errors  s/    #% ]]7*MN12 ONNs	   6
Ac                    [         R                  " 5       Ul        [        R                  " [         R                  5         [        S5        S S S 5        g ! , (       d  f       g = f)Nr  )r  gaierrorr~  rd   re   r   r  s     rW   test_dnsresolver_forced_error&TestUtil.test_dnsresolver_forced_errory  s6    "(//"3]]6??+12 ,++s   A
A"c                    [         R                  " [        R                  5         [	        S5        S S S 5        g ! , (       d  f       g = f)N)zbadhost.invalidrD   )rd   re   r  r  r   r^   s    rW   test_dnsresolver_expected_error(TestUtil.test_dnsresolver_expected_error  s)    ]]6??+ 56	 ,++s	   :
Ac                    SnUR                   UR                  UR                  SU4/Ul        [	        5       =Ul        n[        S5        UR                  S   S   S:X  d   eUR                  R                  U5        g )N)za::brD   r   rJ   r   )
a::b%ifacerD   r   r  )	AF_INET6SOCK_STREAMIPPROTO_TCPr&  r   r   	call_argsr/  assert_called_once_with)rU   r  r  fake_scoped_sa6	fake_socks        rW   'test_create_connection_with_scoped_ipv60TestUtil.test_create_connection_with_scoped_ipv6  s     . """"$
  +4+5i,-$$Q'*l:::11/BrZ   zinput,params,expectedtests   testencodingzutf-8asciic                (    [        U40 UD6U:X  d   eg r\   )r-   rU   inputparamsr   s       rW   test_to_strTestUtil.test_to_str  s     e&v&(222rZ   c                    [         R                  " [        SS9   [        S5        S S S 5        g ! , (       d  f       g = fNznot expecting type intr1  r.   )rd   re   r   r-   r^   s    rW   test_to_str_errorTestUtil.test_to_str_error  s%    ]]9,DE1I FEEr6     és   éc                (    [        U40 UD6U:X  d   eg r\   )r,   r  s       rW   test_to_bytesTestUtil.test_to_bytes  s     ((H444rZ   c                    [         R                  " [        SS9   [        S5        S S S 5        g ! , (       d  f       g = fr  )rd   re   r   r,   r^   s    rW   test_to_bytes_errorTestUtil.test_to_bytes_error  s%    ]]9,DEQK FEEr6  r   )rN   r   rO   ztuple[str, str, int | None]r  rd  rc  )rN   r   r  rd  )rN   r   ro   r   r  rd  )rs   r   r  rd  )rN   r   r   r)   r  rd  )rN   r   r   r   r  rd  )rN   r   r   
str | Noner  rd  )rN   r   r   r  r  rd  )rN   r   r   ztyping.Literal[False] | Urlr  rd  )r   zdict[str, bool | str]r   dict[str, str]r  rd  )r(  r  r)  r(   r*  r   r  r(   )r   zdict[str, int | bool]r3  r   r  rd  )r?  r   r  rd  )r  zbytes | object | Noner  rd  )rS   r   r  rd  )r  r   r  r   rS   r   r  rd  )r  r   r  rd  )r  r   r  r   r  rd  )r  bytes | strr  r  r   r   r  rd  )r  r  r  r  r   bytesr  rd  )Vr  r  r  r  url_host_maprd   markparametrizerX   r_   rg   rq   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+  r4  r   r@  rD  rG  rL  rZ  rg  ro  ru  rz  r  r  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  ).0ir  us   0000rW   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&0aaDOOF4K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 [[LL"D)"$:;!|XZ0
 LL"D)"$56!|WY/
 LL"D)"$78 {HJ/
 LL"D)"N3 {GI.
  +.?-KL%03Di2PQLL$(A$:(S!|XZ0
 LL$(A$5XN!|WY/
 LL$(A$7xP {HJ/
 LL$(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   4`'/`.`.r1   c            	         \ rS rSrSr\R                  R                  SS\R                  4\R                  \R                  4\R                  \R                  4S\R                  4S\R                  4/5            SS j5       r\R                  R                  S\R                  \R                  4S	\R                  4S
\R                  4\R                  \R                  4/5      SS j5       rSS jr\" S5          SS j5       rSS jrSS jrSS jr      SS jrSS jrSS jr\R                  R                  S/ SQ5                    SS j5       rSrg)TestUtilSSLi  z#Test utils that use an SSL backend.zcandidate, requirementsNREQUIREDCERT_REQUIREDc                &    [        U5      U:X  d   eg r\   )r$   )rU   	candidaterequirementss      rW   test_resolve_cert_reqs"TestUtilSSL.test_resolve_cert_reqs  s     !+|;;;rZ   zcandidate, versionPROTOCOL_TLSv1TLSv1c                &    [        U5      U:X  d   eg r\   )r%   )rU   r   versions      rW   test_resolve_ssl_version$TestUtilSSL.test_resolve_ssl_version  s     #9-888rZ   c                x    [        5       n[        5       n[        X!SS9  UR                  R                  SS 5        g )Nz/path/to/certfile)r  sockcertfile)r   r&   load_cert_chainr  rU   r  mock_contexts      rW   )test_ssl_wrap_socket_loads_the_cert_chain5TestUtilSSL.test_ssl_wrap_socket_loads_the_cert_chain  s8    v$<O	
 	$$<<=PRVWrZ   z(urllib3.util.ssl_.create_urllib3_contextc                j    [        5       n[        U[        R                  S9  UR	                  S SS S9  g )N)	cert_reqsrx   )ciphers)r   r&   sslr  r  )rU   create_urllib3_contextr  s      rW   (test_ssl_wrap_socket_creates_new_context4TestUtilSSL.test_ssl_wrap_socket_creates_new_context  s0     #*;*;<66tQ6MrZ   c                |    [        5       n[        5       n[        USUS9  UR                  R                  SS S 5        g )Nz/path/to/pem)r  ca_certsr  r   r&   load_verify_locationsr  r  s      rW   +test_ssl_wrap_socket_loads_verify_locations7TestUtilSSL.test_ssl_wrap_socket_loads_verify_locations  s8    vL>PVW**BBD$	
rZ   c                |    [        5       n[        5       n[        USUS9  UR                  R                  S SS 5        g )Nz/path/to/pems)r  ca_cert_dirr  r  r  s      rW   2test_ssl_wrap_socket_loads_certificate_directories>TestUtilSSL.test_ssl_wrap_socket_loads_certificate_directories  s<    v$/	
 	**BB/4	
rZ   c                |    [        5       n[        5       n[        USUS9  UR                  R                  S S S5        g )NzTOTALLY PEM DATA)r  ca_cert_datar  r  r  s      rW   +test_ssl_wrap_socket_loads_certificate_data7TestUtilSSL.test_ssl_wrap_socket_loads_certificate_data  s>    v$3EF	
 	**BB$*	
rZ   c                    [        5       n[        S5       n[        UUUS9  S S S 5        X44$ ! , (       d  f       UW4$ = f)Nzwarnings.warn)r  r  server_hostname)r   r   r&   )rU   r  r(  r  r  s        rW   _wrap_socket_and_mock_warn&TestUtilSSL._wrap_socket_and_mock_warn  sL     v?#t( / $ !! $# T!!s   -
>c                    [        5       nU R                  US5      u  p#UR                  R                  USS9  UR	                  5         g)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rU   r  contextr  s       rW   +test_ssl_wrap_socket_sni_ip_address_no_warn7TestUtilSSL.test_ssl_wrap_socket_sni_ip_address_no_warn  sB    v77iH33D)3T rZ   c                    [        5       nU R                  US5      u  p#UR                  R                  USS9  UR	                  5         g)z@Test that a warning is not made if server_hostname is not given.Nr,  r-  r0  s       rW   %test_ssl_wrap_socket_sni_none_no_warn1TestUtilSSL.test_ssl_wrap_socket_sni_none_no_warn$  sB    v77dC33D$3O rZ   zgopenssl_version, openssl_version_number, implementation_name, version_info, pypy_version_info, reliable))OpenSSL 1.1.1cpythonr8  	   r8  NT)r7   r9  r:  NT)r7  r<  pypy)r8  r;  r;  )r;  r8  r;  F)r7  r8  r=  )r8        )r;  r8  r>  T)r7  r8  r9  r8  r;  rx   NT)zLibreSSL 2.8.3r8  r9  )r8  r:  r   NF)zOpenSSL 1.1.0r<  r9  r@  NFc                .    [        UUUUU5      U:X  d   eg r\   )r#   )rU   openssl_versionopenssl_version_numberimplementation_nameversion_infopypy_version_inforeliables          rW   ,test_is_has_never_check_common_name_reliable8TestUtilSSL.test_is_has_never_check_common_name_reliable+  s/    8 5&#! 		
rZ   r   )r   zint | str | Noner  r  r  rd  )r   z	int | strr  r  r  rd  rc  )r  zmock.MagicMockr  rd  )r  r}  r(  r  r  ztuple[Mock, MagicMock])rB  r   rC  r  rD  r   rE  r"   rF  z_TYPE_VERSION_INFO | NonerG  boolr  rd  )r  r  r  r  __doc__rd   r  r  r  r  	CERT_NONEr  r  PROTOCOL_SSLv23r  r  r   r  r  r!  r%  r)  r2  r5  rH  r  r   rZ   rW   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
 
 

%$
rZ   r  idnar  c                  F    \ rS rSr\SS j5       r\SS j5       rSS jrSrg)TestUtilWithoutIdnaiV  c                    [         R                  R                  SS 5        [        R	                  5         [         R
                  R                  S[        5        g )NrN  r   )sysmodulespopmodule_stashstash	meta_pathinsertidna_blockerclss    rW   setup_classTestUtilWithoutIdna.setup_classW  s4    %Q-rZ   c                r    [         R                  R                  [        5        [        R                  5         g r\   )rR  rW  removerY  rU  rT  rZ  s    rW   teardown_class"TestUtilWithoutIdna.teardown_class^  s     \*rZ   c                    Sn[         R                  " [        SU 3S9   [        U5        S S S 5        g ! , (       d  f       g = f)Nra   zFailed to parse: r1  rc   rf   s     rW   test_parse_url_without_idna/TestUtilWithoutIdna.test_parse_url_without_idnac  s2    !]]-7H5NOcN POOs	   4
Ar   Nrc  )	r  r  r  r  classmethodr\  r`  rc  r  r   rZ   rW   rP  rP  V  s-    . .  rZ   rP  )K
__future__r   r   r  r  r  rR  typingr  	itertoolsr   r  r   r   r   r   r	   r
   unittestr   unittest.mockr   r   r   urllib.parser   rd   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  rY  rU  rP  r   rZ   rW   <module>rw     s    " 	   
 
    U U  0 0 !  7 *  & T T > G G 7  ; B B . 
 P PfJ
 J
Z V$9% rZ   