Ϫf.dZddlmZddlmZddlmZGddejZGddZ Gd d e ejZ Gd d e ejZ Gd de ejZ y)z) Tests L{twisted.web.client} helper APIs )urlparse)unittest)clientceZdZdZdZdZy) URLJoinTestsz' Tests for L{client._urljoin}. c|jtjddd|jtjddd|jtjdddy)z L{client._urljoin} does not include a fragment identifier in the resulting URL if neither the base nor the new path include a fragment identifier. http://foo.com/bar/quuxshttp://foo.com/quuxshttp://foo.com/bar#s/quux#N assertEqualr_urljoinselfs A/usr/lib/python3/dist-packages/twisted/web/test/test_webclient.pytest_noFragmentszURLJoinTests.test_noFragmentssh  OO18 <>T   OO2H =?U   OO19 =?U c|jtjddd|jtjddd|jtjdddy)a L{client._urljoin} preserves the fragment identifier from either the new path or the base URL respectively, as specified in the HTTP 1.1 bis draft. @see: U{https://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-22#section-7.1.2} shttp://foo.com/bar#fragr shttp://foo.com/quux#fragr s /quux#frag2shttp://foo.com/quux#frag2Nr rs rtest_preserveFragmentsz#URLJoinTests.test_preserveFragments$sh  OO6 A '   OO1> B (   OO6 G ( rN)__name__ __module__ __qualname____doc__rrrrrrs  rrcteZdZdZdZ ddZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZy)URITestsa Abstract tests for L{twisted.web.client.URI}. Subclass this and L{unittest.TestCase}. Then provide a value for C{host} and C{uriHost}. @ivar host: A host specification for use in tests, must be L{bytes}. @ivar uriHost: The host specification in URI form, must be a L{bytes}. In most cases this is identical with C{host}. IPv6 address literals are an exception, according to RFC 3986 section 3.2.2, as they need to be enclosed in brackets. In this case this variable is different. c |j|jt|j|jt|j|t|j d||j d|jS)a Replace the string "HOST" in C{template} with this test's host. Byte strings Python between (and including) versions 3.0 and 3.4 cannot be formatted using C{%} or C{format} so this does a simple replace. @type template: L{bytes} @param template: A string containing "HOST". @rtype: L{bytes} @return: A string where "HOST" has been replaced by C{self.host}. sHOST)assertIsInstancehostbytesuriHostassertInreplace)rtemplates r makeURIStringzURITests.makeURIStringIsa dii/ dllE2 h. gx(66rc |j|||||||| f|j|j|j|j|j |j |j|jfy)aU Assert that all of a L{client.URI}'s components match the expected values. @param uri: U{client.URI} instance whose attributes will be checked for equality. @type scheme: L{bytes} @param scheme: URI scheme specifier. @type netloc: L{bytes} @param netloc: Network location component. @type host: L{bytes} @param host: Host name. @type port: L{int} @param port: Port number. @type path: L{bytes} @param path: Hierarchical path. @type params: L{bytes} @param params: Parameters for last path segment, defaults to C{b''}. @type query: L{bytes} @param query: Query string, defaults to C{b''}. @type fragment: L{bytes} @param fragment: Fragment identifier, defaults to C{b''}. N) r schemenetlocrportpathparamsqueryfragment) rurir&r'rr(r)r*r+r,s rassertURIEqualszURITests.assertURIEquals]sdD  VT4vuh G       rctjj|jd}|j d|j tjj|jd}|j d|j tjj|jd}|j d|j y)z L{client.URI.fromBytes} by default assumes port 80 for the I{http} scheme and 443 for the I{https} scheme. http://HOSTPs http://HOST: https://HOSTiNrURI fromBytesr$r r(rr-s rtest_parseDefaultPortzURITests.test_parseDefaultPorts jj""4#5#5n#EF SXX&jj""4#5#5o#FG SXX&jj""4#5#5o#FG chh'rc4tjj|jdd}|j d|j tjj|jdd}|j d|j y)z L{client.URI.fromBytes} accepts a C{defaultPort} parameter that overrides the normal default port logic. r0) defaultPortr2Nr3r6s rtest_parseCustomDefaultPortz$URITests.test_parseCustomDefaultPorts| jj""4#5#5n#ESW"X sxx(jj""    /T#  sxx(rctjj|jd}|j d|j |j |j |j |j |jdz|jtjj|jd}|j |j|jy)zj Parsing a I{URI} splits the network location component into I{host} and I{port}. shttp://HOST:5144r9s:5144s http://HOST N) rr4r5r$r r(rr r'r6s rtest_netlocHostPortzURITests.test_netlocHostPorts jj""4#5#56I#JK sxx( CHH- 0#**=jj""4#5#5o#FG szz2rc|jd}tjj|}|j |d|j |j dd|j||jy)z/ Parse the path from a I{URI}. shttp://HOST/foo/barhttpr1/foo/barr&r'rr(r)N r$rr4r5r.r rr toBytesrr-parseds r test_pathzURITests.test_pathso  !78%%c*  <<   fnn./rc|jd}tjj|}|j |d|j |j dd|j||jy)zL The path of a I{URI} that has no path is the empty string. r0r?r1rrANrBrDs r test_noPathzURITests.test_noPathsn  0%%c*  <<   fnn./rc|jd}|jtjj |d|j |j ddy)zE The path of a I{URI} with an empty path is C{b'/'}. http://HOST/r?r1/rAN)r$r.rr4r5r rr6s rtest_emptyPathzURITests.test_emptyPathsP  1  JJ  %<<  rc |jd}tjj|}|j |d|j |j ddd|j||jy)z8 Parse I{URI} parameters from a I{URI}. shttp://HOST/foo/bar;paramr?r1r@param)r&r'rr(r)r*NrBrDs r test_paramzURITests.test_paramsr  !=>%%c*  <<   fnn./rc |jd}tjj|}|j |d|j |j dddd|j||jy) z7 Parse the query string from a I{URI}. s!http://HOST/foo/bar;param?a=1&b=2r?r1r@rNa=1&b=2)r&r'rr(r)r*r+NrBrDs r test_queryzURITests.test_querysu  !EF%%c*  <<   fnn./rc |jd}tjj|}|j |d|j |j ddddd |j||jy ) z> Parse the fragment identifier from a I{URI}. s&http://HOST/foo/bar;param?a=1&b=2#fragr?r1r@rNrQsfrag)r&r'rr(r)r*r+r,NrBrDs r test_fragmentzURITests.test_fragmentsx  !JK%%c*  <<   fnn./rctjj|jd}|j d|j y)zn L{client.URI.originForm} produces an absolute I{URI} path including the I{URI} path. shttp://HOST/foos/fooNrr4r5r$r originFormr6s rtest_originFormzURITests.test_originForms8 jj""4#5#56H#IJ #..1rctjj|jd}|j d|j y)z L{client.URI.originForm} produces an absolute I{URI} path including the I{URI} path, parameters and query string but excludes the fragment identifier. shttp://HOST/foo;param?a=1#frags/foo;param?a=1NrVr6s rtest_originFormComplexzURITests.test_originFormComplex s> jj""   @ A  *CNN;rctjj|jd}|j d|j y)zp L{client.URI.originForm} produces a path of C{b'/'} when the I{URI} specifies no path. r0rKNrVr6s rtest_originFormNoPathzURITests.test_originFormNoPath+s7 jj""4#5#5n#EF s~~.rctjj|jd}|j d|j y)zv L{client.URI.originForm} produces a path of C{b'/'} when the I{URI} specifies an empty path. rJrKNrVr6s rtest_originFormEmptyPathz!URITests.test_originFormEmptyPath3s7 jj""4#5#5o#FG s~~.rc\|jd}|jd}t|tjj |}|j |jt|j |jt|j |jty)z L{client.URI.fromBytes} parses the scheme, host, and path elements into L{bytes}, even when passed an URL which has previously been passed to L{urlparse} as a L{unicode} string. shttp://HOST/pathasciiN) r$decoderrr4r5rr&rrr))r goodInputbadInputr-s r test_externalUnicodeInterferencez)URITests.test_externalUnicodeInterference;s} &&':; ##G,jj""9- cjj%0 chh. chh.rN)rrr)rrrrr$r.r7r;r=rFrHrLrOrRrTrXrZr\r^rdrrrrr:s_ 7*VY. ` ( ) 30 0  0"0$0&2 <// /rrceZdZdZdxZZy)URITestsForHostnamez> Tests for L{twisted.web.client.URI} with host names. s example.comNrrrrr rrrrrfrfJs$#GdrrfceZdZdZdxZZy)URITestsForIPv4zG Tests for L{twisted.web.client.URI} with IPv4 host addresses. s 192.168.1.67NrgrrrririRs%$GdrriceZdZdZdZdZdZy)URITestsForIPv6z Tests for L{twisted.web.client.URI} with IPv6 host addresses. IPv6 addresses must always be surrounded by square braces in URIs. No attempt is made to test without. sfe80::20c:29ff:fea4:c60s[fe80::20c:29ff:fea4:c60]ctjjd}|j|jd|j|j d|j|j dy)z Brackets around IPv6 addresses are stripped in the host field. The host field is then exported with brackets in the output of L{client.URI.toBytes}. shttp://[::1]:80/index.htmls::1s[::1]:80N)rr4r5r rr'rCr6s r"test_hostBracketIPv6AddressLiteralz2URITestsForIPv6.test_hostBracketIPv6AddressLiteralesX jj""#@A 6* [1 (EFrN)rrrrrr rmrrrrkrkZs &D*G GrrkN) r urllib.parser twisted.trialr twisted.webrTestCaserrrfrirkrrrrrss ""( 8$$( VM/M/`$(H$5$5$%h 1 1%Gh 1 1Gr