+
    Dfj<                       R t ^ RIHt RR.t^ RIHt ^ RIHtHtH	t	 ^ RI
HtHt ^ RIHt ^ RIHtHt ^ R	IHt ^ R
IHtHt ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RIH t  ^ RI!H"t" ^ RI#H$t$H%t%H&t& R U u. uF	  p RV  R2NK  	  up t'Rt(]' Uu. uF  qPS                  R4      NK  	  upt*](PS                  R4      t+]! ]4       ! R R4      4       t, ! R R4      t- ! R R4      t. ! R R]P^                  4      t0R# u up i u upi )z2
Helpers related to HTTP requests, used by tests.
)annotationsDummyChannelDummyRequest)BytesIO)DictListOptional)implementerverify)Version)IPv4AddressIPv6Address)Deferred)IAddressISSLTransport)Clock)
deprecated)unittest)FOUND)Headers)Resource)NOT_DONE_YETSessionSiteFoobarzFoo barasciic                      ] tR t^'tRtRtR# )NullAddressz'
A null implementation of L{IAddress}.
 N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       @/usr/lib/python3/dist-packages/twisted/web/test/requesthelper.pyr   r   '   s    r&   r   c                      ] tR t^.t ! R R4      t]! ]4       ! R R]4      4       t]! ]	! 4       4      t
RR ltR tR tR	 tR
 tR tR tR tR tR tR tR tR tR tR tR tR tR tR tRtR# )r   c                  R    ] tR t^/t^PtRtRR ltR tR tR t	R t
R tR	 tR
 tRtR# )DummyChannel.TCPFNc                	`    Vf   \        RRR4      pWn        \        4       V n        . V n        R # )NTCPz192.168.1.1i80  )r   _peerr   written	producersselfpeers   &&r'   __init__DummyChannel.TCP.__init__3   s*    |"5-?J"9DLDNr&   c                	    V P                   # N)r-   r1   s   &r'   getPeerDummyChannel.TCP.getPeer:   s    ::r&   c                	    \        V\        4      '       g   \        R V: 24      hV P                  P	                  V4       R# )z)Can only write bytes to a transport, not N)
isinstancebytes	TypeErrorr.   writer1   datas   &&r'   r>   DummyChannel.TCP.write=   s4    dE**"KD8 TUULLt$r&   c                	:    V F  pV P                  V4       K  	  R # r6   )r>   )r1   iovecr@   s   && r'   writeSequenceDummyChannel.TCP.writeSequenceB   s    

4  r&   c                	0    \        R RV P                  4      # )r,   z10.0.0.1)r   portr7   s   &r'   getHostDummyChannel.TCP.getHostF   s    uj$))<<r&   c                	>    V P                   P                  W34       R # r6   )r/   appendr1   producer	streamings   &&&r'   registerProducer!DummyChannel.TCP.registerProducerI   s    NN!!8"78r&   c                	    R # r6   r   r7   s   &r'   unregisterProducer#DummyChannel.TCP.unregisterProducerL   s    r&   c                	    R V n         R# )TN)disconnectedr7   s   &r'   loseConnectionDummyChannel.TCP.loseConnectionO   s
     $Dr&   )r-   rU   r/   r.   r6   )r    r!   r"   r#   rG   rU   r3   r8   r>   rD   rH   rO   rR   rV   r%   r   r&   r'   r,   r*   /   s4    	 		%
	!	=	9		%r&   r,   c                  @    ] tR t^RtR tR tR tR tR tR t	R t
