U a`@sDddlZddlZddlZddlZddlZddlmZddlmZddl m Z ddl m Z ddl m Z ddl m Z dd l mZdd l mZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZejrddlZ ddl!m"Z"ddl!m#Z#GdddeZGdddZ$Gddde$eZ%dS)N)BytesIO)_wsgi_decoding_dance)CombinedMultiDict)EnvironHeaders) FileStorage)ImmutableMultiDict)iter_multi_items) MultiDictdefault_stream_factory)FormDataParser)Request)cached_property)environ_property) _get_server)get_input_stream BadRequest)WSGIApplication)WSGIEnvironmentcseZdZUdZdZejeed<dZ ejeed<e Z ej e ed<dZ ejeed<ded<eed <dUdeedd fd d ZeejejddddZeejdgdfddddZdVejeejeejeejeejdddZeedddZe dddZddddZejdd d!Zddd"d#Zddd$d%Zddd&d'Ze ejdd(d)Z!e"ejd*d+d,Z#e e$dd-d.Z%e&j'dWed/ee$d0d1d2Z(e&j'dXed4eed0d5d2Z(dYeeeej)e$efd0d6d2Z(e d7dd8d9Z*e d:dd;d<Z+e d=dd>d?Z,eedd@dAZ-e eddBdCZ.e"edDdEd,Z/e"edFdGd,Z0e"edHdId,Z1e"edJdKd,Z2e3Z4eejejddLdMZ3e5e5fZ6ej7ejejfedN<dZeeeejejdOdPdQZ8e9ejdRdSdTZ:Z;S)[raRepresents 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:: 2.0 Combine ``BaseRequest`` and mixins into a single ``Request`` class. Using the old classes is deprecated and will be removed in Werkzeug 2.1. .. versionchanged:: 0.5 Read-only mode is enforced with immutable classes for all data. Nmax_content_lengthmax_form_memory_sizeform_data_parser_classdisable_data_descriptorrenvironshallowTF)rpopulate_requestrreturnc stj|dd|ddt|t|dp.d|j|jt|dpFd|j|j|ddd t||d d ||_ |j dk rt j d t d d|p|j }||_|r|s||j d<dS)NREQUEST_METHODGETzwsgi.url_schemehttpZ SCRIPT_NAMEZ PATH_INFO QUERY_STRINGlatin1Z REMOTE_ADDR)methodschemeserver root_pathpathZ query_stringheadersZ remote_addrz|'disable_data_descriptor' is deprecated and will be removed in Werkzeug 2.1. Create the request with 'shallow=True' instead.r stacklevelzwerkzeug.request)super__init__getrrcharsetencoding_errorsencoderrrwarningswarnDeprecationWarningr)selfrrr __class__ZC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-1tps7o9u\werkzeug\wrappers\request.pyr.ks:      zRequest.__init__argskwargsrcOsJddlm}|d|j}||d<|||}z||WS|XdS)aCreate 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)EnvironBuilderr0N)testr>popr0close get_request)clsr<r=r>r0Zbuilderr9r9r: from_valuess  zRequest.from_valuesr)frcs2ddlmtfdd}td|S)amDecorate 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) HTTPExceptionc s|d}|jz|dd|f}Wn0k r\}z||d}W5d}~XYnX||ddW5QRSQRXdS)N)Z get_response)r<requestresperFrCrEr9r: applications  z(Request.application..applicationr) exceptionsrF functoolswrapstcast)rCrErLr9rKr:rLs  zRequest.application)total_content_length content_typefilenamecontent_lengthrcCst||||dS)aCalled 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. )rRrTrSrUr )r6rRrSrTrUr9r9r:_get_file_streams zRequest._get_file_stream)rcCst|jdS)z``True`` if the request method carries content. By default this is true if a ``Content-Type`` is sent. .. versionadded:: 0.8 CONTENT_TYPE)boolrr/r6r9r9r:want_form_data_parsedszRequest.want_form_data_parsedcCs ||j|j|j|j|j|jS)zCreates the form data parser. Instantiates the :attr:`form_data_parser_class` with some parameters. .. versionadded:: 0.8 )rrVr0r1rrparameter_storage_classrYr9r9r:make_form_data_parserszRequest.make_form_data_parsercCsld|jkrdS|jr8|}|||j|j|j}n|j| | f}|j}|\|d<|d<|d<dS)auMethod 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 formNstreamfiles) __dict__rZr\parse_get_stream_for_parsingmimetyperUZmimetype_paramsr^r[)r6parserdatadr9r9r:_load_form_datas zRequest._load_form_datacCs"t|dd}|dk rt|S|jS)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)getattrrr^)r6Z cached_datar9r9r:rb/s zRequest._get_stream_for_parsingcCs.|jd}t|pdD]\}}|qdS)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 r_r9N)r`r/r rA)r6r__keyvaluer9r9r:rA;s z Request.closecCs|SNr9rYr9r9r: __enter__FszRequest.__enter__cCs |dSrl)rA)r6exc_type exc_valuetbr9r9r:__exit__IszRequest.__exit__cCs|jrtdt|jS)a7 If the incoming form data was not encoded with a known mimetype the data is stored unmodified in this stream for consumption. Most of the time it is a better idea to use :attr:`data` which will give you that data as a string. The stream only returns the data once. Unlike :attr:`input_stream` this stream is properly guarded that you can't accidentally read past the length of the input. Werkzeug will internally always refer to this stream to read data which makes it possible to wrap this object with a stream that does filtering. .. versionchanged:: 0.9 This stream is now always available but might be consumed by the form parser later on. Previously the stream was only set if no parsing happened. zXThis request was created with 'shallow=True', reading from the input stream is disabled.)r RuntimeErrorrrrYr9r9r:r^Ls zRequest.streamz wsgi.inputzThe WSGI input stream. In general it's a bad idea to use this one because you can easily read past the boundary. Use the :attr:`stream` instead.)doccCs |jddS)z Contains the incoming request data as string in case it came with a mimetype Werkzeug does not handle. T)parse_form_data)get_datarYr9r9r:reosz Request.datazte.Literal[False])cacheas_textrtrcCsdSrlr9r6rvrwrtr9r9r:ruwszRequest.get_data.zte.Literal[True]cCsdSrlr9rxr9r9r:ruscCsLt|dd}|dkr4|r ||j}|r4||_|rH||j|j}|S)aThis 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 rhN)rirgr^readrhdecoder0r1)r6rvrwrtrvr9r9r:rus  zImmutableMultiDict[str, str]cCs||jS)aDThe 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. )rgr]rYr9r9r:r]sz Request.formzCombinedMultiDict[str, str]cCsP|jg}|jdkr||jg}|D] }t|ts``. 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 ``
`` 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. )rgr_rYr9r9r:r_sz Request.filescCs|jS)zgAlias for :attr:`self.root_path`. ``environ["SCRIPT_ROOT"]`` without a trailing slash. )r(rYr9r9r: script_rootszRequest.script_rootcCs|jS)zAlias for :attr:`root_url`. The URL with scheme, host, and root path. For example, ``https://example.com/app/``. )Zroot_urlrYr9r9r:url_rootszRequest.url_rootZ REMOTE_USERzIf the server supports user authentication, and the script is protected, this attribute contains the username the user has authenticated as.zwsgi.multithreadz[boolean that is `True` if the application is served by a multithreaded WSGI server.zwsgi.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.cCs|S)zThe parsed JSON data if :attr:`mimetype` indicates JSON (:mimetype:`application/json`, see :meth:`is_json`). Calls :meth:`get_json` with default arguments. )get_jsonrYr9r9r:json"sz Request.json _cached_json)forcesilentrvrc Cs|r|j|tk r|j|S|s*|js*dS|j|d}z|j|}Wnftk r}zH|rzd}|r|j\}}||f|_n"||}|r|j\}} || f|_W5d}~XYnX|r||f|_|S)a&Parse :attr:`data` as JSON. If the mimetype does not indicate JSON (:mimetype:`application/json`, see :meth:`is_json`), this returns ``None``. If parsing fails, :meth:`on_json_loading_failed` is called and its return value is used as the return value. :param force: Ignore the mimetype and always try to parse JSON. :param silent: Silence parsing errors and return ``None`` instead. :param cache: Store the parsed JSON to return for subsequent calls. N)rv)rEllipsisZis_jsonru json_moduleloads ValueErroron_json_loading_failed) r6rrrvrer{rJZ normal_rv_Z silent_rvr9r9r:r/s(        zRequest.get_json)rJrcCstd|dS)zCalled if :meth:`get_json` parsing 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`. zFailed to decode JSON object: Nr)r6rJr9r9r:r^szRequest.on_json_loading_failed)TF)NN)TFF)T.F)TFF)FFT)<__name__ __module__ __qualname____doc__rrPOptionalint__annotations__rr rTyperrXr. classmethodAnyrDCallablerLstrBinaryIOrVpropertyrZr\rgrbrArmrqrr^rZ input_streambytesretypingoverloadruUnionr]rr_rrZ remote_userZis_multithreadZis_multiprocessZ is_run_oncerrrrTuplerrr __classcell__r9r9r7r:rs (  %+ !!     &   /rcs.eZdZdZejejddfdd ZZS)StreamOnlyMixinaMixin to create a ``Request`` that disables the ``data``, ``form``, and ``files`` properties. Only ``stream`` is available. .. deprecated:: 2.0 Will be removed in Werkzeug 2.1. Create the request with ``shallow=True`` instead. .. versionadded:: 0.9 Nr;cs*tjdtddd|d<tj||dS)Nzt'StreamOnlyMixin' is deprecated and will be removed in Werkzeug 2.1. Create the request with 'shallow=True' instead.rr+Tr)r3r4r5r-r.r6r<r=r7r9r:r.rszStreamOnlyMixin.__init__rrrrrPrr.rr9r9r7r:rgs rcs.eZdZdZejejddfdd ZZS) PlainRequestzA request object without ``data``, ``form``, and ``files``. .. deprecated:: 2.0 Will be removed in Werkzeug 2.1. Create the request with ``shallow=True`` instead. .. versionadded:: 0.9 Nr;c sBtjdtddt tdttj||W5QRXdS)Nzq'PlainRequest' is deprecated and will be removed in Werkzeug 2.1. Create the request with 'shallow=True' instead.rr+ignore)r3r4r5catch_warnings simplefilterr-r.rr7r9r:r.s  zPlainRequest.__init__rr9r9r7r:r~s r)&rNrrrPr3ior _internalrZdatastructuresrrrrr r Z formparserr r Zsansio.requestrZ_SansIORequestutilsrrZwsgirrZwerkzeug.exceptionsr TYPE_CHECKINGZtyping_extensionsteZ_typeshed.wsgirrrrr9r9r9r:s>                  M