HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: sport3497 (1034)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/CyberCP/lib/python3.10/site-packages/django/http/__pycache__/response.cpython-310.pyc
o

�h�b�@s*ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
ddlmZddl
mZddlmZmZddlmZddlmZmZddlmZdd	lmZdd
lmZddlmZddlm Z dd
l!m"Z"ddl#m$Z$m%Z%ddl&m'Z'e'dej(�Z)Gdd�de �Z*Gdd�de+�Z,Gdd�d�Z-Gdd�de-�Z.Gdd�de-�Z/Gdd�de/�Z0Gdd�de.�Z1Gdd �d e1�Z2Gd!d"�d"e1�Z3Gd#d$�d$e.�Z4Gd%d&�d&e.�Z5Gd'd(�d(e.�Z6Gd)d*�d*e.�Z7Gd+d,�d,e.�Z8Gd-d.�d.e.�Z9Gd/d0�d0e.�Z:Gd1d2�d2e;�Z<Gd3d4�d4e.�Z=dS)5�N)�Header)�	responses)�urlparse)�
async_to_sync�
sync_to_async)�settings)�signals�signing)�DisallowedRedirect)�DjangoJSONEncoder)�SimpleCookie)�timezone)�CaseInsensitiveMapping)�
iri_to_uri)�content_disposition_header�	http_date)�_lazy_re_compilez ;\s*charset=(?P<charset>[^\s;]+)c@s@eZdZdd�Zddd�Zdd�Zdd	�Zddd�Zd
d�Zd
S)�ResponseHeaderscCs.i|_|r|�|�D]
\}}|||<q
dSdS)zm
        Populate the initial data using __setitem__ to ensure values are
        correctly encoded.
        N)�_store�
_unpack_items)�self�data�header�value�r�G/usr/local/CyberCP/lib/python3.10/site-packages/django/http/response.py�__init__!s
�zResponseHeaders.__init__Fc
Csz2t|t�r|�|�nt|t�r|�|�}n	t|�}|�|�d|vs(d|vr0td|�d���W|Sty}zAt|t�rGd|vsTd|vsTt|t�r]d|vsTd|vr]td|�d��|�|rjt|dtj	d���}n
|j
d	|7_
�WYd
}~|Sd
}~ww)z�
        Convert headers key/value to ascii/latin-1 native strings.
        `charset` must be 'ascii' or 'latin-1'. If `mime_encode` is True and
        `value` can't be represented in the given charset, apply MIME-encoding.
        �
�
z*Header values can't contain newlines (got �)�
�
zutf-8)�
maxlinelenz,, HTTP response headers must be in %s formatN)�
isinstance�str�encode�bytes�decode�BadHeaderError�UnicodeErrorr�sys�maxsize�reason)rr�charset�mime_encode�errr�_convert_to_charset+s>



����
��
���z#ResponseHeaders._convert_to_charsetcC�|�|�dS�N)�pop)r�keyrrr�__delitem__R�zResponseHeaders.__delitem__cCs2|�|d�}|j|ddd�}||f|j|��<dS)N�ascii�latin-1T)r.)r0r�lower�rr4rrrr�__setitem__UszResponseHeaders.__setitem__NcCs|j�|��|�Sr2)rr3r9)rr4�defaultrrrr3ZszResponseHeaders.popcCs||vr
|||<dSdSr2rr:rrr�
setdefault]��zResponseHeaders.setdefault)Fr2)	�__name__�
__module__�__qualname__rr0r5r;r3r=rrrrr s

'
rc@�eZdZdS)r(N�r?r@rArrrrr(b�r(c@s eZdZdZdZ	d9dd�Zedd��Zejdd��Zed	d
��Z	e	jdd
��Z	dd
�Z
e
Zedd��Zdd�Z
dd�Zdd�Zdd�ZeZdd�Zd:dd�Z								d;dd �Zd!d"�Zd<d#d$�Zd=d%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Z dS)>�HttpResponseBasez�
    An HTTP response base class with dictionary-accessed headers.

    This class doesn't handle content. It should not be used directly.
    Use the HttpResponse and StreamingHttpResponse subclasses instead.
    ��Nc	Cs�t|�|_||_d|jvr|durd|j��}||jd<n|r#td��g|_d|_t�|_d|_	|dur\zt
|�|_Wn
ttfyHtd��wd|jkrWdks\td��td��||_
dS)	N�Content-Typeztext/html; charset=zX'headers' must not contain 'Content-Type' when the 'content_type' parameter is provided.Fz$HTTP status code must be an integer.�diWz4HTTP status code must be an integer from 100 to 599.)r�headers�_charsetr-�
ValueError�_resource_closers�_handler_classr�cookies�closed�int�status_code�	TypeError�_reason_phrase)r�content_type�statusr,r-rIrrrrps2