RtR	# )
DummyChannel.SSLc                	    R # r6   r   r7   s   &r'   abortConnection DummyChannel.SSL.abortConnectionT       r&   c                	    R # r6   r   r7   s   &r'   getTcpKeepAlive DummyChannel.SSL.getTcpKeepAliveX   r]   r&   c                	    R # r6   r   r7   s   &r'   getTcpNoDelayDummyChannel.SSL.getTcpNoDelay\   r]   r&   c                	    R # r6   r   r7   s   &r'   loseWriteConnection$DummyChannel.SSL.loseWriteConnection`   r]   r&   c                	    R # r6   r   r1   enableds   &&r'   setTcpKeepAlive DummyChannel.SSL.setTcpKeepAlived   r]   r&   c                	    R # r6   r   rh   s   &&r'   setTcpNoDelayDummyChannel.SSL.setTcpNoDelayh   r]   r&   c                	    R # r6   r   r7   s   &r'   getPeerCertificate#DummyChannel.SSL.getPeerCertificatel   r]   r&   r   N)r    r!   r"   r#   r[   r_   rb   re   rj   rm   rp   r%   r   r&   r'   SSLrY   R   s%    							r&   rr   Nc                	2    V P                  V4      V n        R # r6   )r,   	transportr0   s   &&r'   r3   DummyChannel.__init__r   s    $r&   c                	    R # r6   r   )r1   requests   &&r'   requestDoneDummyChannel.requestDoneu       r&   c                	v   \        V\        4      '       d0   VP                  4        UUUu. uF  w  rVV F  quV3NK  	  K  	  ppppVR ,           V,           R ,           V,           R,           pV.p	V	P                  R V 4       4       V	P	                  R4       V P
                  P                  V	4       R# u upppi )       
c              3  T   "   T F  w  rVR ,           V,           R,           x  K   	  R# 5i)s   : r}   Nr   ).0namevalues   &  r'   	<genexpr>,DummyChannel.writeHeaders.<locals>.<genexpr>   s%     XPWdUlU2W<<PWs   &(N)r;   r   getAllRawHeadersextendrK   rt   rD   )
r1   versioncodereasonheaderskvaluesvresponse_lineheaderSequences
   &&&&&     r'   writeHeadersDummyChannel.writeHeadersx   s    gw''*1*B*B*D*D;AfAf*D    $-4v=G'XPWXXg&$$^4s   B4c                	6    V P                   P                  4       # r6   )rt   r8   r7   s   &r'   r8   DummyChannel.getPeer       ~~%%''r&   c                	6    V P                   P                  4       # r6   )rt   rH   r7   s   &r'   rH   DummyChannel.getHost   r   r&   c                	<    V P                   P                  W4       R # r6   )rt   rO   rL   s   &&&r'   rO   DummyChannel.registerProducer   s    ''<r&   c                	:    V P                   P                  4        R # r6   )rt   rR   r7   s   &r'   rR   DummyChannel.unregisterProducer   s    ))+r&   c                	<    V P                   P                  V4       R # r6   )rt   r>   r?   s   &&r'   r>   DummyChannel.write   s    T"r&   c                	<    V P                   P                  V4       R # r6   )rt   rD   )r1   rC   s   &&r'   rD   DummyChannel.writeSequence   s    $$U+r&   c                	:    V P                   P                  4        R # r6   )rt   rV   r7   s   &r'   rV   DummyChannel.loseConnection   s    %%'r&   c                	    R # r6   r   r7   s   &r'   
endRequestDummyChannel.endRequest   rz   r&   c                	B    \        V P                  V P                  4      # r6   )r;   rt   rr   r7   s   &r'   isSecureDummyChannel.isSecure   s    $..$((33r&   c                	    R # r6   r   r7   s   &r'   r[   DummyChannel.abortConnection       r&   c                	    R # r6   r   r7   s   &r'   r_   DummyChannel.getTcpKeepAlive   r   r&   c                	    R # r6   r   r7   s   &r'   rb   DummyChannel.getTcpNoDelay   r   r&   c                	    R # r6   r   r7   s   &r'   re    DummyChannel.loseWriteConnection   r   r&   c                	    R # r6   r   r7   s   &r'   rj   DummyChannel.setTcpKeepAlive   r   r&   c                	    R # r6   r   r7   s   &r'   rm   DummyChannel.setTcpNoDelay   r   r&   c                	    R # r6   r   r7   s   &r'   rp   DummyChannel.getPeerCertificate   r   r&   )rt   r6   )r    r!   r"   r#   r,   r	   r   rr   r   r   siter3   rx   r   r8   rH   rO   rR   r>   rD   rV   r   r   r[   r_   rb   re   rj   rm   rp   r%   r   r&   r'   r   r   .   s    !% !%F c   : 
D(	5((=,#,(4r&   c                  0   ] tR t^t$ RtRtRtRtR]R&   R]R&   R]R	&   R]R
&   R]R&   R]R&   R t	R t
R+R R lltR tR tR tR,R ltR tR tR R ltR tR tR tR,R ltR tR  t]! ]! R!^^^ 4      R"R#7      R$ 4       tR% tR& tR' tR-R( ltR) t R*t!R# ).r   a  
Represents a dummy or fake request. See L{twisted.web.server.Request}.

