o
    g!                     @   s   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 d dlmZ d d	lmZ ed
ZG dd deZG dd de	ZG dd dejZdd Zdd Zdd Zdd ZdS )    )IOBase)settings)signals)base)HttpRequest	QueryDictparse_cookie)set_script_prefix)repercent_broken_unicode)cached_property)_lazy_re_compiles   /+c                   @   s,   e Zd ZdZdd Zd
ddZd
ddZd	S )LimitedStreamz
    Wrap another stream to disallow reading it past a number of bytes.

    Based on the implementation from werkzeug.wsgi.LimitedStream
    See https://github.com/pallets/werkzeug/blob/dbf78f67/src/werkzeug/wsgi.py#L828
    c                 C   s    |j | _|j| _d| _|| _d S )Nr   )read_readreadline	_readline_poslimit)selfstreamr    r   V/var/www/rescue_company/venv/lib/python3.10/site-packages/django/core/handlers/wsgi.py__init__   s   
zLimitedStream.__init__c                C   `   | j }| j}||krdS |dks|d u r|| }nt||| }| |}|  j t|7  _ |S N    r   )r   r   minr   len)r   sizer   r   datar   r   r   r         

zLimitedStream.readc                C   r   r   )r   r   r   r   r   )r   r   r   r   liner   r   r   r   *   r!   zLimitedStream.readlineN)r   )__name__
__module____qualname____doc__r   r   r   r   r   r   r   r      s
    
r   c                       s   e Zd ZejedgB ZeddgZdd Z fddZdd	 Z	e
d
d Zdd Zdd Ze
dd Zedd ZeeeZ  ZS )WSGIRequestenvironzwsgi.errors
wsgi.inputc              	   C   s   t |}t|p	d}|| _|| _d|d|dddf | _|| _|| jd< || jd< |d  | _	| 
| z	t|d}W n ttfyN   d	}Y nw t| jd
 || _d| _d | _d S )N/z%s/%s    	PATH_INFOSCRIPT_NAMEREQUEST_METHODCONTENT_LENGTHr   r)   F)get_script_nameget_path_infor(   	path_inforstripreplacepathMETAuppermethod_set_content_type_paramsintget
ValueError	TypeErrorr   _stream_read_startedresolver_match)r   r(   script_namer3   content_lengthr   r   r   r   <   s$   



zWSGIRequest.__init__c                    s0   t   }| jD ]}||d v r|d |= q|S )Nr7   )super__getstate__meta_non_picklable_attrs)r   stateattr	__class__r   r   rE   U   s   


zWSGIRequest.__getstate__c                 C   s   | j dS )Nzwsgi.url_scheme)r(   r<   r   r   r   r   _get_scheme\   s   zWSGIRequest._get_schemec                 C   s   t | jdd}t|| jdS )NQUERY_STRINGr+   )encoding)get_bytes_from_wsgir(   r   	_encoding)r   raw_query_stringr   r   r   GET_   s   zWSGIRequest.GETc                 C      t | ds	|   | jS )N_post)hasattr_load_post_and_filesrT   rK   r   r   r   	_get_poste   s   
zWSGIRequest._get_postc                 C   s
   || _ d S N)rT   )r   postr   r   r   	_set_postj   s   
zWSGIRequest._set_postc                 C   s   t | jdd}t|S )NHTTP_COOKIEr+   )get_str_from_wsgir(   r   )r   
raw_cookier   r   r   COOKIESm   s   zWSGIRequest.COOKIESc                 C   rS   )N_files)rU   rV   r_   rK   r   r   r   FILESr   s   
zWSGIRequest.FILES)r#   r$   r%   r   non_picklable_attrs	frozensetrF   r   rE   rL   r   rR   rW   rZ   r^   propertyr`   POST__classcell__r   r   rI   r   r'   8   s    


r'   c                       s(   e Zd ZeZ fddZdd Z  ZS )WSGIHandlerc                    s   t  j|i | |   d S rX   )rD   r   load_middleware)r   argskwargsrI   r   r   r   ~   s   zWSGIHandler.__init__c                 C   s   t t| tjj| j|d | |}| |}| j|_d|j	|j
f }g | dd |j D }||| t|dd d urU|drU|j|j_|d |j|j}|S )N)senderr(   z%d %sc                 s   s     | ]}d |j ddfV  qdS )z
Set-Cookier+   )headerN)output).0cr   r   r   	<genexpr>   s    z'WSGIHandler.__call__.<locals>.<genexpr>file_to_streamzwsgi.file_wrapper)r	   r1   r   request_startedsendrJ   request_classget_response_handler_classstatus_codereason_phraseitemscookiesvaluesgetattrr<   closerp   
block_size)r   r(   start_responserequestresponsestatusresponse_headersr   r   r   __call__   s(   



zWSGIHandler.__call__)r#   r$   r%   r'   rs   r   r   re   r   r   rI   r   rf   {   s    rf   c                 C   s   t | dd}t| S )z0Return the HTTP request's PATH_INFO as a string.r-   r*   )rO   r
   decode)r(   r3   r   r   r   r2      s   r2   c                 C   s   t jdurt jS t| ddpt| dd}|r7d|v r td|}t| dd}|r1|dt|  n|}| S t| dd}| S )	aE  
    Return the equivalent of the HTTP request's SCRIPT_NAME environment
    variable. If Apache mod_rewrite is used, return what would have been
    the script name prior to any rewriting (so it's the script name as seen
    from the client's perspective), unless the FORCE_SCRIPT_NAME setting is
    set (to anything).
    N
SCRIPT_URLr+   REDIRECT_URLs   //   /r-   r.   )r   FORCE_SCRIPT_NAMErO   _slashes_resubr   r   )r(   
script_urlr3   rB   r   r   r   r1      s   
r1   c                 C   s   |  ||}|dS )zh
    Get a value from the WSGI environ dictionary as bytes.

    key and default should be strings.
    z
iso-8859-1)r<   encoder(   keydefaultvaluer   r   r   rO      s   
rO   c                 C   s   t | ||}|jddS )zj
    Get a value from the WSGI environ dictionary as str.

    key and default should be str objects.
    r5   )errors)rO   r   r   r   r   r   r\      s   r\   N)ior   django.confr   django.corer   django.core.handlersr   django.httpr   r   r   django.urlsr	   django.utils.encodingr
   django.utils.functionalr   django.utils.regex_helperr   r   r   r'   BaseHandlerrf   r2   r1   rO   r\   r   r   r   r   <module>   s"    )C"!