/usr/local/lib/python3.6/site-packages/werkzeug/wrappers/__pycache__
NameSizeModeActions
accept.cpython-36.pyc7600644editdlrm
auth.cpython-36.pyc13080644editdlrm
base_request.cpython-36.pyc17010644editdlrm
base_response.cpython-36.pyc17120644editdlrm
common_descriptors.cpython-36.pyc13850644editdlrm
cors.cpython-36.pyc12930644editdlrm
etag.cpython-36.pyc12930644editdlrm
json.cpython-36.pyc7520644editdlrm
request.cpython-36.pyc210660644editdlrm
response.cpython-36.pyc296130644editdlrm
user_agent.cpython-36.pyc7730644editdlrm
__init__.cpython-36.pyc8660644editdlrm
Edit: /usr/local/lib/python3.6/site-packages/werkzeug/wrappers/__pycache__/response.cpython-36.pyc (29613B)
3 _TBg@sddlZddlZddlZddlZddlmZddlmZddlm Z ddlm Z ddl m Z ddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZej r,ddl!Z"ddl#m$Z$ddl#m%Z%ddl#m&Z&ddl'm(Z(ej)ddddZ*ej)ej+e,e-fe,ej.e-dddZ/ej+e0e,fe,dd d!Z1Gd"d#d#e Z Gd$d%d%Z2Gd&d'd'Z3dS)(N) HTTPStatus) _to_bytes)Headers)remove_entity_headers)Response) iri_to_uri)url_join)cached_property)ClosingIterator)get_current_url) _get_environ) generate_etag) http_date)is_resource_modified) parse_etags)parse_range_header) _RangeWrapper) StartResponse)WSGIApplication)WSGIEnvironment)Request)iterablereturncCst|trtjddddS)znHelper for the response objects to check if the iterable returned to the WSGI server is not a string. zResponse iterable was set to a string. This will appear to work but means that the server will send the data to the client one character at a time. This is almost never intended behavior, use 'response.data' to assign strings to the response object.r) stacklevelN) isinstancestrwarningswarn)rr >/tmp/pip-build-0s3hx122/Werkzeug/werkzeug/wrappers/response.py_warn_if_string s r")rcharsetrccs0x*|D]"}t|tr"|j|Vq|VqWdS)N)rrencode)rr#itemr r r! _iter_encoded/s  r&) accept_rangesrcCs2|dkr dS|dkrdSt|tr&|StddS)NTbytesFnonezInvalid accept_ranges value)rr ValueError)r'r r r!_clean_accept_ranges9s r+cseZdZUdZdZdZdZejej e ej e f dZej ejej e e ej e e fej ejee efej ejeje eje eej eje efffej eje eje efffej e ej e eddfdd Zejgejfejgejfdd d Ze d d d Zed[dej dddddZed\ddeddddZejd]de dddZejde dddZd^eeje e fdddZeje e fddddZeeed d!Z ej ed d"d#Z!d_edd$d%d&Z"dd d'd(Z#ej$e d d)d*Z%eed d+d,Z&eed d-d.Z'dd d/d0Z(dd d1d2Z)d3d4Z*d`ddd5d6d7Z+de,d8d9d:Z-dej e d8d;d<Z.dejej e e ej/eje e ffd8d=d>Z0dd?ej e d@dAdBZ1e2Z3eej ejd dCdDZ2daeeej ejdEdFdGZ4e5dHd dIdJZ6eeddKdLdMZ7ded8dNdOZ8dbdej eej ejee fedPdQdRZ9dcejddejee fej eddTdUdVZ:deeeddWdXdYZ;Z) is_sequencesummaplen iter_encoded is_streamedtype__name__r-)r7Z body_infor r r!__repr__szResponse.__repr__r)r,environrcCs>t|ts4|dkrtdddlm}t|||}||_|S)aEnforce that the WSGI response is a response object of the current type. Werkzeug will use the :class:`Response` internally in many situations like the exceptions. If you call :meth:`get_response` on an exception you will get back a regular :class:`Response` object, even if you are using a custom subclass. This method can enforce a given response type, and it will also convert arbitrary WSGI callables into response objects if an environ is provided:: # convert a Werkzeug response object into an instance of the # MyResponseClass subclass. response = MyResponseClass.force_type(response) # convert any WSGI application into a response object response = MyResponseClass.force_type(response, environ) This is especially useful if you want to post-process responses in the main dispatcher and use functionality provided by your subclass. Keep in mind that this will modify response objects in place if possible! :param response: a response object or wsgi application. :param environ: a WSGI environment object. :return: a response object. NzHcannot convert WSGI application into response objects without an environr) run_wsgi_app)rr TypeErrortestrHr8)clsr,rGrHr r r! force_types  zResponse.force_typer)apprGbufferedrcCsddlm}|||||S)aCreate a new response object from an application output. This works best if you pass it an application that returns a generator all the time. Sometimes applications may use the `write()` callable returned by the `start_response` function. This tries to resolve such edge cases automatically. But if you don't get the expected output you should set `buffered` to `True` which enforces buffering. :param app: the WSGI application to execute. :param environ: the WSGI environment to execute against. :param buffered: set to `True` to enforce buffering. :return: a response object. r)rH)rJrH)rKrMrGrNrHr r r!from_app s zResponse.from_appzte.Literal[False])as_textrcCsdS)Nr )r7rPr r r!get_data!szResponse.get_datazte.Literal[True]cCsdS)Nr )r7rPr r r!rQ%scCs*|jdj|j}|r&|j|jS|S)aThe string representation of the response body. Whenever you call this property the response iterable is encoded and flattened. This can lead to unwanted behavior if you stream big data. This behavior can be disabled by setting :attr:`implicit_sequence_conversion` to `False`. If `as_text` is set to `True` the return value will be a decoded string. .. versionadded:: 0.9 )_ensure_sequencejoinrBdecoder#)r7rPrvr r r!rQ)s  )valuercCsDt|tr|j|j}nt|}|g|_|jr@tt||jd<dS)zSets a new string as response. The value must be a string or bytes. If a string is set it's encoded to the charset of the response (utf-8 by default). .. versionadded:: 0.9 zContent-LengthN) rrr$r#r(r, automatically_set_content_lengthrAr.)r7rWr r r!r6>s zResponse.set_dataz>A descriptor that calls :meth:`get_data` and :meth:`set_data`.)docc Cs8y |jWntk r dSXtdd|jDS)z[sz4Response.calculate_content_length..)rS RuntimeErrorr?rB)r7r r r!calculate_content_lengthUs  z!Response.calculate_content_length)mutablercCsP|jr(|r$t|jt r$t|j|_dS|jr6td|jsDtd|jdS)zThis method can be called by methods that need a sequence. If `mutable` is true, it will also ensure that the response sequence is a standard Python list. .. versionadded:: 0.6 Nz]Attempted implicit sequence conversion but the response object is in direct passthrough mode.zThe response object required the iterable to be a sequence, but the implicit conversion was disabled. Call make_sequence() yourself.)r>rr,listr1r]implicit_sequence_conversion make_sequence)r7r_r r r!rS]s zResponse._ensure_sequencecCs8|js4t|jdd}t|j|_|dk r4|j|dS)aCConverts the response iterator in a list. By default this happens automatically if required. If `implicit_sequence_conversion` is disabled, this method is not automatically called and some properties might raise exceptions. This also encodes all the items. .. versionadded:: 0.6 closeN)r>getattrr,r`rBr;)r7rcr r r!rbvs zResponse.make_sequencecCst|jt|j|jS)aIter the response encoded with the encoding of the response. If the response object is invoked as WSGI application the return value of this method is used as application iterator unless :attr:`direct_passthrough` was activated. )r"r,r&r#)r7r r r!rBs zResponse.iter_encodedc Cs,yt|jWnttfk r&dSXdS)aIf the response is streamed (the response is not an iterable with a length information) this property is `True`. In this case streamed means that there is no information about the number of iterations. This is usually `True` if a generator is passed to the response object. This is useful for checking before applying some sort of post filtering that should not take place for streamed responses. TF)rAr,rIAttributeError)r7r r r!rCs zResponse.is_streamedcCst|jttfS)zIf the iterator is buffered, this property will be `True`. A response object will consider an iterator to be buffered if the response attribute is a list or tuple. .. versionadded:: 0.6 )rr,tupler`)r7r r r!r>szResponse.is_sequencecCs0t|jdr|jjx|jD] }|qWdS)zClose the wrapped response if possible. You can also use the object in a with statement which will automatically close it. .. versionadded:: 0.9 Can now be used in a with statement. rcN)hasattrr,rcr4)r7r9r r r!rcs   zResponse.closecCs|S)Nr )r7r r r! __enter__szResponse.__enter__cCs |jdS)N)rc)r7exc_type exc_valuetbr r r!__exit__szResponse.__exit__)no_etagrcCsLt|j|_tttt|j|jd<|dk r@tj dt dd|j dS)aOMake the response object ready to be pickled. Does the following: * Buffer the response into a list, ignoring :attr:`implicity_sequence_conversion` and :attr:`direct_passthrough`. * Set the ``Content-Length`` header. * Generate an ``ETag`` header if one is not already set. .. versionchanged:: 2.0 An ``ETag`` header is added, the ``no_etag`` parameter is deprecated and will be removed in Werkzeug 2.1. .. versionchanged:: 0.6 The ``Content-Length`` header is set. zContent-LengthNzJThe 'no_etag' parameter is deprecated and will be removed in Werkzeug 2.1.r)r) r`rBr,rr?r@rAr.rrDeprecationWarningadd_etag)r7rmr r r!freezeszResponse.freeze)rGrc Cst|j}d}d}d}|j}x@|D]8\}}|j} | dkr@|}q"| dkrN|}q"| dkr"|}q"W|dk r|} t|trt|dd}|jrt|dd} t| trt| } t | |}|| kr||d<|dk rt|trt||d <d |kod kns|d kr |j d n|dkrt ||j r|j r|dkr|dkrd |koTd kn rytdd|jD}Wntk rYnXt||d <|S)akThis is automatically called right before the response is started and returns headers modified for the given environment. It returns a copy of the headers from the response with some modifications applied if necessary. For example the location header (if present) is joined with the root URL of the environment. Also the content length is automatically set to zero here for certain status codes. .. versionchanged:: 0.6 Previously that function was called `fix_headers` and modified the response object in place. Also since 0.6, IRIs in location and content-location headers are handled properly. Also starting with 0.6, Werkzeug will attempt to set the content length if it is able to figure it out on its own. This is the case if all the strings in the response iterable are already encoded and the iterable is buffered. :param environ: the WSGI environment of the request. :return: returns a new :class:`~werkzeug.datastructures.Headers` object. Nlocationzcontent-locationzcontent-lengthT)Zsafe_conversion)Zstrip_querystringLocationzContent-LocationdzContent-Length0css|]}tt|dVqdS)asciiN)rAr)rZr[r r r!r\3sz,Response.get_wsgi_headers..)rurv)rr. status_codelowerrrrautocorrect_location_headerr r removerrXr>r?r, UnicodeError) r7rGr.rqcontent_locationcontent_lengthr-keyrWikey old_locationZ current_urlr r r!get_wsgi_headerssR       "     zResponse.get_wsgi_headerscCsb|j}|ddks2d|ko$dkns2|dkr8f}n|jrNt|j|jS|j}t||jS)aReturns the application iterator for the given environ. Depending on the request method and the current status code the return value might be an empty response rather than the one from the response. If the request method is `HEAD` or the status code is in a range where the HTTP specification requires an empty response, an empty iterable is returned. .. versionadded:: 0.6 :param environ: the WSGI environment of the request. :return: a response iterable. REQUEST_METHODHEADrsrtru0)rur)rxr1r"r,rBr rc)r7rGr-rr r r! get_app_iter=s  zResponse.get_app_itercCs$|j|}|j|}||j|jfS)aFReturns the final WSGI response as tuple. The first item in the tuple is the application iterator, the second the status and the third the list of headers. The response returned is created specially for the given environment. For example if the request method in the WSGI environment is ``'HEAD'`` the response will be empty and only the headers and status code will be present. .. versionadded:: 0.6 :param environ: the WSGI environment of the request. :return: an ``(app_iter, status, headers)`` tuple. )rrr-Z to_wsgi_list)r7rGr.app_iterr r r!get_wsgi_responseZs  zResponse.get_wsgi_responser)rGstart_responsercCs|j|\}}}||||S)zProcess this response as WSGI application. :param environ: the WSGI environment. :param start_response: the response callable provided by the WSGI server. :return: an application iterator )r)r7rGrrr-r.r r r!__call__ms  zResponse.__call__cCs|jS)zThe parsed JSON data if :attr:`mimetype` indicates JSON (:mimetype:`application/json`, see :attr:`is_json`). Calls :meth:`get_json` with default arguments. )get_json)r7r r r!jsonsz Response.json)forcesilentrc CsB|p|jsdS|j}y |jj|Stk r<|s8dSXdS)aParse :attr:`data` as JSON. Useful during testing. If the mimetype does not indicate JSON (:mimetype:`application/json`, see :attr:`is_json`), this returns ``None``. Unlike :meth:`Request.get_json`, the result is not cached. :param force: Ignore the mimetype and always try to parse JSON. :param silent: Silence parsing errors and return ``None`` instead. N)Zis_jsonrQ json_moduleloadsr*)r7rrdatar r r!rs  zResponse.get_jsonResponseStreamcCst|S)z+The response iterable as write-only stream.)r)r7r r r!streamszResponse.stream)startlengthrcCs|jdkrt|j|||_dS)z8Wrap existing Response in case of Range Request context.N)rxrr,)r7rrr r r!_wrap_range_responses zResponse._wrap_range_responsecCs4d|ks,t||jjdd|jjddd o2d|kS)zReturn ``True`` if `Range` header is present and if underlying resource is considered unchanged when compared with `If-Range` header. Z HTTP_IF_RANGEetagNz last-modifiedF)Zignore_if_range HTTP_RANGE)rr.get)r7rGr r r!_is_range_request_processables   z&Response._is_range_request_processable)rGcomplete_lengthr'rc Csddlm}|dks0|dks0|dks0|j| r4dSt|jd}|dkrR|||j|}|j|}|dksv|dkr~|||d|d}||jd<||jd <||_d |_ |j |d|d S) a.Handle Range Request related headers (RFC7233). If `Accept-Ranges` header is valid, and Range Request is processable, we set the headers as described by the RFC, and wrap the underlying response in a RangeWrapper. Returns ``True`` if Range Request can be fulfilled, ``False`` otherwise. :raises: :class:`~werkzeug.exceptions.RequestedRangeNotSatisfiable` if `Range` header could not be parsed or satisfied. .. versionchanged:: 2.0 Returns ``False`` if the length is 0. r)RequestedRangeNotSatisfiableNrFrrzContent-Lengthz Accept-RangesrT) exceptionsrrrrZrange_for_lengthZto_content_range_headerr.Z content_rangerxr) r7rGrr'rZ parsed_rangeZ range_tupleZcontent_range_headerr~r r r!_process_range_requests(      zResponse._process_range_requestr)request_or_environr'rrcCst|}|ddkrd|jkr*t|jd<t|}|j|||}| rt||jjdd|jjd rt|jd r|d |_nd |_|j rd |jkr|j }|dk r||jd <|S)aMake the response conditional to the request. This method works best if an etag was defined for the response already. The `add_etag` method can be used to do that. If called without etag just the date header is set. This does nothing if the request method in the request or environ is anything but GET or HEAD. For optimal performance when handling range requests, it's recommended that your response data object implements `seekable`, `seek` and `tell` methods as described by :py:class:`io.IOBase`. Objects returned by :meth:`~werkzeug.wsgi.wrap_file` automatically implement those methods. It does not remove the body of the response because that's something the :meth:`__call__` function does for us automatically. Returns self so that you can do ``return resp.make_conditional(req)`` but modifies the object in-place. :param request_or_environ: a request object or WSGI environment to be used to make the response conditional against. :param accept_ranges: This parameter dictates the value of `Accept-Ranges` header. If ``False`` (default), the header is not set. If ``True``, it will be set to ``"bytes"``. If ``None``, it will be set to ``"none"``. If it's a string, it will use this value. :param complete_length: Will be used only in valid Range Requests. It will set `Content-Range` complete length value and compute `Content-Length` real value. This parameter is mandatory for successful Range Requests completion. :raises: :class:`~werkzeug.exceptions.RequestedRangeNotSatisfiable` if `Range` header could not be parsed or satisfied. .. versionchanged:: 2.0 Range processing is skipped if length is 0 instead of raising a 416 Range Not Satisfiable error. rGETrdateDaterNz last-modifiedZ HTTP_IF_MATCHii0zcontent-lengthzContent-Length)rr) r r.rr+rrrrrxrXr^)r7rr'rrGZis206rr r r!make_conditionals(.      zResponse.make_conditional) overwriteweakrcCs&|sd|jkr"|jt|j|dS)zAdd an etag for the current response if there is none yet. .. versionchanged:: 2.0 SHA-1 is used to generate the value. MD5 may not be available in some environments. rN)r.Zset_etagrrQ)r7rrr r r!ro:szResponse.add_etag)NNNNNF)N)F)F)F)F)N)FF)NN)FN)rr)FF)=rE __module__ __qualname____doc__rarzrXtUnionIterablerr(r,OptionalintrMappingZTupleboolr3CallableAnyr;rF classmethodrLrOtypingZoverloadrQr6propertyrr^rSrbIteratorrBrCr>rcrhrlrprrrZListrrrrrr rrrrrro __classcell__r r )r8r!rCs~ B  (  *    ]0.Frc@seZdZdZdZedddZeedddZ e j ed d d d Z d d ddZ d d ddZed ddZed ddZeed ddZd S)rzA file descriptor like object used by the :class:`ResponseStreamMixin` to represent the body of the stream. It directly pushes into the response iterable of the response object. zwb+)r,cCs||_d|_dS)NF)r,closed)r7r,r r r!r3MszResponseStream.__init__)rWrcCsB|jrtd|jjdd|jjj||jjjddt|S)NzI/O operation on closed fileT)r_zContent-Length)rr*r,rSr:r.poprA)r7rWr r r!writeQs zResponseStream.writeN)seqrcCsx|D]}|j|qWdS)N)r)r7rr%r r r! writelinesYs zResponseStream.writelines)rcCs d|_dS)NT)r)r7r r r!rc]szResponseStream.closecCs|jrtddS)NzI/O operation on closed file)rr*)r7r r r!flush`szResponseStream.flushcCs|jrtddS)NzI/O operation on closed fileF)rr*)r7r r r!isattydszResponseStream.isattycCs|jjttt|jjS)N)r,rSr?r@rA)r7r r r!tellis zResponseStream.tellcCs|jjS)N)r,r#)r7r r r!encodingmszResponseStream.encoding)rErrrmoderr3r(rrrrrrcrrrrrrrr r r r!rEsrcs*eZdZejejddfdd ZZS)ResponseStreamMixinN)argskwargsrcs"tjdtddtj||dS)Nz|'ResponseStreamMixin' is deprecated and will be removed in Werkzeug 2.1. 'Response' now includes the functionality directly.r)r)rrrnr2r3)r7rr)r8r r!r3ss zResponseStreamMixin.__init__)rErrrrr3rr r )r8r!rrsr)4rrrrhttprZ _internalrZdatastructuresrrZsansio.responserZ_SansIOResponseurlsrr utilsr Zwsgir r Zwerkzeug._internalr Z werkzeug.httprrrrrZ werkzeug.wsgirZ TYPE_CHECKINGZtyping_extensionsteZ_typeshed.wsgirrrrequestrrr"rrr(rr&rr+rrr r r r!sN                      -