���
zHttpResponseBase.__init__cCs|jdur|jSt�|jd�S)NzUnknown Status Code)rSr�getrQ�rrrr�
reason_phrase�s
zHttpResponseBase.reason_phrasecC�
||_dSr2)rS�rrrrrrX��
cCsD|jdur|jS|j�d�}rt�|�}r|d�dd�StjS)NrGr-�"�)rJrIrV�_charset_from_content_type_re�search�replacer�DEFAULT_CHARSET)rrT�matchedrrrr-�s
zHttpResponseBase.charsetcCrYr2)rJrZrrrr-�r[cCsd�dd�|j��D��S)zHTTP headers as a bytestring.s
cSs(g|]\}}|�d�d|�d��qS)r7s: r8)r%)�.0r4rrrr�
<listcomp>�s��z6HttpResponseBase.serialize_headers.<locals>.<listcomp>)�joinrI�itemsrWrrr�serialize_headers�s
��z"HttpResponseBase.serialize_headerscCsd|jvrd|jdSdS)NrGz, "%s"r]�rIrWrrr�_content_type_for_repr�s

���z'HttpResponseBase._content_type_for_reprcCs||j|<dSr2rh)rrrrrrr;�r6zHttpResponseBase.__setitem__cCs|j|=dSr2rh�rrrrrr5��zHttpResponseBase.__delitem__cCs
|j|Sr2rhrjrrr�__getitem__��
zHttpResponseBase.__getitem__cCs
||jvS)z$Case-insensitive check for a header.rhrjrrr�
has_header�r[zHttpResponseBase.has_headercCs
|j��Sr2)rIrfrWrrrrf�rmzHttpResponseBase.itemscCs|j�||�Sr2)rIrV)rr�	alternaterrrrV�r6zHttpResponseBase.getr]�/Fc
Csr||j|<|durMt|tj�rEt�|�rt�|tjj�}|tjjtjjd�}
|
tjdd�7}
d}|dur9t	d��t
d|
jd|
j�}n||j|d<nd	|j|d<|durzt|tj�rb|�
�}t|�|j|d
<|sztt��|�|j|d<|dur�||j|d<|dur�||j|d<|r�d
|j|d<|r�d
|j|d<|	r�|	��dvr�t	d��|	|j|d<dSdS)a�
        Set a cookie.

        ``expires`` can be:
        - a string in the correct format,
        - a naive ``datetime.datetime`` object in UTC,
        - an aware ``datetime.datetime`` object in any time zone.
        If it is a ``datetime.datetime`` object then calculate ``max_age``.

        ``max_age`` can be:
        - int/float specifying seconds,
        - ``datetime.timedelta`` object.
        N)�tz�)�secondsz/'expires' and 'max_age' can't be used together.ri�Q�expiresr]zmax-age�path�domainT�secure�httponly)�lax�none�strictz,samesite must be "lax", "none", or "strict".�samesite)rNr#�datetimer
�is_naive�
make_aware�utc�now�	timedeltarK�max�daysrs�
total_secondsrPr�timer9)rr4r�max_agertrurvrwrxr|�deltarrr�
set_cookie�s@

�zHttpResponseBase.set_cookiecCs|j�||�dS)z,Set a header unless it has already been set.N)rIr=r:rrrr=�zHttpResponseBase.setdefaultcKs*tj||d��|�}|j||fi|��S)N)�salt)r	�get_cookie_signer�signr�)rr4rr��kwargsrrr�set_signed_cookiesz"HttpResponseBase.set_signed_cookiec	Cs6|�d�p|o|��dk}|j|d|||d|d�dS)N)z	__Secure-z__Host-rzrzThu, 01 Jan 1970 00:00:00 GMT)r�rurvrwrtr|)�
startswithr9r�)rr4rurvr|rwrrr�
delete_cookies
�
�zHttpResponseBase.delete_cookiecCs@t|ttf�rt|�St|t�rt|�|j��St|��|j�S)z=Turn a value into a bytestring encoded in the output charset.)r#r&�
memoryviewr$r%r-rZrrr�
make_bytes1s
	
