3
g                 @   s*  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 d dlmZ d dl	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 d d
lmZ d dlmZ d dl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&m'Z' d dl(m)Z) d dl*m+Z+ d dl,m-Z- d dl.m/Z/ d dl0m1Z1 d dl2m3Z3 d dl4m5Z5 d dl6m7Z7 d9Z8d Z9d!e9 Z:e7d"Z;e7d#Z<G d$d de=Z>G d%d& d&Z?d'd( Z@d)d* ZAG d+d, d,eZBG d-d. d.eZCd/d0 ZDd1d ZEd2d ZFG d3d dZGG d4d deGZHG d5d6 d6ZIG d7d deIeGZJG d8d deIeHZKdS ):    N)copy)partial)
HTTPStatus)import_module)BytesIO)unquote_to_bytesurljoinurlparseurlsplit)sync_to_async)settings)ASGIRequest)BaseHandler)WSGIRequest)DjangoJSONEncoder)got_request_exceptionrequest_finishedrequest_started)close_old_connections)HttpRequest	QueryDictSimpleCookie)signals)ContextList)resolve)force_bytes)SimpleLazyObject)	urlencode)is_iterable)_lazy_re_compileAsyncClientAsyncRequestFactoryClientRedirectCycleErrorRequestFactoryencode_fileencode_multipartZBoUnDaRyStRiNgz multipart/form-data; boundary=%sz.*; charset=([\w\d-]+);?z^application\/(.+\+)?jsonc                   s    e Zd ZdZ fddZ  ZS )r#   z9The test client has been asked to follow a redirect loop.c                s   t  j| || _|j| _d S )N)super__init__last_responseredirect_chain)selfmessager)   )	__class__ P/var/www/tester-filtro-web/env/lib/python3.6/site-packages/django/test/client.pyr(   0   s    zRedirectCycleError.__init__)__name__
__module____qualname____doc__r(   __classcell__r.   r.   )r-   r/   r#   .   s   c               @   s4   e Zd ZdZdddZdd ZdddZd	d
 ZdS )FakePayloada  
    A wrapper around BytesIO that restricts what can be read since data from
    the network can't be sought and cannot be read outside of its content
    length. This makes sure that views can't do anything under the test client
    that wouldn't work in real life.
    Nc             C   s*   t  | _d| _d| _|d k	r&| j| d S )Nr   F)r   _FakePayload__content_FakePayload__lenread_startedwrite)r+   contentr.   r.   r/   r(   =   s
    zFakePayload.__init__c             C   s   | j S )N)r7   )r+   r.   r.   r/   __len__D   s    zFakePayload.__len__c             C   sZ   | j s| jjd d| _ |d kr*| jp(d}| j|ks<td| jj|}|  j|8  _|S )Nr   TzFCannot read more than the available bytes from the HTTP incoming data.)r8   r6   seekr7   AssertionErrorread)r+   	num_bytesr:   r.   r.   r/   r>   G   s    
zFakePayload.readc             C   s8   | j rtdt|}| jj| |  jt|7  _d S )Nz.Unable to write a payload after it's been read)r8   
ValueErrorr   r6   r9   r7   len)r+   r:   r.   r.   r/   r9   R   s
    zFakePayload.write)N)N)r0   r1   r2   r3   r(   r;   r>   r9   r.   r.   r.   r/   r5   6   s
   

r5   c             c   s0   z| E d H  W d t jt |  t jt X d S )N)r   
disconnectr   connect)iterablecloser.   r.   r/   closing_iterator_wrapperZ   s
    
rF   c             C   sZ   d|j   kodk n  s$|j dkr8|jr2g |_nd|_| jdkrV|jrPg |_nd|_|S )z
    Simulate the behavior of most Web servers by removing the content of
    responses for HEAD requests, 1xx, 204, and 304 responses. Ensure
    compliance with RFC 7230, section 3.3.3.
    d         0      HEAD)rI   rJ   )status_code	streamingstreaming_contentr:   method)requestresponser.   r.   r/   conditional_content_removalc   s    $