@ivar _finishedDeferreds: L{None} or a C{list} of L{Deferreds} which will
    be called back with L{None} when C{finish} is called or which will be
    errbacked if C{processingFailed} is called.

@type requestheaders: C{Headers}
@ivar requestheaders: A Headers instance that stores values for all request
    headers.

@type responseHeaders: C{Headers}
@ivar responseHeaders: A Headers instance that stores values for all
    response headers.

@type responseCode: C{int}
@ivar responseCode: The response code which was passed to
    C{setResponseCode}.

@type written: C{list} of C{bytes}
@ivar written: The bytes which have been written to the request.
s   http://dummy/s   GETNOptional[IAddress]clientzList[bytes]sitepathr.   prepathzDict[bytes, List[bytes]]argszList[Deferred[None]]_finishedDeferredsc                \    ^V n         V P                   '       d   VP                  4        K$  R# )z
Call an L{IPullProducer}'s C{resumeProducing} method in a
loop until it unregisters itself.

@param prod: The producer.
@type prod: L{IPullProducer}

@param s: Whether or not the producer is streaming.
N)goresumeProducing)r1   prodss   &&&r'   rO   DummyRequest.registerProducer   s%     ggg  " r&   c                	    ^ V n         R# )    N)r   r7   s   &r'   rR   DummyRequest.unregisterProducer   s	    r&   c               (    V ^8  d   QhRRRRRRRR/# )	   postpathzlist[bytes]sessionzOptional[Session]r   r   returnNoner   )formats   "r'   __annotate__DummyRequest.__annotate__   s2     ' '' #' #	'
 
'r&   c                	$   . V n         . V n        ^ V n        Wn        . V n        RV n        T;'       g    \        RR\        4       R7      V n        / V n	        \        4       V n        \        4       V n        RV n        . V n        RV n        RV n        R# )r   N   0)r   uidreactors   dummys   HTTP/1.0)r   r.   finishedr   r   r   r   r   protoSessionr   r   requestHeadersresponseHeadersresponseCoder   _serverNameclientproto)r1   r   r   r   s   &&&&r'   r3   DummyRequest.__init__   s      #TTwDdEG'T	%i&y "$#&r&   c                    / pV P                   P                  4        F  w  r#VR,          WP                  4       &   K   	  V# )a0  
Return dictionary mapping the names of all received headers to the last
value received for each.

Since this method does not return all header information,
C{self.requestHeaders.getAllRawHeaders()} may be preferred.

NOTE: This function is a direct copy of
C{twisted.web.http.Request.getAllRawHeaders}.
)r   r   lower)r1   r   r   r   s   &   r'   getAllHeadersDummyRequest.getAllHeaders  s;     ''88:DA!"2GGGI ;r&   c                f    V P                   P                  VP                  4       R.4      ^ ,          # )a  
Retrieve the value of a request header.

@type name: C{bytes}
@param name: The name of the request header for which to retrieve the
    value.  Header names are compared case-insensitively.

@rtype: C{bytes} or L{None}
@return: The value of the specified request header.
N)r   getRawHeadersr   )r1   r   s   &&r'   	getHeaderDummyRequest.getHeader  s*     ""00vFqIIr&   c                <    V P                   P                  W4       R# )zATODO: make this assert on write() if the header is content-lengthN)r   addRawHeaderr1   r   r   s   &&&r'   	setHeaderDummyRequest.setHeader   s    ))$6r&   c                	    V P                   '       d   V P                   # V P                  '       d   Q R 4       hV P                  V n         V P                   # )z8Session cannot be requested after data has been written.)r   r.   r   )r1   sessionInterfaces   &&r'   
getSessionDummyRequest.getSession$  sG    <<<<<	FE	F((||r&   c                    VP                  V 4      pV\        J d   R# V P                  V4       V P                  4        R# )aP  
Render the given resource as a response to this request.

This implementation only handles a few of the most common behaviors of
resources.  It can handle a render method that returns a string or
C{NOT_DONE_YET}.  It doesn't know anything about the semantics of
request methods (eg HEAD) nor how to set any particular headers.
Basically, it's largely broken, but sufficient for some tests at least.
It should B{not} be expanded to do all the same stuff L{Request} does.
Instead, L{DummyRequest} should be phased out and L{Request} (or some
other real code factored in a different way) used.
N)renderr   r>   finish)r1   resourceresults   && r'   r   DummyRequest.render-  s2     &\!

