U a @s~ddlZddlZddlZddlZddlmZddlmZddlmZddl m Z ddl m Z ddl mZddlmZdd lmZdd lmZdd lmZd d lmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlm Z d dlm!Z!d dlm"Z"d dl#m$Z$d dl#m%Z%d dl#m&Z&d dl'm(Z(d dl'm)Z)d dl'm*Z*d dl'm+Z+d dl'm,Z,d d l'm-Z-d d!l.m/Z/d d"l.m0Z0d d#l.m1Z1d d$l.m2Z2d d%l.m3Z3d d&l.m4Z4d d'l5m6Z6d d l7mZd d(l8m9Z9d d)l:m;Z;d d*l:mm?Z?dd,l>m@Z@dRejAeBejCfeDeEejFeBeBejGejHeEeBfd0d1d2ZIdSejAeBejCfejFeBeBejGeBeJfd3d4d5ZKGd6d7d7ZLGd8d9d9ZMGd:d;d;e ZNejAeBejCfejOejGeBejCfd<d=d>ZPejQd?e"d@ZRGdAdBdBZSGdCdDdDeTZUGdEdFdFZVejCejCdGdHdIdJZWdTdLdGeDejGejXeJeBe!fdMdNdOZYGdPdQdQe9ZZdS)UN) defaultdict)datetime) timedelta) CookieJar)BytesIO)chain)random) TemporaryFile)time)Request) _get_environ)_make_encode_wrapper)_wsgi_decoding_dance)_wsgi_encoding_dance) Authorization) CallbackDict)CombinedMultiDict)EnvironHeaders) FileMultiDict)Headers) MultiDict) dump_cookie)dump_options_header)parse_options_header)Data)Epilogue)Field)File)MultipartEncoder)Preamble) iri_to_uri) url_encode)url_fix) url_parse) url_unparse) url_unquote)get_content_type)Response)ClosingIterator)get_current_url)WSGIApplication)WSGIEnvironmentTutf-8)data use_tempfile thresholdboundarycharsetreturnc s|dkrdtt}tdd|rHttdfdd }nj}t|}||t dd t |D]\}}t |d d} | dk rJt |d t |d d} t |d d} | dkr| rt | dpd} td| fg} | dkr||t|| dn||t|| | d| d} | s.q||t| ddqqvt|ts^t|}||t|td||t||ddqv||tdd }d||fS)zEncode a dict of values (either strings or file descriptors or :class:`FileStorage` objects.) into a multipart encoded string stored in a file descriptor. Nz ---------------WerkzeugFormPart_rF)sr4cspr|St|}|kr.|n2ttjtd}||||d|7|SdS)Nzwb+T)writelentcastBinaryIOr getvalue)r5lengthZ new_streamZon_diskstreamr1 total_lengthNC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-1tps7o9u\werkzeug\test.py write_binaryIs    z-stream_encode_multipart..write_binary)r/readfilenamename content_typezapplication/octet-stream Content-Type)rFheaders)rFrErIi@T)r/Z more_data)r rrbytesintr6rencodeZ send_eventr _iter_datagetattr mimetypes guess_typerrrr isinstancestrrtellseek)r/r0r1r2r3rBencoderkeyvaluereaderrErGrIchunkr<r@r=rAstream_encode_multipart5sV          rZ)valuesr2r3r4cCs"t|d||d\}}}||fS)zuLike `stream_encode_multipart` but returns a tuple in the form (``boundary``, ``data``) where data is bytes. F)r0r2r3)rZrD)r[r2r3r>r<r@r@rAencode_multiparts r\c@sveZdZdZejeejeje e ffddddZ e ej e dddZ d e ej ej e ej e d d d ZdS) _TestCookieHeaderszA headers adapter for cookielibNrIr4cCs ||_dSNrIselfrIr@r@rA__init__sz_TestCookieHeaders.__init__)rFr4cCs6g}|}|jD]\}}||kr||q|Sr_)lowerrIappend)rbrFrIkvr@r@rA getheaderss   z_TestCookieHeaders.getheaders)rFdefaultr4cCs||}|s|S|Sr_)rh)rbrFrirIr@r@rAget_alls z_TestCookieHeaders.get_all)N)__name__ __module__ __qualname____doc__r8UnionrListTuplerRrcIterablerhOptionalrjr@r@r@rAr]s* r]c@sHeZdZdZejeejeje e ffddddZ e dddZ dS) _TestCookieResponsezSomething that looks like a httplib.HTTPResponse, but is actually just an adapter for our test responses to make them available for cookielib. Nr^cCst||_dSr_)r]rIrar@r@rArcsz_TestCookieResponse.__init__r4cCs|jSr_r`rbr@r@rAinfosz_TestCookieResponse.info) rkrlrmrnr8rorrprqrRrcr]rwr@r@r@rArts*rtc@sLeZdZdZdddddZdejeejej e e ffdddd Z dS) _TestCookieJarzA cookielib.CookieJar modified to inject and read cookie headers from and to wsgi environments, and wsgi application responses. r,N)environr4cCs2dd|D}|r"d||d<n |dddS)zYInject the cookies as client headers into the server's wsgi environment. cSsg|]}|jd|jqS)=)rFrW).0cr@r@rA sz._TestCookieJar.inject_wsgi..z; Z HTTP_COOKIEN)joinpop)rbryZcvalsr@r@rA inject_wsgisz_TestCookieJar.inject_wsgi)ryrIr4cCs|t|tt|dS)zXExtract the server's set-cookie headers as cookies into the cookie jar. N)extract_cookiesrt_UrllibRequestr*)rbryrIr@r@rA extract_wsgis z_TestCookieJar.extract_wsgi) rkrlrmrnrr8rorrprqrRrr@r@r@rArxs  rx)r/r4ccs^t|tr|jddEdHn<|D]2\}}t|trN|D]}||fVqd?Z2e2j%e j eddd@d?Z2e#eddAdBZ3e#eddCdDZ4dddEdFZ5dddGdHZ6dddIdJZ7dOe j e j*eedKdLdMZ8dS)PEnvironBuilderaThis class can be used to conveniently create a WSGI environment for testing purposes. It can be used to quickly create WSGI environments or request objects from arbitrary data. The signature of this class is also used in some other places as of Werkzeug 0.5 (:func:`create_environ`, :meth:`Response.from_values`, :meth:`Client.open`). Because of this most of the functionality is available through the constructor alone. Files and regular form data can be manipulated independently of each other with the :attr:`form` and :attr:`files` attributes, but are passed with the same argument to the constructor: `data`. `data` can be any of these values: - a `str` or `bytes` object: The object is converted into an :attr:`input_stream`, the :attr:`content_length` is set and you have to provide a :attr:`content_type`. - a `dict` or :class:`MultiDict`: The keys have to be strings. The values have to be either any of the following objects, or a list of any of the following objects: - a :class:`file`-like object: These are converted into :class:`FileStorage` objects automatically. - a `tuple`: The :meth:`~FileMultiDict.add_file` method is called with the key and the unpacked `tuple` items as positional arguments. - a `str`: The string is set as form data for the associated key. - a file-like object: The object content is loaded in memory and then handled like a regular `str` or a `bytes`. :param path: the path of the request. In the WSGI environment this will end up as `PATH_INFO`. If the `query_string` is not defined and there is a question mark in the `path` everything after it is used as query string. :param base_url: the base URL is a URL that is used to extract the WSGI URL scheme, host (server name + server port) and the script root (`SCRIPT_NAME`). :param query_string: an optional string or dict with URL parameters. :param method: the HTTP method to use, defaults to `GET`. :param input_stream: an optional input stream. Do not specify this and `data`. As soon as an input stream is set you can't modify :attr:`args` and :attr:`files` unless you set the :attr:`input_stream` to `None` again. :param content_type: The content type for the request. As of 0.5 you don't have to provide this when specifying files and form data via `data`. :param content_length: The content length for the request. You don't have to specify this when providing data via `data`. :param errors_stream: an optional error stream that is used for `wsgi.errors`. Defaults to :data:`stderr`. :param multithread: controls `wsgi.multithread`. Defaults to `False`. :param multiprocess: controls `wsgi.multiprocess`. Defaults to `False`. :param run_once: controls `wsgi.run_once`. Defaults to `False`. :param headers: an optional list or :class:`Headers` object of headers. :param data: a string or dict of form data or a file-object. See explanation above. :param json: An object to be serialized and assigned to ``data``. Defaults the content type to ``"application/json"``. Serialized with the function assigned to :attr:`json_dumps`. :param environ_base: an optional dict of environment defaults. :param environ_overrides: an optional dict of environment overrides. :param charset: the charset used to encode string data. :param auth: An authorization object to use for the ``Authorization`` header value. A ``(username, password)`` tuple is a shortcut for ``Basic`` authorization. .. versionchanged:: 2.0 ``REQUEST_URI`` and ``RAW_URI`` is the full raw URI including the query string, not only the path. .. versionchanged:: 2.0 The default :attr:`request_class` is ``Request`` instead of ``BaseRequest``. .. versionadded:: 2.0 Added the ``auth`` parameter. .. versionadded:: 0.15 The ``json`` param and :meth:`json_dumps` method. .. versionadded:: 0.15 The environ has keys ``REQUEST_URI`` and ``RAW_URI`` containing the path before perecent-decoding. This is not part of the WSGI PEP, but many WSGI servers include it. .. versionchanged:: 0.6 ``path`` and ``base_url`` can now be unicode strings that are encoded with :func:`iri_to_uri`. zHTTP/1.1)r rrN_args _query_string _input_stream_form_files/GETFr.)pathbase_url query_stringmethod input_streamrGcontent_length errors_stream multithread multiprocessrun_oncerIr/ environ_baseenviron_overridesr3mimetypejsonauthr4cCst|}|dk r$|d|kr$tdt|}|dkrF|d|krF|j}||_t|j|_||_|dk rvtt|||}||_ t |t t fr||_ n(|dkrt}nt |tst|}||_||_| dkrt} nt | tst| } | |_|dk r||_|dkrtj}||_| |_| |_| |_||_||_||_||_d|_|dk r|t |trjt d|d|dd}|j!d|"|dk r| dk rt#d |$|} |jdkrd |_| rv|dk rt#d t%| d r| &} t | t r| '|j} t | t r&t(| |_|jdkrvt)| |_nPt*| D]F\}}t |tt+fsRt%|d r`|,||n|j-.|/|q.|dk r||_0dS) N?z6Query string is defined in the path and as an argumentFbasicrr )usernamepasswordrz can't provide both json and datazapplication/jsonz#can't provide input stream and datarD)1r ValueErrorr$queryr3r!r request_urir#rrQrJrRrrargsrrrIrGsysstderrrrrrrrrrclosedtuplersetZ to_header TypeError json_dumpshasattrrDrLrr7rMdict_add_file_from_dataformZsetlistdefaultrer)rbrrrrrrGrrrrrrIr/rrr3rrrZpath_srrVrWr@r@rArcbs                   zEnvironBuilder.__init__r,)rykwargsr4c Kstt|}t|d||d|dt|dt|d|d|d|dd |d d |d |d |d |d|d }|||f|S)a-Turn an environ dict back into a builder. Any extra kwargs override the args extracted from the environ. .. versionchanged:: 2.0 Path and query values are passed through the WSGI decoding dance to avoid double encoding. .. versionadded:: 0.15 PATH_INFOwsgi.url_schemeHost SCRIPT_NAME QUERY_STRINGREQUEST_METHOD wsgi.inputrHNContent-Length wsgi.errorswsgi.multithreadwsgi.multiprocess wsgi.run_once) rrrrrrGrrrrrrI)rrr_make_base_urlrupdate)clsryrrIoutr@r@rA from_environs(       zEnvironBuilder.from_environ)rVrWr4cCs0t|tr|jj|f|n|j||dS)z=Called in the EnvironBuilder to add files from the data dict.N)rQrfilesZadd_file)rbrVrWr@r@rArs z"EnvironBuilder._add_file_from_data)schemehost script_rootr4cCst|||ddfddS)Nr)r%rstrip)rrrr@r@rArszEnvironBuilder._make_base_urlrucCs||j|j|jS)z`The base URL is used to extract the URL scheme, host name, port, and root path. )r url_schemerrrvr@r@rArszEnvironBuilder.base_url)rWr4cCsT|dkrd}d}d}n"t|\}}}}}|s0|r8td|d|_||_||_dS)Nhttp localhostrz4base url must not contain a query string or fragmentr)r$rrrrr)rbrWrnetlocrqsanchorr@r@rArs cCs6|jd}|dkr2|js2|jr$dS|jr.dSdS|S)zThe content type for the request. Reflected from and to the :attr:`headers`. Do not set if you set :attr:`files` or :attr:`form` for auto detection. rHNmultipart/form-data!application/x-www-form-urlencoded)rIgetrrrrbctr@r@rArGs zEnvironBuilder.content_typecCs&|dkr|jddn ||jd<dSNrH)rIrrbrWr@r@rArGscCs |j}|r|ddSdS)zYThe mimetype (content type without charset etc.) .. versionadded:: 0.14 ;rN)rGsplitstriprr@r@rAr%szEnvironBuilder.mimetypecCst||j|_dSr_)r'r3rGrr@r@rAr.scs>tjttfddfdd }tjddd}t||S)zThe mimetype parameters as dict. For example if the content type is ``text/html; charset=utf-8`` the params would be ``{'charset': 'utf-8'}``. .. versionadded:: 0.14 N)dr4cstj|jd<dSr)rrrI)rrvr@rA on_update;sz1EnvironBuilder.mimetype_params..on_updatez content-typerr )r8MappingrRrrIrr)rbrrr@rvrAmimetype_params2s zEnvironBuilder.mimetype_paramscCs|jjdtdS)zThe content length as integer. Reflected from and to the :attr:`headers`. Do not set if you set :attr:`files` or :attr:`form` for auto detection. r)type)rIrrKrvr@r@rArAszEnvironBuilder.content_lengthcCs*|dkr|jddnt||jd<dS)Nr)rIrrRrr@r@rArIs)rFstorager4cCs:|jdk rtdt||}|dkr6|}t||||S)zCommon behavior for getting the :attr:`form` and :attr:`files` properties. :param name: Name of the internal cached attribute. :param storage: Storage class used for the data. Nzan input stream is defined)rAttributeErrorrNsetattr)rbrFrrvr@r@rA _get_formPs   zEnvironBuilder._get_form)rFrWr4cCsd|_t|||dS)zCommon behavior for setting the :attr:`form` and :attr:`files` properties. :param name: Name of the internal cached attribute. :param value: Value to assign to the attribute. N)rr)rbrFrWr@r@rA _set_formbszEnvironBuilder._set_formcCs |dtS)z$A :class:`MultiDict` of form values.r)rrrvr@r@rArlszEnvironBuilder.formcCs|d|dS)Nrrrr@r@rArqscCs |dtS)zrA :class:`FileMultiDict` of uploaded files. Use :meth:`~FileMultiDict.add_file` to add new files. r)rrrvr@r@rAruszEnvironBuilder.filescCs|d|dS)Nrrrr@r@rAr|scCs|jS)zAn optional input stream. This is mutually exclusive with setting :attr:`form` and :attr:`files`, setting it will clear those. Do not provide this if the method is not ``POST`` or another method that has a body. )rrvr@r@rArszEnvironBuilder.input_streamcCs||_d|_d|_dSr_)rrrrr@r@rArscCs.|jdkr(|jdk r$t|j|jdSdS|jS)ziThe query string. If you set this to a string :attr:`args` will no longer be available. Nr3r)rrr"r3rvr@r@rArs   zEnvironBuilder.query_stringcCs||_d|_dSr_rrrr@r@rArscCs*|jdk rtd|jdkr$t|_|jS)z(The URL arguments as :class:`MultiDict`.Nza query string is defined)rrrrrvr@r@rArs   zEnvironBuilder.argscCsd|_||_dSr_rrr@r@rArscCs|jdddS)z4The server name (read-only, use :attr:`host` to set):r r)rrrvr@r@rA server_nameszEnvironBuilder.server_namecCsD|jdd}t|dkr2|dr2t|dS|jdkr@dSdS)z?The server port as integer (read-only, use :attr:`host` to set)rr httpsiP)rrr7isdigitrKr)rbpiecesr@r@rA server_ports   zEnvironBuilder.server_portcCs&z |Wntk r YnXdSr_)close Exceptionrvr@r@rA__del__s zEnvironBuilder.__del__c Csh|jr dSz|j}Wntk r0d}YnX|D]&}z |Wq6tk rZYq6Xq6d|_dS)zCloses all files. If you put real :class:`file` objects into the :attr:`files` dict you can call this method to automatically close them all in one go. Nr@T)rrr[rrr)rbrfr@r@rArs  zEnvironBuilder.closecsj}j}j}j}|dk rP|}|dd|}||||}np|dkrttjj gj d\}}}|d|d}n6|dkrt jj d d }t |}t|}nt}i} jr| jttd fd d } tjj } | j| j| jtjj | | jtjjjjj|jjj j!d j"#} |dk r~|| d<| $d||dk rt|| d<| $d|t%t&} | 'D]*\}}| d|()dd*|q| +D]\}}d,|| |<qj-r| j-| S)zReturn the built environ. .. versionchanged:: 0.15 The content type and length headers are set based on input stream detection. Previously this only set the WSGI keys. Nrrrrz ; boundary=""rascii)xr4cstt|jjSr_)rr&r3)rrvr@rA _path_encodesz0EnvironBuilder.get_environ.._path_encode)rrrrZ REQUEST_URIZRAW_URIZ SERVER_NAMEZ SERVER_PORTZ HTTP_HOSTZSERVER_PROTOCOLz wsgi.versionrrrrrr CONTENT_TYPErHCONTENT_LENGTHrZHTTP_-_z, ).rrrrGrSrTrZrrrr3r"rLr7rrrrRrrrrrrrrrserver_protocol wsgi_versionrrrrrrIcopyrrrZ to_wsgi_listupperreplacererr~r)rbrrrrGZ start_posZend_posr2Z form_encodedresultrZraw_urirIZcombined_headersrVrWr[r@rvrA get_environsz             $ zEnvironBuilder.get_environ)rr4cCs|dkr|j}||S)zReturns a request with the data. If the request class is not specified :attr:`request_class` is used. :param cls: The request wrapper to use. N) request_classr)rbrr@r@rA get_request+szEnvironBuilder.get_request)rNNrNNNNFFFNNNNr.NNN)N)9rkrlrmrnrrr rr staticmethoddumpsrr8rsr__annotations__rRr:rrorrKTextIOboolrrrrqrJAnyrrc classmethodrrrpropertyrsetterrGrrrTyperrrrrrrrrrrrrrr@r@r@rArs ]   "$ d$$     Wrc@seZdZdZdS)ClientRedirectErrorzIf a redirect loop is detected when using follow_redirects=True with the :cls:`Client`, then this exception is raised. N)rkrlrmrnr@r@r@rAr7src@seZdZdZd3dejejdeedddd Zd4e e e ejej e e fejej e e e efe eje eeeje e dd ddZd5e e e eje eeeje ddddZd6deejejee efdddZd7deddddZddddejeeeejddddZejejddd d!Zejejddd"d#Zejejddd$d%Zejejddd&d'Zejejddd(d)Zejejddd*d+Zejejddd,d-Zejejddd.d/Z e d0d1d2Z!dS)8ClientadThis class allows you to send requests to a wrapped application. The use_cookies parameter indicates whether cookies should be stored and sent for subsequent requests. This is True by default, but passing False will disable this behaviour. If you want to request some subdomain of your application you may set `allow_subdomain_redirects` to `True` as if not no external redirects are allowed. .. versionchanged:: 2.0 ``response_wrapper`` is always a subclass of :class:``TestResponse``. .. versionchanged:: 0.5 Added the ``use_cookies`` parameter. NTFr+r() applicationresponse_wrapper use_cookiesallow_subdomain_redirectsr4cCsd||_|dthkrt}nt|ts2tdt|fi}ttjd||_|rTt |_ nd|_ ||_ dS)NZWrapperTestResponse TestResponse) rr(rrQrr8r9rrrx cookie_jarr)rbrrrrr@r@rArcPs   zClient.__init__rrr.) rrVrWmax_ageexpiresrdomainsecurehttponlysamesiter3r4c  Cs\|jdk stdt|||||||| | | d } t|d|d} d| fg}|j| |dS)zSets a cookie in the client's cookie jar. The server name is required and has to match the one that is also passed to the open call. Nzcookies disabled)rzhttp://)rz Set-Cookie)rAssertionErrorrcreate_environr)rbrrVrWrrrrrrrr3headerryrIr@r@rA set_cookieks   zClient.set_cookie)rrVrrrrrr4c Cs |j||dd|||||d dS)z$Deletes a cookie in the test client.r)rrrrrrrN)r )rbrrVrrrrrr@r@rA delete_cookies zClient.delete_cookier,)rybufferedr4cCsF|jdk r|j|t|j||d}|jdk rB|j||d|S)zVRuns the wrapped WSGI app with the given environment. :meta private: Nr"r)rr run_wsgi_apprr)rbryr"rr@r@rAr$s    zClient.run_wsgi_appr)responser"r4c CsHt|j\}}}}}tj|jj|d}|dddd} |jd} | dgkr`||_||_ n| } | | kr| t |  d| kr|j st dnt d |d } |j d } | dt | | kr|t |j d|_n ||_d|_ |jd kr:|jd krd |_|jdk r |jd|_d|_d|_|jdd|j||dS)zPerform a new request to the location given by the redirect response to the previous request. :meta private: )rrr r.rNz-Following subdomain redirects is not enabled.z.Following external redirects is not supported.r>34HEADrzTransfer-Encodingr#)r$locationrrrequestryrrrrr7r RuntimeErrorrr status_coderrrrGrrIropen) rbr%r"rrrrrbuilderZ to_name_partsZfrom_name_parts path_partsZ root_partsr@r@rAresolve_redirects:         zClient.resolve_redirect)as_tupler"follow_redirects)rr2r"r3rr4c Osld}|sXt|dkrX|d}t|tr0|}n(t|trJt|}nt|trX|}|dkrt||}z |}W5|X|j|j |d} |j | d|i} t } g} |r0| j dkr0|s| | | j| j f} | | krtd| j d| jd | | t| | _| | |j| |d} qt| | _| |jj|rhtjd td d |j | fS| S) aGenerate an environ dict from the given arguments, make a request to the application using it, and return the response. :param args: Passed to :class:`EnvironBuilder` to create the environ for the request. If a single arg is passed, it can be an existing :class:`EnvironBuilder` or an environ dict. :param buffered: Convert the iterator returned by the app into a list. If the iterator has a ``close()`` method, it is called automatically. :param follow_redirects: Make additional requests to follow HTTP redirects until a non-redirect status is returned. :attr:`TestResponse.history` lists the intermediate responses. .. versionchanged:: 2.0 ``as_tuple`` is deprecated and will be removed in Werkzeug 2.1. Use :attr:`TestResponse.request` and ``request.environ`` instead. .. versionchanged:: 2.0 The request input stream is closed when calling ``response.close()``. Input streams for redirects are automatically closed. .. versionchanged:: 0.5 If a dict is provided as file in the dict for the ``data`` parameter the content type has to be called ``content_type`` instead of ``mimetype``. This change was made for consistency with :class:`werkzeug.FileWrapper`. .. versionchanged:: 0.5 Added the ``follow_redirects`` parameter. Nr rr#r+>-./1r'r(zLoop detected: A z redirect to z was already made.zh'as_tuple' is deprecated and will be removed in Werkzeug 2.1. Access 'response.request.environ' instead.r stacklevel)r7rQrrrrr rr$ryrrr-Z make_sequencer*raddrhistoryrer1Z call_on_closerwarningswarnDeprecationWarning) rbr2r"r3rrr+argr/r%Z redirectsr;Znew_redirect_entryr@r@rAr.sR)               z Client.open)rkwr4cOsd|d<|j||S)z1Call :meth:`open` with ``method`` set to ``GET``.rrr.rbrr@r@r@rArdsz Client.getcOsd|d<|j||S)z2Call :meth:`open` with ``method`` set to ``POST``.POSTrrArBr@r@rApostisz Client.postcOsd|d<|j||S)z1Call :meth:`open` with ``method`` set to ``PUT``.PUTrrArBr@r@rAputnsz Client.putcOsd|d<|j||S)z4Call :meth:`open` with ``method`` set to ``DELETE``.DELETErrArBr@r@rAdeletessz Client.deletecOsd|d<|j||S)z3Call :meth:`open` with ``method`` set to ``PATCH``.PATCHrrArBr@r@rApatchxsz Client.patchcOsd|d<|j||S)z5Call :meth:`open` with ``method`` set to ``OPTIONS``.OPTIONSrrArBr@r@rAoptions}szClient.optionscOsd|d<|j||S)z2Call :meth:`open` with ``method`` set to ``HEAD``.r)rrArBr@r@rAheadsz Client.headcOsd|d<|j||S)z3Call :meth:`open` with ``method`` set to ``TRACE``.TRACErrArBr@r@rAtracesz Client.tracerucCsdt|jd|jdS)N< >)rrkrrvr@r@rA__repr__szClient.__repr__)NTF) rNNrNFFNr.)rNFFN)F)F)"rkrlrmrnr8rsrr rcrRrorrKrfloatr r!rqrrrJrr$r1r r.rrDrFrHrJrLrMrOrSr@r@r@rAr=s  '   @ qrr,)rrr4cOs&t||}z |WS|XdS)aCreate a new WSGI environ dict based on the values passed. The first parameter should be the path of the request which defaults to '/'. The second one can either be an absolute path (in that case the host is localhost:80) or a full path to the request with scheme, netloc port and the path to the script. This accepts the same arguments as the :class:`EnvironBuilder` constructor. .. versionchanged:: 0.5 This function is now a thin wrapper over :class:`EnvironBuilder` which was added in 0.5. The `headers`, `environ_base`, `environ_overrides` and `charset` parameters were added. N)rrr)rrr/r@r@rArs  rFr+)appryr"r4c st|}dgdfdd }|||}t|dd}t|}|rfz t|}W5|dk rb|XnH|D]}|dk rjqqjrt|}|dk r||k rt||}\}} ||t| fS)aReturn a tuple in the form (app_iter, status, headers) of the application output. This works best if you pass it an application that returns an iterator 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. If passed an invalid WSGI application the behavior of this function is undefined. Never pass non-conforming WSGI applications to this function. :param app: the application to execute. :param buffered: set to `True` to enforce buffering. :return: tuple in the form ``(app_iter, status, headers)`` Ncs0|r"z|d|dW5d}X||fjS)Nr r)with_tracebackre)statusrIexc_infobufferr%r@rAstart_responses z$run_wsgi_app..start_responser)N) r rrNiterrrerr)r) rUryr"r[Zapp_rvZ close_funcZapp_iteritemrWrIr@rYrAr$s,        r$c s|eZdZUdZeed<ejded<deje e e eejdej ddfdd Z ejd d d Zeej d ddZZS)ra:class:`~werkzeug.wrappers.Response` subclass that provides extra information about requests made with the test :class:`Client`. Test client requests will always return an instance of this class. If a custom response class is passed to the client, it is subclassed along with this to support test information. If the test request included large files, or if the application is serving a file, call :meth:`close` to close any open files and prevent Python showing a ``ResourceWarning``. r+)r.r;r@N)r%rWrIr+r;rr4c s0tj|||f|||_||_|||f|_dSr_)superrcr+r; _compat_tuple)rbr%rWrIr+r;r __class__r@rArcs zTestResponse.__init__rucCstjdtddt|jS)NzThe test client no longer returns a tuple, it returns a 'TestResponse'. Tuple unpacking is deprecated and will be removed in Werkzeug 2.1. Access the attributes 'data', 'status', and 'headers' instead.rr8)r<r=r>r\r_rvr@r@rA__iter__s  zTestResponse.__iter__)r]r4cCstjdtdd|j|S)NzThe test client no longer returns a tuple, it returns a 'TestResponse'. Item indexing is deprecated and will be removed in Werkzeug 2.1. Access the attributes 'data', 'status', and 'headers' instead.rr8)r<r=r>r_)rbr]r@r@rA __getitem__!s  zTestResponse.__getitem__)r@)rkrlrmrnr rr8rqrrrJrRrr rcIteratorrbrKrc __classcell__r@r@r`rArs    r)Tr-Nr.)Nr.)F)[rOrtypingr8r< collectionsrrrhttp.cookiejarrior itertoolsrrtempfiler r urllib.requestr r _internalr rrrZdatastructuresrrrrrrrrrrrZsansio.multipartrrrrrr urlsr!r"r#r$r%r&utilsr'Zwrappers.requestZwrappers.responser(Zwsgir)r* TYPE_CHECKINGZ_typeshed.wsgir+r,rrRr r rKrsrqr:rZrJr\r]rtrxrdrMTypeVarrrrrrrrrr$rr@r@r@rAs                                            Y  .KU H