rS   c                   s*   e Zd ZdZd fdd	Zdd Z  ZS )ClientHandlerz
    A HTTP Handler that can be used for testing purposes. Use the WSGI
    interface to compose requests, but return the raw HttpResponse object with
    the originating WSGIRequest attached to its ``wsgi_request`` attribute.
    Tc                s   || _ t j|| d S )N)enforce_csrf_checksr'   r(   )r+   rU   argskwargs)r-   r.   r/   r(   |   s    zClientHandler.__init__c             C   s   | j d kr| j  tjt tj| j|d tjt t|}| j	 |_
| j|}t|| ||_|jrzt|j|j|_ntjt |j  tjt |S )N)senderenviron)_middleware_chainload_middlewarer   rB   r   sendr-   rC   r   rU   _dont_enforce_csrf_checksZget_responserS   Zwsgi_requestrN   rF   rO   rE   r   )r+   rY   rQ   rR   r.   r.   r/   __call__   s"    







zClientHandler.__call__)T)r0   r1   r2   r3   r(   r^   r4   r.   r.   )r-   r/   rT   v   s   rT   c                   s*   e Zd ZdZd fdd	Zdd Z  ZS )AsyncClientHandlerz"An async version of ClientHandler.Tc                s   || _ t j|| d S )N)rU   r'   r(   )r+   rU   rV   rW   )r-   r.   r/   r(      s    zAsyncClientHandler.__init__c                s   | j d kr| jdd d|kr*|jd}ntd}tjt ttjdd| j	|dI d H  tj
t t||}| j |_| j|I d H }t|| ||_|jrttdd|j|jI d H |_n*tjt t|jdd I d H  tj
t |S )NT)Zis_async
_body_file F)Zthread_sensitive)rX   scope)rZ   r[   popr5   r   rB   r   r   r\   r-   rC   r   rU   r]   Zget_response_asyncrS   Zasgi_requestrN   rF   rO   rE   r   )r+   rb   	body_filerQ   rR   r.   r.   r/   r^      s*    








zAsyncClientHandler.__call__)T)r0   r1   r2   r3   r(   r^   r4   r.   r.   )r-   r/   r_      s   r_   c             K   s:   | j dg j| d| kr$t | d< | d jt| dS )z
    Store templates and contexts that are rendered.

    The context is copied so that it is an accurate representation at the time
    of rendering.
    	templatescontextN)
setdefaultappendr   r   )storesignalrX   templaterf   rW   r.   r.   r/   store_rendered_templates   s    
rl   c                s  g }dd  dd }x|j  D ]\}}|dkr<td| q||rX|jt| || qt|t rt|rxz|D ]H}||r|jt| || qr|j fddd	|  d
| d|gD  qrW q|j fddd	|  d
| d|gD  qW |j d|  dg dj|S )a+  
    Encode multipart POST data from a dictionary of form values.

    The key will be used as the form data name; the value will be transmitted
    as content. If the value is a file, the contents of the file will be sent
    as an application/octet-stream; otherwise, str(value) will be sent.
    c             S   s   t | tjS )N)r   r   DEFAULT_CHARSET)sr.   r.   r/   to_bytes   s    z"encode_multipart.<locals>.to_bytesc             S   s   t | dot| jS )Nr>   )hasattrcallabler>   )thingr.   r.   r/   is_file   s    z!encode_multipart.<locals>.is_fileNzeCannot encode None for key '%s' as POST data. Did you mean to pass an empty string or omit the value?c             3   s   | ]} |V  qd S )Nr.   ).0val)ro   r.   r/   	<genexpr>  s    z#encode_multipart.<locals>.<genexpr>z--%sz)Content-Disposition: form-data; name="%s"ra   c             3   s   | ]} |V  qd S )Nr.   )rt   ru   )ro   r.   r/   rv   	  s    z--%s--rK   s   
)items	TypeErrorextendr%   
isinstancestrr   join)boundarydatalinesrs   keyvalueitemr.   )ro   r/   r&      s8    