6r&   c                	~    \        V\        4      '       g   \        R 4      hV P                  P	                  V4       R# )zwrite() only accepts bytesN)r;   r<   r=   r.   rK   r?   s   &&r'   r>   DummyRequest.write@  s-    $&&899D!r&   c                   V ^8  d   QhRR/# )r   r   zDeferred[None]r   )r   s   "r'   r   r   E  s      n r&   c                P    \        4       pV P                  P                  V4       V# )z
Return a L{Deferred} which is called back with L{None} when the request
is finished.  This will probably only work if you haven't called
C{finish} yet.
)r   r   rK   )r1   r   s   & r'   notifyFinishDummyRequest.notifyFinishE  s$     $,:&&x0r&   c                    V P                   ^,           V n         V P                  e0   V P                  pRV n        V F  pVP                  R4       K  	  R# R# )ze
Record that the request is finished and callback and L{Deferred}s
waiting for notification of this.
N)r   r   callback)r1   	observersobss   &  r'   r   DummyRequest.finishO  sN    
 )"".//I&*D# T" ! /r&   c                    V P                   e0   V P                   pRV n         V F  pVP                  V4       K  	  R# R# )z;
Errback and L{Deferreds} waiting for finish notification.
N)r   errback)r1   r   r   r   s   &&  r'   processingFailedDummyRequest.processingFailed[  s>     "".//I&*D# F# ! /r&   c                	&    V.V P                   V&   R # r6   )r   r   s   &&&r'   addArgDummyRequest.addArge  s     '		$r&   c                    V P                   '       d0   Q RP                  RP                  V P                   4      4      4       hWn        W n        R# )zc
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.   r   joinr   responseMessage)r1   r   messages   &&&r'   setResponseCodeDummyRequest.setResponseCodeh  sF     	
KRRKK%
	
 !&r&   c                	    V P                   '       d0   Q R P                  RP                  V P                   4      4      4       hR# )z<Last-Modified cannot be set after data has been written: {}.r  Nr.   r   r  )r1   whens   &&r'   setLastModifiedDummyRequest.setLastModifiedu  s8    	
LSSKK%
	
r&   c                	    V P                   '       d0   Q R P                  RP                  V P                   4      4      4       hR# )z3ETag cannot be set after data has been written: {}.r  Nr  )r1   tags   &&r'   setETagDummyRequest.setETag|  s8    	
CJJKK%
	
r&   TwistedgetClientAddress)replacementc                ~    \        V P                  \        \        34      '       d   V P                  P                  # R# )zd
Return the IPv4 address of the client which made this request, if there
is one, otherwise L{None}.
N)r;   r   r   r   hostr7   s   &r'   getClientIPDummyRequest.getClientIP  s-     dkkK#=>>;;###r&   c                J    V P                   f   \        4       # V P                   # )zu
Return the L{IAddress} of the client that made this request.

@return: an address.
@rtype: an L{IAddress} provider.
)r   r   r7   s   &r'   r  DummyRequest.getClientAddress  s      ;;= {{r&   c                    V P                   # )zc
Get a dummy hostname associated to the HTTP request.

@rtype: C{bytes}
@returns: a dummy hostname
)r   r7   s   &r'   getRequestHostnameDummyRequest.getRequestHostname  s     r&   c                    \        RR^P4      # )zZ
Get a dummy transport's host.

