HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/flask/__pycache__/testing.cpython-310.pyc
o

'we!'�@sddlmZddlZddlZddlmZddlmZddl	m	Z	ddl
mZddlm
Z
ddlZddlmZdd	lmZdd
lmZddlmZdd
lmZejr]ddlmZddlmZGdd�dejj�Zda ddd�Z!Gdd�de�Z"Gdd�de�Z#dS)�)�annotationsN)�contextmanager)�	ExitStack)�copy)�
TracebackType)�urlsplit)�	CliRunner)�Client)�Request�)�
ScriptInfo)�SessionMixin)�TestResponse)�Flaskcs6eZdZdZ				dd�fdd�
Zddd�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`.
    �/N�appr�path�str�base_url�
str | None�	subdomain�
url_scheme�args�t.Any�kwargs�return�Nonecs�|s|s|r|dut|p
|�ksJd��|dure|j�d�pd}|jd}	|r.|�d|��}|dur7|jd}t|�}
|
jp?|�d|
jpE|�d|	�d���}|
j}|
jret	|
jt
�r\d	nd
}|||
j7}||_t�j
||g|�Ri|��dS)Nz8Cannot pass "subdomain" or "url_scheme" with "base_url".�SERVER_NAME�	localhost�APPLICATION_ROOT�.�PREFERRED_URL_SCHEMEz://r�?�?)�bool�config�getr�scheme�netloc�lstripr�query�
isinstance�bytesr�super�__init__)�selfrrrrrrr�	http_host�app_root�url�sep��	__class__��F/home/arjun/projects/env/lib/python3.10/site-packages/flask/testing.pyr//s4
���

�� zEnvironBuilder.__init__�objcKs|jjj|fi|��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)r0r9rr7r7r8�
json_dumpsWszEnvironBuilder.json_dumps)rNNN)rrrrrrrrrrrrrrrr)r9rrrrr)�__name__�
__module__�__qualname__�__doc__r/r<�
__classcell__r7r7r5r8rs�(r�rrcCststj�d�atS)N�werkzeug)�_werkzeug_version�	importlib�metadata�versionr7r7r7r8�_get_werkzeug_versioncsrHcsteZdZUdZded<d$�fd	d
�Zed%dd
��Zdd�Zdd�Z	ddd�d&�fdd�Z
d'dd�Zd(d"d#�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�applicationrrrrrcs>t�j|i|��d|_g|_t�|_ddt���d�|_dS)NFz	127.0.0.1z	Werkzeug/)�REMOTE_ADDR�HTTP_USER_AGENT)r.r/�preserve_context�
_new_contextsr�_context_stackrH�environ_base)r0rrr5r7r8r/|s
�zFlaskClient.__init__�%t.Generator[SessionMixin, None, None]cos��|jdur
td��|j}|j|i|��}|�|jj�|�|j�||j�}Wd�n1s1wY|dur>t	d��|V|�
�}|j�|�rMdS|�|j�|||�Wd�n1sbwY|�
|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�	TypeErrorrJ�test_request_context�_add_cookies_to_wsgi�request�environ�session_interface�open_session�RuntimeError�response_class�is_null_session�save_session�_update_cookies_from_response�host�	partitionr�headers�getlist)r0rrr�ctx�sess�respr7r7r8�session_transaction�s2�
���
�zFlaskClient.session_transactioncCs$i|j�|�}|jr|jj|d<|S)Nzwerkzeug.debug.preserve_context)rPrMrN�append)r0�other�outr7r7r8�
_copy_environ�szFlaskClient._copy_environcCsL|�|�di��|d<t|jg|�Ri|��}z	|��W|��S|��w)NrP)rkr'rrJ�get_request�close)r0rr�builderr7r7r8�_request_from_builder_args�s
z&FlaskClient._request_from_builder_argsF��buffered�follow_redirectsrqr%rrrc	s�|rQt|dtjjttf�rQt|dtjj�r+t|d�}|�|jp#i�|_|�	�}n,t|dt�rCtj
|d|j|�i�d��	�}nt|d�}|�|j�|_n|�
||�}|j��t�j|||d�}|jj|_|jr{|j��}|j�|�|jsm|S)Nr)rrPrp)r,rC�testr�dict�BaseRequestrrkrPrl�from_environrJrXrorOrmr.�openr:�json_modulerN�pop�
enter_context)	r0rqrrrrrnrW�response�cmr5r7r8rw�s8�
��
�

�zFlaskClient.opencCs|jrtd��d|_|S)NzCannot nest client invocationsT)rMr[�r0r7r7r8�	__enter__�szFlaskClient.__enter__�exc_type�type | None�	exc_value�BaseException | None�tb�TracebackType | NonecCsd|_|j��dS)NF)rMrOrm)r0rr�r�r7r7r8�__exit__�szFlaskClient.__exit__)rrrrrr)rrrrrrQ)
rrrqr%rrr%rrrr)rrI)rr�r�r�r�r�rr)r=r>r?r@�__annotations__r/rrgrkrorwr~r�rAr7r7r5r8rIls


1�
-rIcs4eZdZdZd�fdd	�Z	
dd�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`.
    rrrrrrcs||_t�jdi|��dS)Nr7)rr.r/)r0rrr5r7r8r/szFlaskCliRunner.__init__N�clircsD|dur�jj}d|vrt�fdd�d�|d<t�j||fi|��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.
        Nr9cs�jS)N)rr7r}r7r8�<lambda>%sz'FlaskCliRunner.invoke.<locals>.<lambda>)�
create_app)rr�rr.�invoke)r0r�rrr5r}r8r�s
zFlaskCliRunner.invoke)rrrrrr)NN)r�rrrrrrr)r=r>r?r@r/r�rAr7r7r5r8r�s
�r�)rr)$�
__future__r�importlib.metadatarE�typing�t�
contextlibrrr�typesr�urllib.parser�
werkzeug.testrC�
click.testingrr	�werkzeug.wrappersr
rur�r�sessionsr
�
TYPE_CHECKINGrrrrsrrDrHrIr�r7r7r7r8�<module>s.G