o b;@s:dZddgZddlmZddlmZddlmZmZddl m Z ddl m Z m Z dd lmZdd lmZmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlm Z m!Z!m"Z"dddDZ#dZ$dde#DZ%e$&dZ'eeGdddZ(GdddZ)GdddZ*Gdddej+Z,dS)z2 Helpers related to HTTP requests, used by tests. DummyChannel DummyRequest)BytesIO)Optional) implementerverify)Version) IPv4Address IPv6Address)Deferred)IAddress ISSLTransport)Clock) deprecated)unittest)FOUND)Headers)Resource) NOT_DONE_YETSessionSitecCsg|]}d|dqS)Foobar).0lwrr@/usr/lib/python3/dist-packages/twisted/web/test/requesthelper.py sr)  z zFoo barcCsg|]}|dqS)ascii)encode)r componentrrrr s r c@seZdZdZdS) NullAddressz/ A null implementation of L{IAddress}. N)__name__ __module__ __qualname____doc__rrrrr#&sr#c@seZdZGdddZeeGdddeZeeZ d,ddZ dd Z d d Z d d Z ddZddZddZddZddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+ZdS)-rc@sVeZdZdZdZdddZddZdd Zd d Zd d Z ddZ ddZ ddZ dS)zDummyChannel.TCPPFNcCs,|dur tddd}||_t|_g|_dS)NTCPz 192.168.1.1i80)r _peerrwritten producersselfpeerrrr__init__2s   zDummyChannel.TCP.__init__cC|jSN)r*r.rrrgetPeer9szDummyChannel.TCP.getPeercCs(t|ts td||j|dS)Nz)Can only write bytes to a transport, not ) isinstancebytes TypeErrorr+writer.datarrrr8<s zDummyChannel.TCP.writecCs|D]}||qdSr2)r8)r.iovecr:rrr writeSequenceAs zDummyChannel.TCP.writeSequencecCstdd|jS)Nr)z10.0.0.1)r portr3rrrgetHostEzDummyChannel.TCP.getHostcCs|j||fdSr2)r,appendr.producer streamingrrrregisterProducerHsz!DummyChannel.TCP.registerProducercCdSr2rr3rrrunregisterProducerKz#DummyChannel.TCP.unregisterProducercC d|_dS)NT) disconnectedr3rrrloseConnectionN zDummyChannel.TCP.loseConnectionr2) r$r%r&r=rIr0r4r8r<r>rDrFrJrrrrr).s  r)c@sDeZdZddZddZddZddZd d Zd d Zd dZ dS)zDummyChannel.SSLcCrEr2rr3rrrabortConnectionSz DummyChannel.SSL.abortConnectioncCrEr2rr3rrrgetTcpKeepAliveWrMz DummyChannel.SSL.getTcpKeepAlivecCrEr2rr3rrr getTcpNoDelay[rMzDummyChannel.SSL.getTcpNoDelaycCrEr2rr3rrrloseWriteConnection_rMz$DummyChannel.SSL.loseWriteConnectioncCrEr2rr.enabledrrrsetTcpKeepAlivecrMz DummyChannel.SSL.setTcpKeepAlivecCrEr2rrQrrr setTcpNoDelaygrMzDummyChannel.SSL.setTcpNoDelaycCrEr2rr3rrrgetPeerCertificatekrMz#DummyChannel.SSL.getPeerCertificateN) r$r%r&rLrNrOrPrSrTrUrrrrSSLQs rVNcCs|||_dSr2)r) transportr-rrrr0qzDummyChannel.__init__cCrEr2r)r.requestrrr requestDonetrGzDummyChannel.requestDonecCsL|d|d|d}|g}|dd|D|d|j|dS)N  css$|] \}}|d|dVqdS)s: r\Nr)rnamevaluerrr zs"z,DummyChannel.writeHeaders..)extendr@rWr<)r.versioncodereasonheaders response_lineheaderSequencerrr writeHeadersws  zDummyChannel.writeHeaderscC |jSr2)rWr4r3rrrr4~rKzDummyChannel.getPeercCrhr2)rWr>r3rrrr>rKzDummyChannel.getHostcCs|j||dSr2)rWrDrArrrrDszDummyChannel.registerProducercC|jdSr2)rWrFr3rrrrFr?zDummyChannel.unregisterProducercC|j|dSr2)rWr8r9rrrr8rXzDummyChannel.writecCrjr2)rWr<)r.r;rrrr<rXzDummyChannel.writeSequencecCrir2)rWrJr3rrrrJr?zDummyChannel.loseConnectioncCrEr2rr3rrr endRequestrGzDummyChannel.endRequestcCst|j|jSr2)r5rWrVr3rrrisSecurer?zDummyChannel.isSecurecCrEr2rr3rrrrLrMzDummyChannel.abortConnectioncCrEr2rr3rrrrNrMzDummyChannel.getTcpKeepAlivecCrEr2rr3rrrrOrMzDummyChannel.getTcpNoDelaycCrEr2rr3rrrrPrMz DummyChannel.loseWriteConnectioncCrEr2rr3rrrrSrMzDummyChannel.setTcpKeepAlivecCrEr2rr3rrrrTrMzDummyChannel.setTcpNoDelaycCrEr2rr3rrrrUrMzDummyChannel.getPeerCertificater2)r$r%r&r)rr rVrrsiter0rZrgr4r>rDrFr8r<rJrkrlrLrNrOrPrSrTrUrrrrr-s0#   c@seZdZUdZdZdZdZeee d<ddZ dd Z d9d d Z d d Z ddZddZd:ddZddZddZdedfddZddZddZdd Zd:d!d"Zd#d$Zd%d&Zeed'd(d)d*d+d,d-d.Zd/d0Zd1d2Zd3d4Z d;d5d6Z!d7d8Z"dS)|jd|_|jdur|j}d|_|D] }|dqdSdS)z} Record that the request is finished and callback and L{Deferred}s waiting for notification of this. roN)rxrcallback)r. observersobsrrrr@s   zDummyRequest.finishcCs2|jdur|j}d|_|D] }||q dSdS)zK Errback and L{Deferreds} waiting for finish notification. N)rerrback)r.rcrrrrrprocessingFailedLs  zDummyRequest.processingFailedcCs|g|j|<dSr2)r}rrrraddArgVrXzDummyRequest.addArgcCs,|jrJdd|j||_||_dS)z{ Set the HTTP status response code, but takes care that this is called before any data is written. z;Response code cannot be set after data hasbeen written: {}.@@@@N)r+formatjoinrresponseMessage)r.rbmessagerrrsetResponseCodeYs  zDummyRequest.setResponseCodecC |jrJdd|jdS)Nzs zDummyRequest.getHostcCsD||_|r d}nd}||kr|}nd||f}|jd|dS)a_ Change the host and port the request thinks it's using. @type host: C{bytes} @param host: The value to which to change the host header. @type ssl: C{bool} @param ssl: A flag which, if C{True}, indicates that the request is considered secure (if C{True}, L{isSecure} will return C{True}). ir(s%b:%dshostN) _forceSSLrlr~r)r.rr=ssldefault hostHeaderrrrsetHosts  zDummyRequest.setHostcCs|t|d|dS)zu Utility function that does a redirect. The request should have finish() called after this. slocationN)rrr)r.urlrrrredirects zDummyRequest.redirect)NNr2)r)#r$r%r&r'urimethodrnrr __annotations__rDrFr0rrrrrr8r rrrrrrrrrrrrr>rrrrrrrs8            c@s0eZdZdZddZddZddZdd Zd S) DummyRequestTestsz$ Tests for L{DummyRequest}. cCs^tg}||j|jgd}|dt||\}||dt||dddS)zp L{DummyRequest.getClientIP} is deprecated in favor of L{DummyRequest.getClientAddress} )offendingFunctionsrocategoryrz}twisted.web.test.requesthelper.DummyRequest.getClientIP was deprecated in Twisted 18.4.0; please use getClientAddress insteadN)rr flushWarningstest_getClientIPDeprecated assertEquallengetDeprecationWarning)r.rYwarningswarningrrrrsz,DummyRequestTests.test_getClientIPDeprecatedcCs.tg}tddd}||_|d|dS)z L{DummyRequest.getClientIP} supports IPv6 addresses, just like L{twisted.web.http.Request.getClientIP}. r)z::190N)rr rnrr)r.rYrnrrrtest_getClientIPSupportsIPv6s z.DummyRequestTests.test_getClientIPSupportsIPv6cCs tg}|}tt|dS)zu L{DummyRequest.getClientAddress} returns an L{IAddress} provider no C{client} has been set. N)rrr verifyObjectr )r.rYnullrrr"test_getClientAddressWithoutClientsz4DummyRequestTests.test_getClientAddressWithoutClientcCs2tg}tddd}||_|}|||dS)zI L{DummyRequest.getClientAddress} returns the C{client}. r)rrN)rr rnrassertIs)r.rYrnaddressrrrtest_getClientAddresss  z'DummyRequestTests.test_getClientAddressN)r$r%r&r'rrrrrrrrrs  rN)-r'__all__iortypingrzope.interfacerr incrementalrtwisted.internet.addressr r twisted.internet.deferr twisted.internet.interfacesr r twisted.internet.taskrtwisted.python.deprecater twisted.trialrtwisted.web._responsesrtwisted.web.http_headersrtwisted.web.resourcertwisted.web.serverrrrtextLinearWhitespaceComponents sanitizedTextbytesLinearWhitespaceComponentsr!sanitizedBytesr#rrSynchronousTestCaserrrrrs<