c             C   s   dd }t |dot|jt}|r0tjj|jnd}t |drF|j}n|rZtj	|d }nd }|d krjd}|pp|}|d|  |d	||f |d
| d||j
 gS )Nc             S   s   t | tjS )N)r   r   rm   )rn   r.   r.   r/   ro     s    zencode_file.<locals>.to_bytesnamera   content_typer   zapplication/octet-streamz--%sz8Content-Disposition: form-data; name="%s"; filename="%s"zContent-Type: %srK   )rp   rz   r   r{   ospathbasenamer   	mimetypes
guess_typer>   )r}   r   filero   Zfile_has_string_namefilenamer   r.   r.   r/   r%     s"    



c               @   s   e Zd ZdZedddZdd Zdd Zd	d
 Zdd Z	dd Z
d%ddZdedfddZd&ddZd'ddZd(ddZd)ddZd*dd Zd+d!d"Zd,d#d$ZdS )-r$   aV  
    Class that lets you create mock Request objects for use in testing.

    Usage:

    rf = RequestFactory()
    get_request = rf.get('/hello/')
    post_request = rf.post('/submit/', {'foo': 'bar'})

    Once you have a request object you can pass it to any view function,
    just as if that view had been hooked up using a URLconf.
    )json_encoderc            K   s    || _ || _t | _t | _d S )N)r   defaultsr   cookiesr   errors)r+   r   r   r.   r.   r/   r(   A  s    zRequestFactory.__init__c             K   sL   dj tdd | jj D dddddd	d
ddtd| jdddd| j|S )z5
        The base environment for a request.
        z; c             s   s   | ]}d |j |jf V  qdS )z%s=%sN)r   coded_value)rt   morselr.   r.   r/   rv   Q  s   z/RequestFactory._base_environ.<locals>.<genexpr>/z	127.0.0.1GETra   
testserver80zHTTP/1.1   r   httprK   TF)ZHTTP_COOKIE	PATH_INFOZREMOTE_ADDRREQUEST_METHODZSCRIPT_NAMESERVER_NAMESERVER_PORTZSERVER_PROTOCOLzwsgi.versionzwsgi.url_schemez
wsgi.inputzwsgi.errorszwsgi.multiprocesszwsgi.multithreadzwsgi.run_once)r   r   )r|   sortedr   valuesr5   r   r   )r+   rQ   r.   r.   r/   _base_environG  s&    	zRequestFactory._base_environc             K   s   t | jf |S )z#Construct a generic request object.)r   r   )r+   rQ   r.   r.   r/   rQ   f  s    zRequestFactory.requestc             C   s@   |t krtt|S tj|}|r*|d }ntj}t||dS d S )Nr   )encoding)MULTIPART_CONTENTr&   BOUNDARYCONTENT_TYPE_REmatchr   rm   r   )r+   r~   r   r   charsetr.   r.   r/   _encode_dataj  s    


zRequestFactory._encode_datac             C   s2   t j|ot|tttf}|r.tj|| jdS |S )zu
        Return encoded JSON if data is a dict, list, or tuple and content_type
        is application/json.
        )cls)	JSON_CONTENT_TYPE_REr   rz   dictlisttuplejsondumpsr   )r+   r~   r   Zshould_encoder.   r.   r/   _encode_jsonv  s    zRequestFactory._encode_jsonc             C   s,   |j }|jr|d|j 7 }t|}|jdS )N;z
