o
    'h`                     @  s.  d dl mZ d dlm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 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 ddlmZ ddlmZ ddl m!Z! ddl m"Z" ej#rd dl$m%Z% d dl$m&Z& G dd deZdS )    )annotationsN)BytesIO   )_wsgi_decoding_dance)CombinedMultiDict)EnvironHeaders)FileStorage)ImmutableMultiDict)iter_multi_items)	MultiDict)
BadRequest)UnsupportedMediaTypedefault_stream_factory)FormDataParser)Request)cached_property)environ_property)_get_server)get_input_stream)WSGIApplication)WSGIEnvironmentc                      s0  e Zd ZU dZdZded< dZded< dZeZ	ded	< d
ed< ded< 		dndo fddZ
edpddZedqddZ		drdsd%d&Zedtd'd(Zdud*d+Zdvd,d-Zdwd.d/Zdvd0d1Zdxd2d3Zdvd4d5Zedwd6d7Zeeje  d8d9d:Zedyd<d=Zej			dzd{dBdCZ ej		D	d|d}dGdCZ 	dzd~dIdCZ eddKdLZ!eddNdOZ"eddQdRZ#eddSdTZ$eddUdVZ%ee& dWdXd:Z'ee( dYdZd:Z)ee( d[d\d:Z*ee( d]d^d:Z+e,Z-edd`daZ,e.e.fZ/dbedc< ej	DdddfdgZ0ej	DdddhdgZ0	dddidgZ0ddldmZ1  Z2S )r   am  Represents an incoming WSGI HTTP request, with headers and body
    taken from the WSGI environment. Has properties and methods for
    using the functionality defined by various HTTP specs. The data in
    requests object is read-only.

    Text data is assumed to use UTF-8 encoding, which should be true for
    the vast majority of modern clients. Using an encoding set by the
    client is unsafe in Python due to extra encodings it provides, such
    as ``zip``. To change the assumed encoding, subclass and replace
    :attr:`charset`.

    :param environ: The WSGI environ is generated by the WSGI server and
        contains information about the server configuration and client
        request.
    :param populate_request: Add this request object to the WSGI environ
        as ``environ['werkzeug.request']``. Can be useful when
        debugging.
    :param shallow: Makes reading from :attr:`stream` (and any method
        that would read from it) raise a :exc:`RuntimeError`. Useful to
        prevent consuming the form data in middleware, which would make
        it unavailable to the final application.

    .. versionchanged:: 3.0
        The ``charset``, ``url_charset``, and ``encoding_errors`` parameters
        were removed.

    .. versionchanged:: 2.1
        Old ``BaseRequest`` and mixin classes were removed.

    .. versionchanged:: 2.1
        Remove the ``disable_data_descriptor`` attribute.

    .. versionchanged:: 2.0
        Combine ``BaseRequest`` and mixins into a single ``Request``
        class.

    .. versionchanged:: 0.5
        Read-only mode is enforced with immutable classes for all data.
    N
int | Nonemax_content_lengthi  max_form_memory_sizei  ztype[FormDataParser]form_data_parser_classr   environboolshallowTFpopulate_requestreturnNonec                   s   t  j|dd|ddt|t|dpdt|dpd|ddd	t||d
d || _|| _|rC|sE| | jd< d S d S d S )NREQUEST_METHODGETzwsgi.url_schemehttpSCRIPT_NAME 	PATH_INFOQUERY_STRINGlatin1REMOTE_ADDR)methodschemeserver	root_pathpathquery_stringheadersremote_addrzwerkzeug.request)	super__init__getr   r   encoder   r   r   )selfr   r   r   	__class__ U/var/www/html/olx_land/venv/lib/python3.10/site-packages/werkzeug/wrappers/request.pyr4   q   s   


zRequest.__init__argst.Anykwargsc                 O  s:   ddl m} ||i |}z
|| W |  S |  w )a  Create a new request object based on the values provided.  If
        environ is given missing values are filled from there.  This method is
        useful for small scripts when you need to simulate a request from an URL.
        Do not use this method for unittesting, there is a full featured client
        object (:class:`Client`) that allows to create multipart requests,
        support for cookies etc.

        This accepts the same options as the
        :class:`~werkzeug.test.EnvironBuilder`.

        .. versionchanged:: 0.5
           This method now accepts the same arguments as
           :class:`~werkzeug.test.EnvironBuilder`.  Because of this the
           `environ` parameter is now called `environ_overrides`.

        :return: request object
        r   )EnvironBuilder)testr?   get_requestclose)clsr<   r>   r?   builderr:   r:   r;   from_values   s
   
zRequest.from_valuesf&t.Callable[[Request], WSGIApplication]r   c                   s4   ddl m  td fdd}td	|S )am  Decorate a function as responder that accepts the request as
        the last argument.  This works like the :func:`responder`
        decorator but the function is passed the request object as the
        last argument and the request object will be closed
        automatically::

            @Request.application
            def my_wsgi_app(request):
                return Response('Hello World!')

        As of Werkzeug 0.14 HTTP exceptions are automatically caught and
        converted to responses instead of failing.

        :param f: the WSGI callable to decorate
        :return: a new WSGI callable
        r   )HTTPExceptionr<   r=   r    cabc.Iterable[bytes]c                    s   | d }|; z| d d |f  }W n  y3 } zt d|| d }W Y d }~nd }~ww || dd   W  d    S 1 sFw   Y  d S )Nr   )tcastget_response)r<   requestresperH   rC   rF   r:   r;   application   s   "$z(Request.application.<locals>.applicationr   N)r<   r=   r    rI   )
exceptionsrH   	functoolswrapsrK   rL   )rC   rF   rR   r:   rQ   r;   rR      s   	zRequest.applicationtotal_content_lengthcontent_type
str | Nonefilenamecontent_lengtht.IO[bytes]c                 C  s   t ||||dS )a  Called to get a stream for the file upload.

        This must provide a file-like class with `read()`, `readline()`
        and `seek()` methods that is both writeable and readable.

        The default implementation returns a temporary file if the total
        content length is higher than 500KB.  Because many browsers do not
        provide a content length for the files only the total content
        length matters.

        :param total_content_length: the total content length of all the
                                     data in the request combined.  This value
                                     is guaranteed to be there.
        :param content_type: the mimetype of the uploaded file.
        :param filename: the filename of the uploaded file.  May be `None`.
        :param content_length: the length of this file.  This value is usually
                               not provided because webbrowsers do not provide
                               this value.
        )rV   rY   rW   rZ   r   )r7   rV   rW   rY   rZ   r:   r:   r;   _get_file_stream   s   zRequest._get_file_streamc                 C  s   t | jdS )z``True`` if the request method carries content. By default
        this is true if a ``Content-Type`` is sent.

        .. versionadded:: 0.8
        CONTENT_TYPE)r   r   r5   r7   r:   r:   r;   want_form_data_parsed   s   zRequest.want_form_data_parsedr   c                 C  s   | j | j| j| j| j| jdS )zCreates the form data parser. Instantiates the
        :attr:`form_data_parser_class` with some parameters.

        .. versionadded:: 0.8
        )stream_factoryr   r   max_form_partsrC   )r   r\   r   r   ra   parameter_storage_classr^   r:   r:   r;   make_form_data_parser   s   zRequest.make_form_data_parserc                 C  sl   d| j v rdS | jr|  }||  | j| j| j}n
| j| 	 | 	 f}| j }|\|d< |d< |d< dS )au  Method used internally to retrieve submitted data.  After calling
        this sets `form` and `files` on the request object to multi dicts
        filled with the incoming form data.  As a matter of fact the input
        stream will be empty afterwards.  You can also call this method to
        force the parsing of the form data.

        .. versionadded:: 0.8
        formNstreamfiles)
__dict__r_   rc   parse_get_stream_for_parsingmimetyperZ   mimetype_paramsre   rb   )r7   parserdatadr:   r:   r;   _load_form_data   s    

zRequest._load_form_datac                 C  s"   t | dd}|durt|S | jS )zThis is the same as accessing :attr:`stream` with the difference
        that if it finds cached data from calling :meth:`get_data` first it
        will create a new stream out of the cached data.

        .. versionadded:: 0.9.3
        _cached_dataN)getattrr   re   )r7   cached_datar:   r:   r;   ri   !  s   zRequest._get_stream_for_parsingc                 C  s.   | j d}t|p
dD ]\}}|  qdS )zCloses associated resources of this request object.  This
        closes all file handles explicitly.  You can also use the request
        object in a with statement which will automatically close it.

        .. versionadded:: 0.9
        rf   r:   N)rg   r5   r
   rB   )r7   rf   _keyvaluer:   r:   r;   rB   -  s   
zRequest.closec                 C  s   | S Nr:   r^   r:   r:   r;   	__enter__8  s   zRequest.__enter__c                 C  s   |    d S ru   )rB   )r7   exc_type	exc_valuetbr:   r:   r;   __exit__;  s   zRequest.__exit__c                 C  s   | j rtdt| j| jdS )a  The WSGI input stream, with safety checks. This stream can only be consumed
        once.

        Use :meth:`get_data` to get the full data as bytes or text. The :attr:`data`
        attribute will contain the full bytes only if they do not represent form data.
        The :attr:`form` attribute will contain the parsed form data in that case.

        Unlike :attr:`input_stream`, this stream guards against infinite streams or
        reading past :attr:`content_length` or :attr:`max_content_length`.

        If ``max_content_length`` is set, it can be enforced on streams if
        ``wsgi.input_terminated`` is set. Otherwise, an empty stream is returned.

        If the limit is reached before the underlying stream is exhausted (such as a
        file that is too large, or an infinite stream), the remaining contents of the
        stream cannot be read safely. Depending on how the server handles this, clients
        may show a "connection reset" failure instead of seeing the 413 response.

        .. versionchanged:: 2.3
            Check ``max_content_length`` preemptively and while reading.

        .. versionchanged:: 0.9
            The stream is always set (but may be consumed) even if form parsing was
            accessed first.
        zXThis request was created with 'shallow=True', reading from the input stream is disabled.)r   )r   RuntimeErrorr   r   r   r^   r:   r:   r;   re   >  s   zRequest.streamz
wsgi.inputzThe raw WSGI input stream, without any safety checks.

        This is dangerous to use. It does not guard against infinite streams or reading
        past :attr:`content_length` or :attr:`max_content_length`.

        Use :attr:`stream` instead.
        )docbytesc                 C  s   | j ddS )zThe raw data read from :attr:`stream`. Will be empty if the request
        represents form data.

        To get the raw data even if it represents form data, use :meth:`get_data`.
        T)parse_form_data)get_datar^   r:   r:   r;   rm   n  s   zRequest.datacacheas_textt.Literal[False]r~   c                 C     d S ru   r:   r7   r   r   r~   r:   r:   r;   r   w     zRequest.get_data.t.Literal[True]strc                 C  r   ru   r:   r   r:   r:   r;   r     r   bytes | strc                 C  sH   t | dd}|du r|r|   | j }|r|| _|r"|jdd}|S )a  This reads the buffered incoming data from the client into one
        bytes object.  By default this is cached but that behavior can be
        changed by setting `cache` to `False`.

        Usually it's a bad idea to call this method without checking the
        content length first as a client could send dozens of megabytes or more
        to cause memory problems on the server.

        Note that if the form data was already parsed this method will not
        return anything as form data parsing does not cache the data like
        this method does.  To implicitly invoke form data parsing function
        set `parse_form_data` to `True`.  When this is done the return value
        of this method will be an empty string if the form parser handles
        the data.  This generally is not necessary as if the whole data is
        cached (which is the default) the form parser will used the cached
        data to parse the form data.  Please be generally aware of checking
        the content length first in any case before calling this method
        to avoid exhausting server memory.

        If `as_text` is set to `True` the return value will be a decoded
        string.

        .. versionadded:: 0.9
        rp   Nreplace)errors)rq   ro   re   readrp   decode)r7   r   r   r~   rvr:   r:   r;   r     s   
ImmutableMultiDict[str, str]c                 C     |    | jS )aD  The form parameters.  By default an
        :class:`~werkzeug.datastructures.ImmutableMultiDict`
        is returned from this function.  This can be changed by setting
        :attr:`parameter_storage_class` to a different type.  This might
        be necessary if the order of the form data is important.

        Please keep in mind that file uploads will not end up here, but instead
        in the :attr:`files` attribute.

        .. versionchanged:: 0.9

            Previous to Werkzeug 0.9 this would only contain form data for POST
            and PUT requests.
        )ro   rd   r^   r:   r:   r;   rd     s   zRequest.formCombinedMultiDict[str, str]c                 C  sP   | j g}| jdkr|| j g }|D ]}t|tst|}|| qt|S )a  A :class:`werkzeug.datastructures.CombinedMultiDict` that
        combines :attr:`args` and :attr:`form`.

        For GET requests, only ``args`` are present, not ``form``.

        .. versionchanged:: 2.0
            For GET requests, only ``args`` are present, not ``form``.
        r#   )r<   r+   appendrd   
isinstancer   r   )r7   sourcesr<   rn   r:   r:   r;   values  s   


zRequest.values$ImmutableMultiDict[str, FileStorage]c                 C  r   )a  :class:`~werkzeug.datastructures.MultiDict` object containing
        all uploaded files.  Each key in :attr:`files` is the name from the
        ``<input type="file" name="">``.  Each value in :attr:`files` is a
        Werkzeug :class:`~werkzeug.datastructures.FileStorage` object.

        It basically behaves like a standard file object you know from Python,
        with the difference that it also has a
        :meth:`~werkzeug.datastructures.FileStorage.save` function that can
        store the file on the filesystem.

        Note that :attr:`files` will only contain data if the request method was
        POST, PUT or PATCH and the ``<form>`` that posted to the request had
        ``enctype="multipart/form-data"``.  It will be empty otherwise.

        See the :class:`~werkzeug.datastructures.MultiDict` /
        :class:`~werkzeug.datastructures.FileStorage` documentation for
        more details about the used data structure.
        )ro   rf   r^   r:   r:   r;   rf     s   zRequest.filesc                 C     | j S )zgAlias for :attr:`self.root_path`. ``environ["SCRIPT_ROOT"]``
        without a trailing slash.
        )r.   r^   r:   r:   r;   script_root     zRequest.script_rootc                 C  r   )zAlias for :attr:`root_url`. The URL with scheme, host, and
        root path. For example, ``https://example.com/app/``.
        )root_urlr^   r:   r:   r;   url_root  r   zRequest.url_rootREMOTE_USERzIf the server supports user authentication, and the
        script is protected, this attribute contains the username the
        user has authenticated as.zwsgi.multithreadz[boolean that is `True` if the application is served by a
        multithreaded WSGI server.zwsgi.multiprocesszlboolean that is `True` if the application is served by a
        WSGI server that spawns multiple processes.zwsgi.run_oncezboolean that is `True` if the application will be
        executed only once in a process lifetime.  This is the case for
        CGI for example, but it's not guaranteed that the execution only
        happens one time.t.Any | Nonec                 C  s   |   S )a  The parsed JSON data if :attr:`mimetype` indicates JSON
        (:mimetype:`application/json`, see :attr:`is_json`).

        Calls :meth:`get_json` with default arguments.

        If the request content type is not ``application/json``, this
        will raise a 415 Unsupported Media Type error.

        .. versionchanged:: 2.3
            Raise a 415 error instead of 400.

        .. versionchanged:: 2.1
            Raise a 400 error if the content type is incorrect.
        )get_jsonr^   r:   r:   r;   json   s   zRequest.jsonztuple[t.Any, t.Any]_cached_jsonforcesilentc                 C  r   ru   r:   r7   r   r   r   r:   r:   r;   r   6     zRequest.get_jsonc                 C  r   ru   r:   r   r:   r:   r;   r   ;  r   c           
   
   C  s   |r| j | tur| j | S |s| js|s| dS dS | j|d}z| j|}W nC tym } z7|rCd}|rB| j \}}||f| _ n| |}|r[| j \}}	||	f| _ W Y d}~|S W Y d}~|S W Y d}~|S d}~ww |ru||f| _ |S )a  Parse :attr:`data` as JSON.

        If the mimetype does not indicate JSON
        (:mimetype:`application/json`, see :attr:`is_json`), or parsing
        fails, :meth:`on_json_loading_failed` is called and
        its return value is used as the return value. By default this
        raises a 415 Unsupported Media Type resp.

        :param force: Ignore the mimetype and always try to parse JSON.
        :param silent: Silence mimetype and parsing errors, and
            return ``None`` instead.
        :param cache: Store the parsed JSON to return for subsequent
            calls.

        .. versionchanged:: 2.3
            Raise a 415 error instead of 400.

        .. versionchanged:: 2.1
            Raise a 400 error if the content type is incorrect.
        N)r   )r   Ellipsisis_jsonon_json_loading_failedr   json_moduleloads
ValueError)
r7   r   r   r   rm   r   rP   	normal_rv_	silent_rvr:   r:   r;   r   @  s<   








 
rP   ValueError | Nonec                 C  s   |durt d| td)a  Called if :meth:`get_json` fails and isn't silenced.

        If this method returns a value, it is used as the return value
        for :meth:`get_json`. The default implementation raises
        :exc:`~werkzeug.exceptions.BadRequest`.

        :param e: If parsing failed, this is the exception. It will be
            ``None`` if the content type wasn't ``application/json``.

        .. versionchanged:: 2.3
            Raise a 415 error instead of 400.
        NzFailed to decode JSON object: z^Did not attempt to load JSON data because the request Content-Type was not 'application/json'.)r   r   )r7   rP   r:   r:   r;   r   w  s
   zRequest.on_json_loading_failed)TF)r   r   r   r   r   r   r    r!   )r<   r=   r>   r=   r    r   )rF   rG   r    r   )NN)
rV   r   rW   rX   rY   rX   rZ   r   r    r[   )r    r   )r    r   )r    r!   )r    r[   )r    r   )r    r}   )TFF)r   r   r   r   r~   r   r    r}   )T.F)r   r   r   r   r~   r   r    r   )r   r   r   r   r~   r   r    r   )r    r   )r    r   )r    r   )r    r   )r    r   )...)r   r   r   r   r   r   r    r=   )r   r   r   r   r   r   r    r   )FFT)rP   r   r    r=   )3__name__
__module____qualname____doc__r   __annotations__r   ra   r   r   r4   classmethodrE   rR   r\   propertyr_   rc   ro   ri   rB   rv   rz   r   re   r   rK   IOr}   input_streamrm   overloadr   rd   r   rf   r   r   r   remote_userr   is_multithreadis_multiprocessis_run_oncer   r   r   r   r   r   __classcell__r:   r:   r8   r;   r      s   
 /)!


!


$&7r   )'
__future__r   collections.abcabccabcrT   r   typingrK   ior   	_internalr   datastructuresr   r   r   r	   r
   r   rS   r   r   
formparserr   r   sansio.requestr   _SansIORequestutilsr   r   wsgir   r   TYPE_CHECKING_typeshed.wsgir   r   r:   r:   r:   r;   <module>   s4    