@rtype: C{IPv4Address}
@returns: a dummy transport's host
r,   	127.0.0.1)r   r7   s   &r'   rH   DummyRequest.getHost  s     5+r22r&   c                    W0n         V P                  4       '       d   RpM^PpW$8X  d   TpM
RW3,          pV P                  P                  RV4       R# )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}).
i  s   %b:%ds   hostN)	_forceSSLr   r   r   )r1   r  rG   ssldefault
hostHeaders   &&&&  r'   setHostDummyRequest.setHost  sJ     ==??GG?J!TL0J((*=r&   c                T    V P                  \        4       V P                  RV4       R# )z]
Utility function that does a redirect.

The request should have finish() called after this.
s   locationN)r
  r   r   )r1   urls   &&r'   redirectDummyRequest.redirect  s      	U#{C(r&   )r   r%  r   r   r   r   r   r   r   r   r   r   r   r  r   r   r.   )NNr6   )r   )"r    r!   r"   r#   r$   urimethodr   __annotations__rO   rR   r3   r   r   r   r   r   r>   r   r   r   r  r
  r  r  r   r   r  r  r  rH   r)  r-  r%   r   r&   r'   r   r      s    . CF!%F%
"",,#'* J7&"

#$"'

 	2q!,:LM N	 3>,)r&   c                  2    ] tR tRtRtR tR tR tR tRt	R# )	DummyRequestTestsi  z
Tests for L{DummyRequest}.
c                @   \        . 4      pVP                  4        V P                  V P                  .R7      pV P	                  ^\        V4      4       Vw  pV P	                  VP                  R4      \        4       V P	                  VP                  R4      R4       R# )zX
L{DummyRequest.getClientIP} is deprecated in favor of
L{DummyRequest.getClientAddress}
)offendingFunctionscategoryr	  z}twisted.web.test.requesthelper.DummyRequest.getClientIP was deprecated in Twisted 18.4.0; please use getClientAddress insteadN)r   r  flushWarningstest_getClientIPDeprecatedassertEquallengetDeprecationWarning)r1   rw   warningswarnings   &   r'   r8  ,DummyRequestTests.test_getClientIPDeprecated  s     r"%% $ ? ?@ & 
 	CM*	Z02DEKK	"6	
r&   c                    \        . 4      p\        RRR4      pW!n        V P                  RVP	                  4       4       R# )zi
L{DummyRequest.getClientIP} supports IPv6 addresses, just like
L{twisted.web.http.Request.getClientIP}.
r,   z::190  N)r   r   r   r9  r  )r1   rw   r   s   &  r'   test_getClientIPSupportsIPv6.DummyRequestTests.test_getClientIPSupportsIPv6  s:    
 r"UE51 3 3 56r&   c                r    \        . 4      pVP                  4       p\        P                  ! \        V4       R# )z]
L{DummyRequest.getClientAddress} returns an L{IAddress}
provider no C{client} has been set.
N)r   r  r
   verifyObjectr   )r1   rw   nulls   &  r'   "test_getClientAddressWithoutClient4DummyRequestTests.test_getClientAddressWithoutClient  s,    
 r"'')Hd+r&   c                    \        . 4      p\        RRR4      pW!n        VP                  4       pV P	                  W24       R# )z9
L{DummyRequest.getClientAddress} returns the C{client}.
r,   r"  rA  N)r   r   r   r  assertIs)r1   rw   r   addresss   &   r'   test_getClientAddress'DummyRequestTests.test_getClientAddress  s;     r"UK7**,g&r&   r   N)
r    r!   r"   r#   r$   r8  rB  rG  rL  r%   r   r&   r'   r3  r3    s    
2	7,'r&   r3  N)
z
)1r$   
__future__r   __all__ior   typingr   r   r   zope.interfacer	   r
   incrementalr   twisted.internet.addressr   r   twisted.internet.deferr   twisted.internet.interfacesr   r   twisted.internet.taskr   twisted.python.deprecater   twisted.trialr   twisted.web._responsesr   twisted.web.http_headersr   twisted.web.resourcer   twisted.web.serverr   r   r   textLinearWhitespaceComponentssanitizedTextencodebytesLinearWhitespaceComponentssanitizedBytesr   r   r   SynchronousTestCaser3  )lw	components   00r'   <module>rh     s    #>
*  ' ' .  = + ? ' / " ( , ) : ::N!O:NBCt3-:N!O /M#/M)W/M#  %%g. X  J JZL) L)^:'44 :'Y "P#s   3C8C=