iso-8859-1)r   paramsr   decode)r+   parsedr   r.   r.   r/   	_get_path~  s
    zRequestFactory._get_pathNFc             K   s8   |dkri n|}| j d|fd|idt|ddi|S )zConstruct a GET request.Nr   secureQUERY_STRINGT)doseq)genericr   )r+   r   r~   r   extrar.   r.   r/   get  s    zRequestFactory.getc             K   s@   | j |dkri n||}| j||}| jd|||fd|i|S )zConstruct a POST request.NPOSTr   )r   r   r   )r+   r   r~   r   r   r   Z	post_datar.   r.   r/   post  s    zRequestFactory.postc             K   s8   |dkri n|}| j d|fd|idt|ddi|S )zConstruct a HEAD request.NrL   r   r   T)r   )r   r   )r+   r   r~   r   r   r.   r.   r/   head  s    zRequestFactory.headc             K   s   | j d|fd|i|S )zConstruct a TRACE request.TRACEr   )r   )r+   r   r   r   r.   r.   r/   trace  s    zRequestFactory.tracera   application/octet-streamc             K   s   | j d|||fd|i|S )zConstruct an OPTIONS request.OPTIONSr   )r   )r+   r   r~   r   r   r   r.   r.   r/   options  s    zRequestFactory.optionsc             K   s(   | j ||}| jd|||fd|i|S )zConstruct a PUT request.PUTr   )r   r   )r+   r   r~   r   r   r   r.   r.   r/   put  s    zRequestFactory.putc             K   s(   | j ||}| jd|||fd|i|S )zConstruct a PATCH request.PATCHr   )r   r   )r+   r   r~   r   r   r   r.   r.   r/   patch  s    zRequestFactory.patchc             K   s(   | j ||}| jd|||fd|i|S )zConstruct a DELETE request.DELETEr   )r   r   )r+   r   r~   r   r   r   r.   r.   r/   delete  s    zRequestFactory.deletec       
      K   s   t t|}t|tj}| j|||r*dnd|r4dndd}|r^|jtt||t|d |j| |j	ds|d j
 jd	}	|	|d< | jf |S )
z$Construct an arbitrary HTTP request.443r   httpsr   )r   r   r   zwsgi.url_scheme)CONTENT_LENGTHCONTENT_TYPEz
wsgi.inputr      z
iso-8859-1)r	   r{   r   r   rm   r   updaterA   r5   r   encoder   rQ   )
r+   rP   r   r~   r   r   r   r   rquery_stringr.   r.   r/   r     s     



zRequestFactory.generic)NF)NF)F)ra   r   F)ra   r   F)ra   r   F)ra   r   F)ra   r   F)r0   r1   r2   r3   r   r(   r   rQ   r   r   r   r   r   r   r   r   r   r   r   r   r   r.   r.   r.   r/   r$   4  s,   


 
 
 
 
 c               @   s*   e Zd ZdZdd Zdd Zdd	d
ZdS )r!   a  
    Class that lets you create mock ASGI-like Request objects for use in
    testing. Usage:

    rf = AsyncRequestFactory()
    get_request = await rf.get('/hello/')
    post_request = await rf.post('/submit/', {'foo': 'bar'})

    Once you have a request object you can pass it to any view function,
    including synchronous ones. The reason we have a separate class here is:
    a) this makes ASGIRequest subclasses, and
    b) AsyncTestClient can subclass it.
    c          	   K   sV   ddiddddgddd	g d
| j |}|d jddjtdd | jj D f |S )zThe base scope for a request.versionz3.0r   z1.1z	127.0.0.1r   r   r   r   )Zasgitypehttp_versionclientserverschemerP   headersr   s   cookies   ; c             s   s$   | ]}d |j |jf jdV  qdS )z%s=%sasciiN)r   r   r   )rt   r   r.   r.   r/   rv     s   z2AsyncRequestFactory._base_scope.<locals>.<genexpr>)r   r   )r   rh   r|   r   r   r   )r+   rQ   rb   r.   r.   r/   _base_scope  s     zAsyncRequestFactory._base_scopec             K   s.   d|kr|j d}ntd}t| jf ||S )z#Construct a generic request object.r`   ra   )rc   r5   r   r   )r+   rQ   rd   r.   r.   r/   rQ     s    zAsyncRequestFactory.requestra   application/octet-streamFc       
      K   s   t t|}t|tj}|| j|d|r,dndf|r8dnddgd}|r|d	 jd