zHttpResponseBase.make_bytesc	CsL|jD]}z|�WqtyYqw|j��d|_tjj|jd�dS)NT)�sender)rL�	Exception�clearrOr�request_finished�sendrM)r�closerrrr�closeFs

�
zHttpResponseBase.closecC�td|jj���Nz This %s instance is not writable��OSError�	__class__r?�r�contentrrr�writeQ�zHttpResponseBase.writecCsdSr2rrWrrr�flushT�zHttpResponseBase.flushcCr�)Nz)This %s instance cannot tell its positionr�rWrrr�tellWs
�zHttpResponseBase.tellcC�dS�NFrrWrrr�readable_r�zHttpResponseBase.readablecCr�r�rrWrrr�seekablebr�zHttpResponseBase.seekablecCr�r�rrWrrr�writableer�zHttpResponseBase.writablecCr�r�r�)r�linesrrr�
writelineshr�zHttpResponseBase.writelines)NNNNNr2)r]NNrpNFFN)r])rpNN)!r?r@rA�__doc__rQr�propertyrX�setterr-rg�	__bytes__rir;r5rlrn�__contains__rfrVr�r=r�r�r�r�r�r�r�r�r�r�r�rrrrrEfsZ
�



	


�@

rEcs�eZdZdZdZd�fdd�	Zdd�Zdd	�ZeZe	d
d��Z
e
jdd��Z
d
d�Zdd�Z
dd�Zdd�Zdd�Zdd�Z�ZS)�HttpResponsezs
    An HTTP response class with a string as content.

    This content can be read, appended to, or replaced.
    F�c�t�j|i|��||_dSr2)�superrr�)rr��argsr��r�rrrus
zHttpResponse.__init__cC�d|jj|j|jd�S�Nz5<%(cls)s status_code=%(status_code)d%(content_type)s>)�clsrQrT�r�r?rQrirWrrr�__repr__z�
�zHttpResponse.__repr__cCs|��d|jS)z6Full HTTP message, including headers, as a bytestring.s

)rgr�rWrrr�	serialize�r�zHttpResponse.serializecC�d�|j�S�Nr�)re�
_containerrWrrrr��szHttpResponse.contentcstt|d�r/t|tttf�s/d��fdd�|D��}t|d�r.z|��Wnty-Ynwn��|�}|g�_	dS)N�__iter__r�c3s�|]}��|�VqdSr2�r�)rc�chunkrWrr�	<genexpr>�s�z'HttpResponse.content.<locals>.<genexpr>r�)
�hasattrr#r&r�r$rer�r�r�r�)rrr�rrWrr��s
�
��
cC�
t|j�Sr2)�iterr�rWrrrr��rmzHttpResponse.__iter__cCs|j�|�|��dSr2)r��appendr�r�rrrr��szHttpResponse.writecCr�r2)�lenr�rWrrrr��rmzHttpResponse.tellcCs|jSr2)r�rWrrr�getvalue�szHttpResponse.getvaluecCr�)NTrrWrrrr��r�zHttpResponse.writablecCs|D]}|�|�qdSr2)r�)rr��linerrrr��r>zHttpResponse.writelines)r�)r?r@rAr��	streamingrr�r�r�r�r�r�r�r�r�r�r�r��
__classcell__rrr�rr�ls"

r�csteZdZdZdZd�fdd�	Zdd�Zedd	��Zed
d��Z	e	j
dd��Z	d
d�Zdd�Zdd�Z
dd�Z�ZS)�StreamingHttpResponsea$
    A streaming HTTP response class with an iterator as content.

    This should only be iterated once, when the response is streamed to the
    client. However, it can be appended to or replaced with a new iterator
    that wraps the original content (or yields entirely new content).
    Trcr�r2)r�r�streaming_content)rr�r�r�r�rrr�s
