
    2Bf)(                     2   d dl Zd dlmZ d dlm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 d	dlmZ d	dlmZ ej4                  rd	dlmZ d	dlmZ  G d dej>                  j@                        Z  G d de      Z! G d de
      Z"y)    N)contextmanager)copy)TracebackType)	CliRunner)Client)	url_parse)Request   )_request_ctx_stack)
ScriptInfo)dumps)SessionMixin)Flask)Responsec                        e Zd ZdZ	 	 	 	 ddddedej                  e   dej                  e   dej                  e   d	ej                  d
ej                  ddf fdZdej                  d
ej                  def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`.
    Nappr   pathbase_url	subdomain
url_schemeargskwargsreturnc                 "   |s|s|r|d ut        |xs |      k7  sJ d       ||j                  j                  d      xs d}|j                  d   }	|r| d| }||j                  d   }t        |      }
|
j                  xs | d|
j
                  xs | d|	j                  d       }|
j                  }|
j                  r0t        |
j                  t              rd	nd
}|||
j                  z   z  }|| _        t        | 4  ||g|i | y )Nz8Cannot pass "subdomain" or "url_scheme" with "base_url".SERVER_NAME	localhostAPPLICATION_ROOT.PREFERRED_URL_SCHEMEz:///   ??)boolconfiggetr   schemenetloclstripr   query
isinstancebytesr   super__init__)selfr   r   r   r   r   r   r   	http_hostapp_rooturlsep	__class__s               M/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/flask/testing.pyr.   zEnvironBuilder.__init__,   s1    	ZD #
=
 	F F		F 
 

}5DIzz"45H(k9+6	! ZZ(>?
D/C::+,C

0Gi/HHOOC()+  88Dyy(E:dcii'x9$9&9    objc                 R    |j                  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/   r7   r   s      r5   r:   zEnvironBuilder.json_dumpsT   s(     	%*#(((r6   )r!   NNN)__name__
__module____qualname____doc__strtOptionalAnyr.   r:   __classcell__r4   s   @r5   r   r      s    0 $(%)&*&:&: &: **S/	&:
 ::c?&: JJsO&: uu&: %%&: 
&:P)aee )quu ) )r6   r   c                   D    e Zd ZU dZded<   dZdej                  dej                  ddf fd	Ze	dej                  dej                  dej                  eddf   fd
       Zdddddej                  dedededej                  ddf fdZddZdedededdfdZ xZS )FlaskClientaE  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 :doc:`/testing` chapter.
    r   applicationFr   r   r   Nc                 Z    t        |   |i | ddt        j                   d| _        y )Nz	127.0.0.1z	werkzeug/)REMOTE_ADDRHTTP_USER_AGENT)r-   r.   werkzeug__version__environ_base)r/   r   r   r4   s      r5   r.   zFlaskClient.__init__p   s3    $)&)&!*8+?+?*@A
r6   c              /   $  K   | j                   t        d      | j                  }|j                  di       }| j                   j	                  |       t
        j                  } |j                  |i |5 }|j                  }|j                  ||j                        }|t        d      t        j                  |       	 | t        j                          |j                         }	|j                  |      s|j                  |||	       |	j!                  |j                  j"                        }
| j                   j%                  |j                  j"                  |
       ddd       y# t        j                          w xY w# 1 sw Y   yxY ww)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RuntimeErrorrG   r9   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   rO   outer_reqctxcrU   sessrespheaderss              r5   session_transactionzFlaskClient.session_transactionw   si    ( ??"L  "--.A2F##$56)--%S%%t6v6 	E! # 5 5$11#qyyAD|"U  ##L1)
"&&(%%'D$44T:!..sD$?++AII,=,=>GOO(():):GD3	E 	E& #&&('	E 	Es8   A3F5AFE+BF"	F+FFF	Fas_tuplebufferedfollow_redirectsrg   rh   ri   r   c                    d } fd}|st        |      dk(  r|d   }t        |t        j                  j                        r7t        |      }	 ||	j                  xs i       |	_        |	j                         }nyt        |t              r7t        j                  | j                   |i             j                         }n2t        |t              r"t        |      } ||j                        |_        |U ||j                  di             |d<   t	         j                  g|i |}		 |	j                         }|	j                          t        
 A  ||||      S # |	j                          w xY w)Nc                 @    i j                   | dj                  iS )Nzflask._preserve_context)rM   preserve_context)otherr/   s    r5   copy_environz&FlaskClient.open.<locals>.copy_environ   s5    ## *4+@+@ r6   r
   r   )r   rM   rM   rf   )lenr+   rK   testr   r   rM   get_requestdictfrom_environrG   BaseRequestr^   r&   closer-   open)r/   rg   rh   ri   r   r   rW   rn   argbuilderr4   s   `         r5   rv   zFlaskClient.open   sN    	 #d)q.q'C#x}};;<s)'3G4H4H4NB'O$!--/C&(55T--L<L 6 +-  C-s)".w"??%1&**^R2P%QF>"$T%5%5GGGG !--/w|-	  
 	
 s   *E E/c                 B    | j                   rt        d      d| _         | S )NzCannot nest client invocationsT)rl   rQ   r/   s    r5   	__enter__zFlaskClient.__enter__   s$      ?@@ $r6   exc_type	exc_valuetbc                 t    d| _         	 t        j                  }||j                  r|j	                          ny 1)NF)rl   r   rS   	preservedrY   )r/   r|   r}   r~   rS   s        r5   __exit__zFlaskClient.__exit__   s8     !& $((C3==	 r6   )r   rF   )r;   r<   r=   r>   __annotations__rl   r@   rB   r.   r   	Generatorr   re   r$   rv   r{   typeBaseExceptionr   r   rC   rD   s   @r5   rF   rF   ^   s     
aee 
quu 
 
 4EUU4E&'ee4E	
\4-	.4E 4Er !&/
uu/
 /
 	/

 /
 %%/
 
/
b)6<I	r6   rF   c            	            e Zd ZdZdddej
                  ddf fdZ	 ddej
                  d	ej
                  dej
                  dej
                  f 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`.
    r   r   r   r   Nc                 2    || _         t        |   di | y )N )r   r-   r.   )r/   r   r   r4   s      r5   r.   zFlaskCliRunner.__init__   s    "6"r6   clir   c                      | j                   j                  }d|vrt         fd      |d<   t           ||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.
        r7   c                       j                   S )N)r   rz   s   r5   <lambda>z'FlaskCliRunner.invoke.<locals>.<lambda>  s    $(( r6   )
create_app)r   r   r   r-   invoke)r/   r   r   r   r4   s   `   r5   r   zFlaskCliRunner.invoke  sD    " ;((,,C&2BCF5Mw~c42622r6   )NN)	r;   r<   r=   r>   r@   rB   r.   r   rC   rD   s   @r5   r   r      se    
#G #quu # #
 043553'(uu3?@uu3	
3 3r6   r   )#typingr@   
contextlibr   r   typesr   werkzeug.testrK   click.testingr   r   werkzeug.urlsr   werkzeug.wrappersr	   rt    r   r   r   jsonr   r:   sessionsr   TYPE_CHECKINGr   r   wrappersr   rp   r   rF   r   r   r6   r5   <module>r      sm     %    #   # 4    % "??"E)X]]11 E)PV& Vr!3Y !3r6   