tt|jdfd|jdfg t	||d< |j
dd}	|	dk	r|	|d< |d	  dd |j D 7  < |jds|d |d< | jf |S )z$Construct an arbitrary HTTP request.z	127.0.0.1r   r   r   r      host
   testserver)rP   r   r   r   r   r   s   content-lengthr   s   content-typer`   followNc             S   s(   g | ] \}}|j  jd |jdfqS )r   latin1)lowerr   )rt   r   r   r.   r.   r/   
<listcomp>'  s   z/AsyncRequestFactory.generic.<locals>.<listcomp>r   r   )r   r   )r	   r{   r   r   rm   r   ry   rA   r   r5   rc   rw   r   rQ   )
r+   rP   r   r~   r   r   r   r   rn   r   r.   r.   r/   r     s*    


zAsyncRequestFactory.genericN)ra   r   F)r0   r1   r2   r3   r   rQ   r   r.   r.   r.   r/   r!     s
    c               @   sX   e Zd ZdZdd Zdd Zedd Zdd	 ZdddZ	dddZ
dd Zdd Zd
S )ClientMixinzC
    Mixin with common methods between Client and AsyncClient.
    c             K   s   t j | _dS )z3Store exceptions when they are generated by a view.N)sysexc_info)r+   rW   r.   r.   r/   store_exc_info5  s    zClientMixin.store_exc_infoc             C   s.   | j |_ | j r*| j \}}}d| _ | jr*|dS )z
        Look for a signaled exception, clear the current context exception
        data, re-raise the signaled exception, and clear the signaled exception
        from the local cache.
        N)r   raise_request_exception)r+   rR   _	exc_valuer.   r.   r/   check_exception9  s    zClientMixin.check_exceptionc             C   sJ   t tj}| jjtj}|r(|j|jS |j }|j  |j	| jtj< |S )z%Return the current session variables.)
r   r   SESSION_ENGINEr   r   SESSION_COOKIE_NAMESessionStorer   savesession_key)r+   enginecookiesessionr.   r.   r/   r   F  s    
zClientMixin.sessionc             K   s,   ddl m} |f |}|r(| j| dS dS )z
        Set the Factory to appear as if it has successfully logged into a site.

        Return True if login is possible or False if the provided credentials
        are incorrect.
        r   )authenticateTF)django.contrib.authr   _login)r+   credentialsr   userr.   r.   r/   loginR  s    

zClientMixin.loginNc             C   s,   dd }|d kr| }||_ | j|| d S )Nc              S   s6   ddl m}  x$tjD ]}| |}t|dr|S qW d S )Nr   )load_backendget_user)r   r   r   ZAUTHENTICATION_BACKENDSrp   )r   backend_pathbackendr.   r.   r/   get_backenda  s
    
z,ClientMixin.force_login.<locals>.get_backend)r   r   )r+   r   r   r   r.   r.   r/   force_login`  s
    zClientMixin.force_loginc             C   s   ddl m} t }| jr"| j|_nttj}|j |_|||| |jj  tj	}|jj
| j|< d dtjtjppd d d}| j| j| d S )Nr   )r   r   )zmax-ager   domainr   expires)r   r   r   r   r   r   r   r   r   r   r   r   ZSESSION_COOKIE_DOMAINZSESSION_COOKIE_SECUREr   )r+   r   r   r   rQ   r   Zsession_cookieZcookie_datar.   r.   r/   r   m  s     



zClientMixin._loginc             C   sX   ddl m}m} t }| jr0| j|_|||_nttj}|j	 |_|| t
 | _dS )z<Log out the user by removing the cookies and session object.r   )r   logoutN)r   r   r   r   r   r   r   r   r   r   r   r   )r+   r   r   rQ   r   r.   r.   r/   r     s    

zClientMixin.logoutc             K   sL   t |dsFtj|jds,td|jd tj|jj|j	f||_
|j
S )N_jsonzContent-Typez3Content-Type header is "%s", not "application/json")rp   r   r   r   r@   r   loadsr:   r   r   r   )r+   rR   r   r.   r.   r/   _parse_json  s    
zClientMixin._parse_json)N)N)r0   r1   r2   r3   r   r   propertyr   r   r   r   r   r  r.   r.   r.   r/   r   1  s   

r   c                   s   e Zd ZdZd fdd	Zdd Zd fd	d
	Zdeddf fdd	Zd fdd	Z	d  fdd	Z