zStreamingHttpResponse.__init__cCr�r�)r�rArQrirWrrrr��r�zStreamingHttpResponse.__repr__cCr�)NzMThis %s instance has no `content` attribute. Use `streaming_content` instead.)�AttributeErrorr�r?rWrrrr��s
��zStreamingHttpResponse.contentcs.�jr�j���fdd�}|�St�j�j�S)Ncs&��2z3dHW}��|�Vq6dSr2r�)�part��	_iteratorrrr�awrapper�s��z9StreamingHttpResponse.streaming_content.<locals>.awrapper)�is_asyncr��mapr�)rr�rr�rr��s
z'StreamingHttpResponse.streaming_contentcCr1r2)�_set_streaming_contentrZrrrr��scCsXz
t|�|_d|_Wnty|��|_d|_Ynwt|d�r*|j�|j�dSdS)NFTr�)	r�r�r�rR�	__aiter__r�rLr�r�rZrrrr��s



�
�z,StreamingHttpResponse._set_streaming_contentcCsNzt|j�WSty&t�dt�dd�}t|jtt|�|j	���YSw)Nz�StreamingHttpResponse must consume asynchronous iterators in order to serve them synchronously. Use a synchronous iterator instead.c�s(�g}|2z3dHW}|�|�q6|Sr2)r�)r��as_listr�rrr�to_list�s��z/StreamingHttpResponse.__iter__.<locals>.to_list)
r�r�rR�warnings�warn�Warningr�r�rr�)rr�rrrr��s��zStreamingHttpResponse.__iter__cCsf�z|j2z	3dHW}|Vq6WdSty2t�dt�tt�|j�IdHD]}|Vq)YdSw)Nz�StreamingHttpResponse must consume synchronous iterators in order to serve them asynchronously. Use an asynchronous iterator instead.)r�rRr�r�r�r�list)rr�rrrr�s�����zStreamingHttpResponse.__aiter__cCr�r�)rer�rWrrrr�rkzStreamingHttpResponse.getvalue)r)r?r@rAr�r�rr�r�r�r�r�r�r�r�r�r�rrr�rr��s


r�cs@eZdZdZdZddd��fdd�
Z�fdd	�Zd
d�Z�ZS)�FileResponsez>
    A streaming HTTP response class optimized for files.
    iFr])�
as_attachment�filenamecs8||_||_d|vp|ddu|_t�j|i|��dS)NrT)r�r��_no_explicit_content_typer�r)rr�r�r�r�r�rrrs
�zFileResponse.__init__cslt|d�sd�_t��|�S|�_�t�d�r�j��j�t��fdd�d�}����t��|�dS)N�readr�cs���j�Sr2)r��
block_sizer��filelikerrr�<lambda>*sz5FileResponse._set_streaming_content.<locals>.<lambda>r�)	r��file_to_streamr�r�rLr�r�r��set_headersrZr�r�rr�"s



z#FileResponse._set_streaming_contentcs�t�dd�}t|t�r
|nd}t�d�ot�d�p���}t�d�re|r?���}��dtj����|�j	d<��|�nDt�d�rQ��
�j����j	d<n2tj
�|�rdtj
�|�����j	d<n|r�tt��fd	d
�d���j	d<��t�j	d�tj�tj
��jp�|�}�jr�|r�t�|�\}}ddd
d��||�}|p�d�j	d<nd�j	d<t�j|�}r�|�j	d<dSdS)z�
        Set some common response headers (Content-Length, Content-Type, and
        Content-Disposition) based on the `filelike` response content.
        �namer]�seekr�r�rzContent-Length�	getbuffercst���j��Sr2)r�r�r�rr�rrr�Hsz*FileResponse.set_headers.<locals>.<lambda>zapplication/x-bzipzapplication/gzipzapplication/x-xz)�bzip2�gzip�xzzapplication/octet-streamrGzContent-DispositionN)�getattrr#r$r�r�r�r��io�SEEK_ENDrIr��nbytes�osru�exists�getsize�sumr�rP�basenamer�r��	mimetypes�
guess_typerVrr�)rr�r�r��initial_positionrT�encoding�content_dispositionrr�rr�.sR
�


