
    wdf'                         d Z ddlZddlmZ ddlZddlmZ ddlmZ ddl	m
Z
 ddlmZ dd	lmZ dd
lmZ  G d dej        j                  Zd Z G d de          Z G d de          ZdS )z
    flask.testing
    ~~~~~~~~~~~~~

    Implements test support helpers.  This module is lazily imported
    and usually not used in production environments.

    :copyright: 2010 Pallets
    :license: BSD-3-Clause
    N)contextmanager)	CliRunner)Client)	url_parse   )_request_ctx_stack)
ScriptInfo)dumpsc                   2     e Zd ZdZ	 	 	 	 d fd	Zd Z xZS )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`.
    /Nc                 T   |s|s|r!|d ut          |p|          k    s
J d            ||j                            d          pd}|j        d         }	|rd                    ||          }||j        d         }t	          |          }
d                    |
j        p||
j        p||	                    d          	          }|
j        }|
j	        r+t          |
j	        t                    rd
nd}|||
j	        z   z  }|| _         t          t          |           j        ||g|R i | d S )Nz8Cannot pass "subdomain" or "url_scheme" with "base_url".SERVER_NAME	localhostAPPLICATION_ROOTz{0}.{1}PREFERRED_URL_SCHEMEz{scheme}://{netloc}/{path}r   )schemenetlocpath   ??)boolconfiggetformatr   r   r   lstripr   query
isinstancebytesappsuperr   __init__)selfr    r   base_url	subdomain
url_schemeargskwargs	http_hostapp_rooturlsep	__class__s               R/var/www/book.euthymeo.com/html/venv/lib/python3.11/site-packages/flask/testing.pyr"   zEnvironBuilder.__init__/   s~     	F	 	FZ 	FD #
 
=
 =
 =
 F	=
 =
 =
 
}55DIz"45H C%,,Y	BB	! Z(>?
D//C3::z/Zz.Y__S)) ;  H
 8Dy ((E::Cddci',nd##,T8MdMMMfMMMMM    c                 R    |                     d| j                   t          |fi |S )zSerialize ``obj`` to a JSON-formatted string.

        The serialization will be configured according to the config associated
        with this EnvironBuilder's ``app``.
        r    )
setdefaultr    
json_dumps)r#   objr(   s      r.   r2   zEnvironBuilder.json_dumpsX   s2     	%***#(((((r/   )r   NNN)__name__
__module____qualname____doc__r"   r2   __classcell__r-   s   @r.   r   r      sk         0 'N 'N 'N 'N 'N 'NR) ) ) ) ) ) )r/   r   c                  \    t          j        t          d                     t          | i |S )zCreate a :class:`flask.testing.EnvironBuilder`.

    .. deprecated: 1.1
        Will be removed in 2.0. Construct
        ``flask.testing.EnvironBuilder`` directly instead.
    z"make_test_environ_builder()" is deprecated and will be removed in 2.0. Construct "flask.testing.EnvironBuilder" directly instead.)warningswarnDeprecationWarningr   )r'   r(   s     r.   make_test_environ_builderr>   b   s?     M!	
 	
   4*6***r/   c                   N     e Zd ZdZdZ fdZed             Zd Zd Z	d Z
 xZS )FlaskClientaD  Works like a regular Werkzeug test client but has some knowledge about
    how Flask works to defer the cleanup of the request context stack to the
    end of a ``with`` body when used in a ``with`` statement.  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 :ref:`testing` chapter.
    Fc                 v     t          t          |           j        |i | ddt          j        z   d| _        d S )Nz	127.0.0.1z	werkzeug/)REMOTE_ADDRHTTP_USER_AGENT)r!   r@   r"   werkzeug__version__environ_base)r#   r'   r(   r-   s      r.   r"   zFlaskClient.__init__   sH    )k4  )4:6:::&*X-AA
 
r/   c              /      K   | j         t          d          | j        }|                    di           }| j                             |           t
          j        } |j        |i |5 }|j        }|	                    ||j
                  }|t          d          t          j        |           	 |V  t          j                     n# t          j                     w xY w|                                }	|                    |          s|                    |||	           |	                    |j
        j                  }
| j                             |j
        j        |
           ddd           dS # 1 swxY w Y   dS )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:Session transactions only make sense with cookies enabled.environ_overridesz?Session backend did not open a session. Check the configuration)
cookie_jarRuntimeErrorapplicationr1   inject_wsgir   toptest_request_contextsession_interfaceopen_sessionrequestpushpopresponse_classis_null_sessionsave_sessionget_wsgi_headersenvironextract_wsgi)r#   r'   r(   r    rH   outer_reqctxcrO   sessrespheaderss              r.   session_transactionzFlaskClient.session_transaction   s     $ ?"L   "--.A2FF##$5666)-%S%t6v66 	E! # 5$11#qyAAD|"U   #L111)


"&(((("&((((%%''D$44T:: @!..sD$???++AI,=>>GO(():GDDD3	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	Es,   )AE32C
6E3
CBE33E7:E7c                    |                     dd          }|                     dd          }|                     dd          }|st          |          dk    rt          |d         t          j        j        t          f          r| j                                        }t          |d         t          j        j                  r.|	                    |d         
                                           n|	                    |d                    | j        |d<   n| j        |                    di           d<   |                    d	| j                   t          | j        g|R i |}	 |
                                }|                                 n# |                                 w xY wt          j        | ||||
          S )Nas_tupleFbufferedfollow_redirectsr   r   zflask._preserve_contextrH   rF   )ra   rb   rc   )rS   lenr   rD   testr   dictrF   copyupdateget_environpreserve_contextr1   rK   closer   open)r#   r'   r(   ra   rb   rc   rX   builders           r.   rl   zFlaskClient.open   s   ::j%00::j%00!::&8%@@ 	 D		Q47X]%A4$HII  ',,..G$q'8=#?@@ (tAw22445555tAw'''151FG-.. % 1266) nd.?@@@$T%5GGGGGGG !--//{-
 
 
 	
s   %F F$c                 @    | j         rt          d          d| _         | S )NzCannot nest client invocationsT)rj   rJ   r#   s    r.   	__enter__zFlaskClient.__enter__   s*      	A?@@@ $r/   c                 l    d| _         	 t          j        }||j        r|                                 nd S -)NF)rj   r   rM   	preservedrS   )r#   exc_type	exc_valuetbrM   s        r.   __exit__zFlaskClient.__exit__   s;     %	$(C3=					r/   )r4   r5   r6   r7   rj   r"   r   r_   rl   rp   rv   r8   r9   s   @r.   r@   r@   s   s          
 
 
 
 
 2E 2E ^2Eh$
 $
 $
L        r/   r@   c                   .     e Zd ZdZ fdZd fd	Z xZS )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`.
    c                 V    || _          t          t          |           j        di | d S )N )r    r!   rx   r"   )r#   r    r(   r-   s      r.   r"   zFlaskCliRunner.__init__  s3    ,nd##,66v66666r/   Nc                      | j         j        }d|vrt           fd          |d<    t          t                     j        ||fi |S )ac  Invokes 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.
        Nr3   c                       j         S )N)r    ro   s   r.   <lambda>z'FlaskCliRunner.invoke.<locals>.<lambda>  s	    $( r/   )
create_app)r    clir	   r!   rx   invoke)r#   r   r'   r(   r-   s   `   r.   r   zFlaskCliRunner.invoke  sd     ;(,C&2B2B2B2BCCCF5M1u^T**1#tFFvFFFr/   )NN)r4   r5   r6   r7   r"   r   r8   r9   s   @r.   rx   rx      sj         
7 7 7 7 7G G G G G G G G G Gr/   rx   )r7   r;   
contextlibr   werkzeug.testrD   click.testingr   r   werkzeug.urlsr    r   r   r	   jsonr
   r2   re   r   r>   r@   rx   rz   r/   r.   <module>r      s\  	 	  % % % % % %     # # # # # #             # # # # # #                   % % % % % %F) F) F) F) F)X]1 F) F) F)R+ + +"F F F F F& F F FRG G G G GY G G G G Gr/   