d! fdd	Zd" fdd	Zd# fdd	Zd$ fdd	Zd%ddZ  ZS )&r"   a  
    A class that can act as a client for testing purposes.

    It allows the user to compose GET and POST requests, and
    obtain the response that the server gave to those requests.
    The server Response objects are annotated with the details
    of the contexts and templates that were rendered during the
    process of serving the request.

    Client objects are stateful - they will retain cookie (and
    thus session) details for the lifetime of the Client instance.

    This is not intended as a replacement for Twill/Selenium or
    the like - it is here to allow testing against the
    contexts and templates produced by a view, rather than the
    HTML rendered to the end-user.
    FTc                s.   t  jf | t|| _|| _d | _d | _d S )N)r'   r(   rT   handlerr   r   r   )r+   rU   r   r   )r-   r.   r/   r(     s
    
zClient.__init__c                s  | j f  }i }tt|}dt  }tjj||d dt  }tj| j|d z| j	|}W dtjj
|d tj
|d X | j| | |_ |_|jdg |_|jd|_t| j||_t fdd|_|jrt|jd	kr|jd
 |_|jr| jj|j |S )a	  
        The master request method. Compose the environment dictionary and pass
        to the handler, return the result of the handler. Assume defaults for
        the query environment, which can be overridden using the arguments to
        the request.
        ztemplate-render-%s)dispatch_uidzrequest-exception-%sNre   rf   c                  s   t  d S )Nr   )r   r.   )rQ   r.   r/   <lambda>  s    z Client.request.<locals>.<lambda>r   r   )r   r   rl   idr   template_renderedrC   r   r   r  rB   r   r   rQ   r   re   rf   r  r   r   resolver_matchrA   r   r   )r+   rQ   rY   r~   on_template_render
signal_uidexception_uidrR   r.   )rQ   r/   rQ     s.    

zClient.requestNc                s>   || _ t j|f||d|}|r:| j|fd|i|}|S )z-Request a response from the server using GET.)r~   r   r~   )r   r'   r   _handle_redirects)r+   r   r~   r   r   r   rR   )r-   r.   r/   r     s
    z
Client.getc                sB   || _ t j|f|||d|}|r>| j|f||d|}|S )z.Request a response from the server using POST.)r~   r   r   )r~   r   )r   r'   r   r  )r+   r   r~   r   r   r   r   rR   )r-   r.   r/   r     s
    zClient.postc                s>   || _ t j|f||d|}|r:| j|fd|i|}|S )z.Request a response from the server using HEAD.)r~   r   r~   )r   r'   r   r  )r+   r   r~   r   r   r   rR   )r-   r.   r/   r     s
    zClient.headra   application/octet-streamc                sB   || _ t j|f|||d|}|r>| j|f||d|}|S )z1Request a response from the server using OPTIONS.)r~   r   r   )r~   r   )r   r'   r   r  )r+   r   r~   r   r   r   r   rR   )r-   r.   r/   r     s
    zClient.optionsc                sB   || _ t j|f|||d|}|r>| j|f||d|}|S )z(Send a resource to the server using PUT.)r~   r   r   )r~   r   )r   r'   r   r  )r+   r   r~   r   r   r   r   rR   )r-   r.   r/   r     s
    z
Client.putc                sB   || _ t j|f|||d|}|r>| j|f||d|}|S )z*Send a resource to the server using PATCH.)r~   r   r   )r~   r   )r   r'   r   r  )r+   r   r~   r   r   r   r   rR   )r-   r.   r/   r     s
    zClient.patchc                sB   || _ t j|f|||d|}|r>| j|f||d|}|S )z$Send a DELETE request to the server.)r~   r   r   )r~   r   )r   r'   r   r  )r+   r   r~   r   r   r   r   rR   )r-   r.   r/   r     s
    zClient.deletec                s>   || _ t j|f||d|}|r:| j|fd|i|}|S )z#Send a TRACE request to the server.)r~   r   r~   )r   r'   r   r  )r+   r   r~   r   r   r   rR   )r-   r.   r/   r      s
    zClient.tracec             K   sX  g |_ tjtjtjtjtjf}x2|j|krR|j}|j }|j	||jf t
