6V=j'TddlmZddlZddlZddlmZddlmZddl m Z ddl m Z ddl m Z ddlZddlmZdd lmZdd lmZdd lmZd d lmZd dlmZejrddlmZddlmZd dlm Z Gddej!j"Z"da#ddZ$GddeZ%GddeZ&dS)) annotationsN)contextmanager) ExitStack)copy) TracebackType)urlsplit) CliRunner)Result)Client)Request) ScriptInfo) SessionMixin)WSGIEnvironment) TestResponse)Flaskc6eZdZdZ ddfd ZddZxZS)EnvironBuilderaAn :class:`~werkzeug.test.EnvironBuilder`, that takes defaults from the application. :param app: The Flask application to configure the environment from. :param path: URL path being requested. :param base_url: Base URL where the app is being served, which ``path`` is relative to. If not given, built from :data:`PREFERRED_URL_SCHEME`, ``subdomain``, :data:`SERVER_NAME`, and :data:`APPLICATION_ROOT`. :param subdomain: Subdomain name to append to :data:`SERVER_NAME`. :param url_scheme: Scheme to use instead of :data:`PREFERRED_URL_SCHEME`. :param json: If given, this is serialized as JSON and passed as ``data``. Also defaults ``content_type`` to ``application/json``. :param args: other positional arguments passed to :class:`~werkzeug.test.EnvironBuilder`. :param kwargs: other keyword arguments passed to :class:`~werkzeug.test.EnvironBuilder`. /Napprpathstrbase_url str | None subdomain url_schemeargst.AnykwargsreturnNonec|s|s|r!|dut|p|ks Jd||jdpd}|jd} |r|d|}| |jd}t|} | jp|d| jp|d| d}| j}| jr |d | j}||_ tj ||g|Ri|dS) Nz8Cannot pass "subdomain" or "url_scheme" with "base_url". SERVER_NAME localhostAPPLICATION_ROOT.PREFERRED_URL_SCHEMEz://r?) boolconfiggetrschemenetloclstriprqueryrsuper__init__) selfrrrrrrr http_hostapp_rooturl __class__s ;C:\PYTHON\_runtimes\venv\Lib\site-packages\flask/testing.pyr1zEnvironBuilder.__init__1s`  Z D ))z * *=+=+=+ G=+=++   }55DIz"45H 7(66966 ! Z(>? 4..C:+++ 0Gi++OOC((++ 8Dy -,,,,x9$999&99999objc 2|jjj|fi|S)zSerialize ``obj`` to a JSON-formatted string. The serialization will be configured according to the config associated with this EnvironBuilder's ``app``. )rjsondumps)r2r9rs r7 json_dumpszEnvironBuilder.json_dumpsXs# #tx}"311&111r8)rNNN)rrrrrrrrrrrrrrr r!)r9rrrr r)__name__ __module__ __qualname____doc__r1r= __classcell__r6s@r7rrso0# $!% %:%:%:%:%:%:%:N22222222r8rr rc\tstjdatS)Nwerkzeug)_werkzeug_version importlibmetadataversionr8r7_get_werkzeug_versionrLds* C%.66zBB r8c|eZdZUdZded<d"fd Zed#d Zd$dZd%dZ dddd&fdZ d'dZ d(d!Z xZ S)) FlaskClientaWorks like a regular Werkzeug test client but has knowledge about Flask's contexts to defer the cleanup of the request context until the end of a ``with`` block. For general information about how to use this class refer to :class:`werkzeug.test.Client`. .. versionchanged:: 0.12 `app.test_client()` includes preset default environment, which can be set after instantiation of the `app.test_client()` object in `client.environ_base`. Basic usage is outlined in the :doc:`/testing` chapter. r applicationrrrr r!ctj|i|d|_g|_t |_ddt d|_dS)NFz 127.0.0.1z Werkzeug/) REMOTE_ADDRHTTP_USER_AGENT)r0r1preserve_context _new_contextsr_context_stackrL environ_base)r2rrr6s r7r1zFlaskClient.__init__}se$)&))) %<>'kk&D+@+B+BDD  r8t.Iterator[SessionMixin]c/K|jtd|j}|j|i|}||jj|5|j||j}dddn #1swxYwY|td|V| }|j |rdS|5|j |||dddn #1swxYwY| |jjdd|jj|jddS)aWhen used in combination with a ``with`` statement this opens a session transaction. This can be used to modify the session that the test client uses. Once the ``with`` block is left the session is stored back. :: with client.session_transaction() as session: session['value'] = 42 Internally this is implemented by going through a temporary test request context and since session handling could depend on request variables this function accepts the same arguments as :meth:`~flask.Flask.test_request_context` which are directly passed through. Nz>Cookies are disabled. Create a client with 'use_cookies=True'.z'Session backend did not open a session.:rz Set-Cookie)_cookies TypeErrorrOtest_request_context_add_cookies_to_wsgirequestenvironsession_interface open_session RuntimeErrorresponse_classis_null_session save_session_update_cookies_from_responsehost partitionrheadersgetlist)r2rrrctxsessresps r7session_transactionzFlaskClient.session_transactions( = P &c&777 !!#+"5666  H H(55c3;GGD H H H H H H H H H H H H H H H <HII I !!##  0 0 6 6  F  @ @  ! . .sD$ ? ? ? @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ ** K  & &s + +A . K  L  . .     s$!A;;A?A? C66C:=C:otherrcHi|j|}|jr|jj|d<|S)Nzwerkzeug.debug.preserve_context)rVrSrTappend)r2roouts r7 _copy_environzFlaskClient._copy_environs6,",e,   O595G5NC1 2 r8tuple[t.Any, ...]dict[str, t.Any] BaseRequestc||di|d<t|jg|Ri|} ||S#|wxYw)NrV)rsr+rrO get_requestclose)r2rrbuilders r7_request_from_builder_argsz&FlaskClient._request_from_builder_argss"&!3!3FJJ~r4R4R!S!S~ !1CDCCCFCC &&(( MMOOOOGMMOOOOs A++BFbufferedfollow_redirectsr}r)r~rc|rAt|dtjjtt frt|dtjjrKt |d}||jpi|_| }nt|dtrNt |d|j |i }nKt |d}||j |_ n| ||}|jt!|||}|j j|_|jD]}|j||j|S)Nr)rrVr|) isinstancerFtestrdictrvrrsrVrx from_environrOr_r{rUryr0openr; json_modulerT enter_contextclear) r2r}r~rrrzr^responsecmr6s r7rzFlaskClient.opens  DJ Ghm2D+F   D$q'8=#?@@ FtAw--'+'9'9':N:TRT'U'U$!--//DGT** F(55G!1@R@RSU@V@V6+-- tAw--"&"4"4W_"E"E55dFCCG !!###77<< -    $/4$ 2 2B   - -b 1 1 1 1   """r8c@|jrtdd|_|S)NzCannot nest client invocationsT)rSrbr2s r7 __enter__zFlaskClient.__enter__s*   A?@@ @ $ r8exc_type type | None exc_valueBaseException | NonetbTracebackType | NonecFd|_|jdS)NF)rSrUry)r2rrrs r7__exit__zFlaskClient.__exit__s' !& !!#####r8)rrrrr r!)rrrrr rW)rorr r)rrtrrur rv) rrr}r)r~r)rrr r)r rN)rrrrrrr r!)r>r?r@rA__annotations__r1rrnrsr{rrrrBrCs@r7rNrNms        / / / ^/ b    !& ++++++++Z $$$$$$$$r8rNc4eZdZdZdfd Z ddfd ZxZS)FlaskCliRunnerzA :class:`~click.testing.CliRunner` for testing a Flask app's CLI commands. Typically created using :meth:`~flask.Flask.test_cli_runner`. See :ref:`testing-cli`. rrrrr r!c H||_tjdi|dS)NrK)rr0r1)r2rrr6s r7r1zFlaskCliRunner.__init__s-""6"""""r8Nclirr c | jj}d|vrtfd|d<tj||fi|S)acInvokes a CLI command in an isolated environment. See :meth:`CliRunner.invoke ` for full method documentation. See :ref:`testing-cli` for examples. If the ``obj`` argument is not given, passes an instance of :class:`~flask.cli.ScriptInfo` that knows how to load the Flask app being tested. :param cli: Command object to invoke. Default is the app's :attr:`~flask.app.Flask.cli` group. :param args: List of strings to invoke the command with. :return: a :class:`~click.testing.Result` object. Nr9cjS)N)rrsr7z'FlaskCliRunner.invoke..(s $(r8) create_app)rrrr0invoke)r2rrrr6s` r7rzFlaskCliRunner.invokes]" ;(,C   &2B2B2B2BCCCF5Muww~c4226222r8)rrrrr r!)NN)rrrrrrr r )r>r?r@rAr1rrBrCs@r7rr so ###### 0433333333333r8r)r r)' __future__rimportlib.metadatarHtypingt contextlibrrrtypesr urllib.parser werkzeug.testrF click.testingr r r werkzeug.wrappersr rvrrsessionsr TYPE_CHECKING_typeshed.wsgirrrrrrrGrLrNrrKr8r7rs""""""%%%%%% !!!!!!###### 444444""""""?......******C2C2C2C2C2X]1C2C2C2LY$Y$Y$Y$Y$&Y$Y$Y$x!3!3!3!3!3Y!3!3!3!3!3r8