���
���
�
��zFileResponse.set_headers)	r?r@rAr�r�rr�r�r�rrr�rr�sr�cs8eZdZgd�Z�fdd�Zedd��Zdd�Z�ZS)�HttpResponseRedirectBase)�http�https�ftpcsRt�j|i|��t|�|d<tt|��}|jr%|j|jvr'td|j��dSdS)N�Locationz)Unsafe redirect to URL with protocol '%s')r�rrrr$�scheme�allowed_schemesr
)r�redirect_tor�r��parsedr�rrrfs��z!HttpResponseRedirectBase.__init__cCs|dS)NrrrWrrrr�osz!HttpResponseRedirectBase.<lambda>cCsd|jj|j|j|jd�S)NzD<%(cls)s status_code=%(status_code)d%(content_type)s, url="%(url)s">)r�rQrT�url)r�r?rQrir	rWrrrr�qs���z!HttpResponseRedirectBase.__repr__)	r?r@rArrr�r	r�r�rrr�rrcs
	rc@�eZdZdZdS)�HttpResponseRedirecti.N�r?r@rArQrrrrr}�rc@r
)�HttpResponsePermanentRedirecti-Nrrrrrr�r
rcs0eZdZdZ�fdd�Zejjdd��Z�ZS)�HttpResponseNotModifiedi0cst�j|i|��|d=dS)Nzcontent-type)r�r)rr�r�r�rrr�s
z HttpResponseNotModified.__init__cCs|rtd��g|_dS)Nz7You cannot set content to a 304 (Not Modified) response)r�r�rZrrrr��s
�
zHttpResponseNotModified.content)	r?r@rArQrr�r�r�r�rrr�rr�s
rc@r
)�HttpResponseBadRequesti�Nrrrrrr�r
rc@r
)�HttpResponseNotFoundi�Nrrrrrr�r
rc@r
)�HttpResponseForbiddeni�Nrrrrrr�r
rcs(eZdZdZ�fdd�Zdd�Z�ZS)�HttpResponseNotAllowedi�cs$t�j|i|��d�|�|d<dS)Nz, �Allow)r�rre)r�permitted_methodsr�r�r�rrr�szHttpResponseNotAllowed.__init__cCsd|jj|j|j|dd�S)NzC<%(cls)s [%(methods)s] status_code=%(status_code)d%(content_type)s>r)r�rQrT�methodsr�rWrrrr��s�zHttpResponseNotAllowed.__repr__)r?r@rArQrr�r�rrr�rr�src@r
)�HttpResponseGonei�Nrrrrrr�r
rc@r
)�HttpResponseServerErrori�Nrrrrrr�r
rc@rB)�Http404NrCrrrrr�rDrcs(eZdZdZeddf�fdd�	Z�ZS)�JsonResponseaH
    An HTTP response class that consumes data to be serialized to JSON.

    :param data: Data to be dumped into json. By default only ``dict`` objects
      are allowed to be passed due to a security flaw before ECMAScript 5. See
      the ``safe`` parameter for more information.
    :param encoder: Should be a json encoder class. Defaults to
      ``django.core.serializers.json.DjangoJSONEncoder``.
    :param safe: Controls if only ``dict`` objects may be serialized. Defaults
      to ``True``.
    :param json_dumps_params: A dictionary of kwargs passed to json.dumps().
    TNcs^|rt|t�std��|duri}|�dd�tj|fd|i|��}t�jdd|i|��dS)NzTIn order to allow non-dict objects to be serialized set the safe parameter to False.rTzapplication/jsonr�r�r)r#�dictrRr=�json�dumpsr�r)rr�encoder�safe�json_dumps_paramsr�r�rrr�s�zJsonResponse.__init__)r?r@rAr�rrr�rrr�rr�s�r)>r}r�rr�r��rer*r�r��email.headerr�http.clientr�urllib.parser�asgiref.syncrr�django.confr�django.corerr	�django.core.exceptionsr
�django.core.serializers.jsonr�django.http.cookier�django.utilsr
�django.utils.datastructuresr�django.utils.encodingr�django.utils.httprr�django.utils.regex_helperr�Ir^rrKr(rEr�r�r�rrrrrrrrrrr�rrrrrr�<module>s\�BDcP