1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
U
ß=®d(&ã@sêddlmZddlZddlmZddlmZddlmZddlm    Z    ddl
m Z ddl Z ddlmZdd    l mZdd
lmZd d lmZd d lmZejr²ddl mZd dlmZGdd„de jjƒZGdd„deƒZGdd„deƒZdS)é)Ú annotationsN)Úcontextmanager)Ú    ExitStack)Úcopy)Ú TracebackType)Úurlsplit)Ú    CliRunner)ÚClient)ÚRequesté)Ú
ScriptInfo)Ú SessionMixin)Ú TestResponse)ÚFlaskc
sHeZdZdZdddddddddd    œ‡fd
d „ Zdddd œd d„Z‡ZS)ÚEnvironBuildera½An :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`.
    ú/NrÚstrz
str | Noneút.AnyÚNone)ÚappÚpathÚbase_urlÚ    subdomainÚ
url_schemeÚargsÚkwargsÚreturnc sê|s |s |r(|dk    t|p|ƒks(tdƒ‚|dkrÊ|j d¡p>d}|jd}    |r\|›d|›}|dkrn|jd}t|ƒ}
|
jp~|›d|
jpŠ|›d|     d¡›}|
j}|
j    rÊt
|
j    t ƒr¸d    nd
} || |
j    7}||_ t ƒj||f|ž|ŽdS) Nz8Cannot pass "subdomain" or "url_scheme" with "base_url".Z SERVER_NAMEÚ    localhostZAPPLICATION_ROOTÚ.ZPREFERRED_URL_SCHEMEz://ró?ú?)ÚboolÚAssertionErrorÚconfigÚgetrÚschemeÚnetlocÚlstriprÚqueryÚ
isinstanceÚbytesrÚsuperÚ__init__) ÚselfrrrrrrrZ    http_hostZapp_rootÚurlÚsep©Ú    __class__©úDd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\flask/testing.pyr,.s0
ÿþü
 
$ÿzEnvironBuilder.__init__)ÚobjrrcKs|jjj|f|ŽS)z³Serialize ``obj`` to a JSON-formatted string.
 
        The serialization will be configured according to the config associated
        with this EnvironBuilder's ``app``.
        )rÚjsonÚdumps)r-r4rr2r2r3Ú
json_dumpsVszEnvironBuilder.json_dumps)rNNN)Ú__name__Ú
__module__Ú __qualname__Ú__doc__r,r7Ú __classcell__r2r2r0r3rsú"(rcsžeZdZUdZded<ddddœ‡fdd„ Zeddd    dœd
d „ƒZd d „Zdd„Z    dddœddddddœ‡fdd„Z
ddœdd„Z dddddœdd„Z ‡Z 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Ú applicationrr)rrrcs:tƒj||Žd|_g|_tƒ|_ddtj›dœ|_dS)NFz    127.0.0.1z    werkzeug/)Z REMOTE_ADDRZHTTP_USER_AGENT)    r+r,Úpreserve_contextÚ _new_contextsrÚ_context_stackÚwerkzeugÚ __version__Ú environ_base)r-rrr0r2r3r,os
þzFlaskClient.__init__z%t.Generator[SessionMixin, None, None]c    osÌ|jdkrtdƒ‚|j}|j||Ž}| |jj¡||j ||j¡}W5QRX|dkrbt    dƒ‚|V| 
¡}|j  |¡r€dS||j  |||¡W5QRX|  |jj d¡d|jj|j d¡¡dS)a’When 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Ú    TypeErrorr>Ztest_request_contextZ_add_cookies_to_wsgiÚrequestÚenvironZsession_interfaceZ open_sessionÚ RuntimeErrorÚresponse_classZis_null_sessionZ save_sessionZ_update_cookies_from_responseÚhostÚ    partitionrÚheadersÚgetlist)r-rrrÚctxÚsessÚrespr2r2r3Úsession_transactionys,
ÿ  
ýzFlaskClient.session_transactioncCs |j|–}|jr|jj|d<|S)Nzwerkzeug.debug.preserve_context)rDr?r@Úappend)r-ÚotherÚoutr2r2r3Ú _copy_environ«s
 zFlaskClient._copy_environcCsD| | di¡¡|d<t|jf|ž|Ž}z | ¡W¢S| ¡XdS)NrD)rWr$rr>ÚcloseÚ get_request)r-rrÚbuilderr2r2r3Ú_request_from_builder_args³s
 z&FlaskClient._request_from_builder_argsF©ÚbufferedÚfollow_redirectsr!r)rr]r^rrc    sö|r¢t|dtjjttfƒr¢t|dtjjƒrVt|dƒ}| |jpFi¡|_|     ¡}q®t|dtƒr†tj
|d|j | i¡d     ¡}q®t|dƒ}| |j ¡|_ n |  ||¡}|j ¡tƒj|||d}|j j|_|jrò|j ¡}|j |¡qÔ|S)Nr)rrDr\)r)rBÚtestrÚdictÚ BaseRequestrrWrDrYZ from_environr>rIr[rArXr+Úopenr5Z json_moduler@ÚpopÚ enter_context)    r-r]r^rrrZrHÚresponseÚcmr0r2r3rb¼s8 ÿ 
ÿ   
ý
 
zFlaskClient.open)rcCs|jrtdƒ‚d|_|S)NzCannot nest client invocationsT)r?rJ©r-r2r2r3Ú    __enter__észFlaskClient.__enter__z type | NonezBaseException | NonezTracebackType | None)Úexc_typeÚ    exc_valueÚtbrcCsd|_|j ¡dS)NF)r?rArX)r-rirjrkr2r2r3Ú__exit__ïszFlaskClient.__exit__)r8r9r:r;Ú__annotations__r,rrSrWr[rbrhrlr<r2r2r0r3r=_s
 
1 ü-r=csDeZdZdZddddœ‡fdd„ Zd ddddd    œ‡fd
d „ Z‡ZS) ÚFlaskCliRunnerz®A :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`.
    rrr)rrrc s||_tƒjf|ŽdS©N)rr+r,)r-rrr0r2r3r,ÿszFlaskCliRunner.__init__N)Úclirrrc s@|dkrˆjj}d|kr.t‡fdd„d|d<tƒj||f|ŽS)acInvokes a CLI command in an isolated environment. See
        :meth:`CliRunner.invoke <click.testing.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.
        Nr4csˆjSro)rr2rgr2r3Ú<lambda>óz'FlaskCliRunner.invoke.<locals>.<lambda>)Z
create_app)rrpr r+Úinvoke)r-rprrr0rgr3rss
zFlaskCliRunner.invoke)NN)r8r9r:r;r,rsr<r2r2r0r3rnùs
ÿrn) Ú
__future__rÚtypingÚtÚ
contextlibrrrÚtypesrÚ urllib.parserZ werkzeug.testrBZ click.testingrr    Zwerkzeug.wrappersr
rarpr Úsessionsr Ú TYPE_CHECKINGrrrr_rr=rnr2r2r2r3Ú<module>s&             G