|}|jrb|j|d< |jrr|j|d< |jrt|j|d< |j}	|	jdst|jd |	}	|jtjtjfkr|jd j }
|
dkr|j|d	< t| |
}
n| j}
t|j}d
}|
|	f||dd|}||_ |d |d
d kr8td|dt|dkr"td|dq"W |S )zY
        Follow any redirects by requesting responses from the server using GET.
        zwsgi.url_schemer   r   r   r   r   r   r   r   NF)r~   r   r   r   zRedirect loop detected.)r)      zToo many redirects.)r   r   r  )r*   r   MOVED_PERMANENTLYFOUND	SEE_OTHERTEMPORARY_REDIRECTPERMANENT_REDIRECTrM   urlrh   r
   r   hostnameportr{   r   
startswithr   rQ   r   querygetattrr   r   r#   rA   )r+   rR   r~   r   r   Zredirect_status_codesZresponse_urlr*   r  r   request_methodr.   r.   r/   r  (  sF    




zClient._handle_redirects)FT)NFF)NFF)ra   r  FF)ra   r  FF)ra   r  FF)ra   r  FF)ra   FF)ra   ra   )r0   r1   r2   r3   r(   rQ   r   r   r   r   r   r   r   r   r   r  r4   r.   r.   )r-   r/   r"     s"   ,    c                   s*   e Zd ZdZd fdd	Zdd Z  ZS )	r    z
    An async version of Client that creates ASGIRequests and calls through an
    async request path.

    Does not currently support "follow" on its methods.
    FTc                s.   t  jf | t|| _|| _d | _d | _d S )N)r'   r(   r_   r  r   r   r   )r+   rU   r   r   )r-   r.   r/   r(   i  s
    
zAsyncClient.__init__c                s   d krt d| jf  }i }tt|}dt  }tjj||d dt  }tj| j	|d z| j
|I dH }W dtjj|d tj|d X | j| | |_ |_|jdg |_|jd|_t| j||_t fd	d
|_|jot|jdkr|jd |_|jr| jj|j |S )a  
        The master request method. Compose the scope dictionary and pass to the
        handler, return the result of the handler. Assume defaults for the
        query environment, which can be overridden using the arguments to the
        request.
        r   z?AsyncClient request methods do not accept the follow parameter.ztemplate-render-%s)r  zrequest-exception-%sNre   rf   c                  s   t  d S )Nr   )r   r.   )rQ   r.   r/   r    s    z%AsyncClient.request.<locals>.<lambda>r   r   )NotImplementedErrorr   r   rl   r  r   r  rC   r   r   r  rB   r   r   rQ   r   re   rf   r  r   r   r  rA   r   r   )r+   rQ   rb   r~   r	  r
  r  rR   r.   )rQ   r/   rQ   p  s4    

zAsyncClient.request)FT)r0   r1   r2   r3   r(   rQ   r4   r.   r.   )r-   r/   r    b  s   )r    r!   r"   r#   r$   r%   r&   )Lr   r   r   r   r   	functoolsr   r   r   	importlibr   ior   urllib.parser   r   r	   r
   Zasgiref.syncr   Zdjango.confr   Zdjango.core.handlers.asgir   Zdjango.core.handlers.baser   Zdjango.core.handlers.wsgir   Zdjango.core.serializers.jsonr   Zdjango.core.signalsr   r   r   Z	django.dbr   Zdjango.httpr   r   r   Zdjango.testr   Zdjango.test.utilsr   Zdjango.urlsr   Zdjango.utils.encodingr   Zdjango.utils.functionalr   Zdjango.utils.httpr   Zdjango.utils.itercompatr   Zdjango.utils.regex_helperr   __all__r   r   r   r   	Exceptionr#   r5   rF   rS   rT   r_   rl   r&   r%   r$   r!   r   r"   r    r.   r.   r.   r/   <module>   s`    $	0.6 )Um E