;i`DddlmZddlmZddlZddlZddlZddl m Z ddl m Z ddl mZddl mZddl mZdd l mZdd l mZdd l mZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddl m!Z!ddl m"Z"ej#r ddl$m%Z%ddl$m&Z&GddeZdS)) annotationsN)BytesIO)_wsgi_decoding_dance)CombinedMultiDict)EnvironHeaders) FileStorage)ImmutableMultiDict)iter_multi_items) MultiDict) BadRequest)UnsupportedMediaTypedefault_stream_factory)FormDataParser)Request)cached_property)environ_property) _get_server)get_input_stream)WSGIApplication)WSGIEnvironmentc^eZdZUdZdZded<dZded<dZeZ ded <d ed <d ed < dXdYfd Z e dZdZ e d[dZ d\d]d"Zed^d#Zd_d%Zd`d&Zdad'Zd`d(Zdbd)Zd`d*Zedad+Zeejed,d-.Zedcd0Zej ddded5Z ej dfdgd9Z dddhd;Z edid=Z!edjd?Z"edkdAZ#edldBZ$edldCZ%ee&dDdE.Z'ee(dFdG.Z)ee(dHdI.Z*ee(dJdK.Z+e,Z-edmdLZ,e.e.fZ/dMedN<ej dndodQZ0ej dndpdSZ0 dqdpdTZ0drdWZ1xZ2S)sramRepresents 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 | Nonemax_content_lengthi max_form_memory_sizeiztype[FormDataParser]form_data_parser_classrenvironboolshallowTFpopulate_requestreturnNonec t|dd|ddt|t |dpdt |dpd|ddd t ||d  ||_||_|r|s||jd <dSdSdS) NREQUEST_METHODGETzwsgi.url_schemehttp SCRIPT_NAME PATH_INFO QUERY_STRINGlatin1 REMOTE_ADDR)methodschemeserver root_pathpath query_stringheaders remote_addrzwerkzeug.request) super__init__getrrencoderrr )selfrr!r __class__s MC:\PYTHON\MyICR_Workspace\venv\Lib\site-packages\werkzeug/wrappers/request.pyr7zRequest.__init__qs  ;;/77;;0&99w''*7;;}+E+E+KLL%gkk+&>&>&D"EE ^R88??II"7++ M22     4G 4/3DL+ , , , 4 4 4 4argst.Anykwargscddlm}||i|} |||S#|wxYw)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)EnvironBuilder)testrB get_requestclose)clsr>r@rBbuilders r< from_valueszRequest.from_valuessa& *))))) .$1&11 &&s++ MMOOOOGMMOOOOs 9Af&t.Callable[[Request], WSGIApplication]rcddlmtjd fd }t jd|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) HTTPExceptionr>r?r"cabc.Iterable[bytes]c |d}|5 |dd|fz}n@#$r8}tjd||d}Yd}~nd}~wwxYw||ddcdddS#1swxYwYdS)Nr)tcast get_response)r>requestresperLrFrIs r< applicationz(Request.application..applicationsc$r(mmG ( (O1d3B3i7*45DD$OOO6"3Q^^DH5M5MNNDDDDDDOtT"##Y'  ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (s6B)BA&.A!B!A&&BB Br)r>r?r"rM) exceptionsrL functoolswrapsrPrQ)rFrIrVrLs`` @r<rVzRequest.applicationsk0 /.....    ( ( ( ( ( ( (   (v'555r=total_content_length content_type str | Nonefilenamecontent_length t.IO[bytes]c(t||||S)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. )rZr]r[r^r)r:rZr[r]r^s r<_get_file_streamzRequest._get_file_streams'4&!5%)     r=cPt|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)rrr8r:s r<want_form_data_parsedzRequest.want_form_data_parseds"DL$$^44555r=rch||j|j|j|j|jS)zCreates the form data parser. Instantiates the :attr:`form_data_parser_class` with some parameters. .. versionadded:: 0.8 )stream_factoryrrmax_form_partsrF)rrarrrhparameter_storage_classrds r<make_form_data_parserzRequest.make_form_data_parsers? **0!%!:#6., +   r=cNd|jvrdS|jrN|}|||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__rerjparse_get_stream_for_parsingmimetyper^mimetype_paramsrmri)r:parserdatads r<_load_form_datazRequest._load_form_datas T] " " F  % //11F<<,,.. #$ DD ,,..,,..D M-1*( QvY' r=cTt|dd}|t|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)getattrrrm)r: cached_datas r<rqzRequest._get_stream_for_parsing!s1dND99  ";'' '{r=c|jd}t|pdD]\}}|dS)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 rnN)ror8r rE)r:rn_keyvalues r<rEz Request.close-sQ !!'**+EKR88  KD% KKMMMM  r=c|SNr}rds r< __enter__zRequest.__enter__8s r=c.|dSr)rE)r:exc_type exc_valuetbs r<__exit__zRequest.__exit__;s r=cd|jrtdt|j|jS)aThe 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 RuntimeErrorrrrrds r<rmzRequest.stream>sH6 < 6   LT-D    r=z 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. )docbytesc.|dS)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_datards r<ruz Request.datans}}T}222r=cacheas_textt.Literal[False]rcdSrr}r:rrrs r<rzRequest.get_dataws r=.t.Literal[True]strcdSrr}rs r<rzRequest.get_datas cr= bytes | strct|dd}|8|r||j}|r||_|r|d}|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 ryNreplace)errors)rzrwrmreadrydecode)r:rrrrvs r<rzRequest.get_datasw6T>4 0 0 : '$$&&&!!##B '$&!  -),,B r=ImmutableMultiDict[str, str]c8||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. )rwrlrds r<rlz Request.forms yr=CombinedMultiDict[str, str]c|jg}|jdkr||jg}|D];}t |t st |}||r.appendrl isinstancer r)r:sourcesr>rvs r<valueszRequest.valuess9+ ;%   NN49 % % %  Aa++ !aLL KKNNNN &&&r=$ImmutableMultiDict[str, FileStorage]c8||jS)a:class:`~werkzeug.datastructures.MultiDict` object containing all uploaded files. Each key in :attr:`files` is the name from the ````. 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. )rwrnrds r<rnz Request.filess( zr=c|jS)zgAlias for :attr:`self.root_path`. ``environ["SCRIPT_NAME"]`` without a trailing slash. )r1rds r< script_rootzRequest.script_roots ~r=c|jS)zAlias for :attr:`root_url`. The URL with scheme, host, and root path. For example, ``https://example.com/app/``. )root_urlrds r<url_rootzRequest.url_roots }r= 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.c*|S)aThe 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_jsonrds r<jsonz Request.json s }}r=ztuple[t.Any, t.Any] _cached_jsonforcesilentcdSrr}r:rrrs r<rzRequest.get_json6s r= t.Any | NonecdSrr}rs r<rzRequest.get_json;s sr=c|r!|j|tur |j|S|s |js|s|dSdS||} |j|}|r ||f|_n[#t$rN}|rd}|r|j\}}||f|_n*||}|r|j\}} || f|_Yd}~nd}~wwxYw|S)aParse :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)rEllipsisis_jsonon_json_loading_failedr json_moduleloads ValueError) r:rrrrurrU normal_rv_ silent_rvs r<rzRequest.get_json@s1.  -T&v.h>>$V, ,   224888t}}5})) -!''--B -%'H! 8 8 8 88#'#4LIq)2BD%00338#'#4LAy)+YD% 8" sB C ACCrUValueError | NonecH|td|td)aCalled 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. NzFailed to decode JSON object: z^Did not attempt to load JSON data because the request Content-Type was not 'application/json'.)r r)r:rUs r<rzRequest.on_json_loading_failedws7 =AaAABB B" 8   r=)TF)rrr!rr rr"r#)r>r?r@r?r"r)rIrJr"r)NN) rZrr[r\r]r\r^rr"r_)r"r)r"r)r"r#)r"r_)r"r)r"r)TFF)rrrrrrr"r)T.F)rrrrrrr"r)rrrrrrr"r)r"r)r"r)r"r)r"r)r"r?)...)rrrrrrr"r?)rrrrrrr"r)FFT)rUrr"r?)3__name__ __module__ __qualname____doc__r__annotations__rrhrrr7 classmethodrHrVrapropertyrerjrwrqrErrrrmrrPIOr input_streamruoverloadrrlrrnrrr remote_userris_multithreadis_multiprocess is_run_oncerrrrrr __classcell__)r;s@r<rrs&&^&*))))(/....N4BAAAA MMM "& 4444444,[4#6#6#6[#6R $%)      B666X6     2222B        " " " _" H1#ADK0    L333_3Z$) % ZZ#& % ZRW$$$$$L_$'''_'8_,X _ ("3' &K ,%d+ &N -&t, 7O )"4( KK X&*28(rs"""""" ,,,,,,......++++++((((((//////------&&&&&&######------//////''''''666666######$$$$$$######?/............k  k  k  k  k  nk  k  k  k  k  r=