
    H[gt'                    R   d dl mZ d dl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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 ddlmZ  G d dej@                  jB                        Z!da"ddZ# G d de      Z$ G d de      Z%y)    )annotationsN)contextmanager)	ExitStack)copy)TracebackType)urlsplit)	CliRunner)Client)Request   )
ScriptInfo)SessionMixin)WSGIEnvironment)TestResponse)Flaskc                  T     e Zd ZdZ	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZd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`.
    c                   |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                  r| d	|
j                   }|| _	        t        | ,  ||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lstrippathqueryappsuper__init__)selfr$   r"   base_url	subdomain
url_schemeargskwargs	http_hostapp_rooturl	__class__s              H/var/www/html/bid-api/venv/lib/python3.12/site-packages/flask/testing.pyr&   zEnvironBuilder.__init__0   s    	ZD #
=
 	F F		F 
 

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

0Gi/HHOOC()+  88Dyyq,x9$9&9    c                P     | j                   j                  j                  |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$   jsondumps)r'   objr,   s      r1   
json_dumpszEnvironBuilder.json_dumpsW   s$     #txx}}""31&11r2   )r   NNN)r$   r   r"   strr(   
str | Noner)   r9   r*   r9   r+   t.Anyr,   r:   returnNone)r6   r:   r,   r:   r;   r8   )__name__
__module____qualname____doc__r&   r7   __classcell__r0   s   @r1   r   r      so    0 # $!%%:%: %: 	%:
 %: %: %: %: 
%:N2r2   r    c                 X    t         st        j                  j                  d      a t         S )Nwerkzeug)_werkzeug_version	importlibmetadataversion r2   r1   _get_werkzeug_versionrK   c   s$     %..66zBr2   c                       e Zd ZU dZded<   d fdZe	 	 	 	 	 	 dd       ZddZ	 	 	 	 	 	 ddZ	ddd		 	 	 	 	 	 	 	 	 d fd
Z
ddZ	 	 	 	 	 	 	 	 ddZ xZS )FlaskClienta  Works 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   applicationc                    t        |   |i | d| _        g | _        t	               | _        ddt                d| _        y )NFz	127.0.0.1z	Werkzeug/)REMOTE_ADDRHTTP_USER_AGENT)r%   r&   preserve_context_new_contextsr   _context_stackrK   environ_base)r'   r+   r,   r0   s      r1   r&   zFlaskClient.__init__|   sK    $)&) %<>'k&!*+@+B*CD
r2   c              /    K   | j                   t        d      | j                  } |j                  |i |}| j	                  |j
                  j                         |5  |j                  j                  ||j
                        }ddd       t        d      | |j                         }|j                  j                  |      ry|5  |j                  j                  |||       ddd       | j                  |j
                  j                  j                  d      d   |j
                  j                   |j"                  j%                  d             y# 1 sw Y   xY w# 1 sw 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>Cookies are disabled. Create a client with 'use_cookies=True'.z'Session backend did not open a session.:r   z
Set-Cookie)_cookies	TypeErrorrN   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)r'   r+   r,   r$   ctxsessresps          r1   session_transactionzFlaskClient.session_transaction   s:    ( == P  &c&&77!!#++"5"56((55c3;;GD  <HII
!!#  006!!..sD$?  	**KK&&s+A.KKLL  .	
 S Ss8   AE2'EAE2E&+A/E2E#E2&E/+E2c                p    i | j                   |}| j                  r| j                  j                  |d<   |S )Nzwerkzeug.debug.preserve_context)rU   rR   rS   append)r'   otherouts      r1   _copy_environzFlaskClient._copy_environ   s<    ,"",e,  595G5G5N5NC12
r2   c                    | j                  |j                  di             |d<   t        | j                  g|i |}	 |j	                         |j                          S # |j                          w xY w)NrU   )rq   r   r   rN   get_requestclose)r'   r+   r,   builders       r1   _request_from_builder_argsz&FlaskClient._request_from_builder_args   sb     "&!3!3FJJ~r4R!S~ !1!1CDCFC	&&(MMOGMMOs   A A1Fbufferedfollow_redirectsc                  |r!t        |d   t        j                  j                  t        t
        f      rt        |d   t        j                  j                        rCt        |d         }| j                  |j                  xs i       |_        |j                         }nt        |d   t              rCt        j                  |d   | j                  | j                  i             j                         }nAt        |d         }| j                  |j                        |_        n| j                  ||      }| j                  j                          t         	| E  |||      }| j                  j$                  |_        | j(                  rB| j(                  j+                         }| j                  j-                  |       | j(                  rB|S )Nr   )r$   rU   rw   )
isinstancerE   testr   dictBaseRequestr   rq   rU   rs   from_environrN   r]   rv   rT   rt   r%   openr4   json_modulerS   popenter_context)
r'   rx   ry   r+   r,   ru   r\   responsecmr0   s
            r1   r   zFlaskClient.open   s    JGhmm22D+F
 $q'8==#?#?@tAw-'+'9'9':N:N:TRT'U$!--/DGT*(55G!1!1@R@RSU@V 6 +- 
 tAw-"&"4"4W__"E 55dFCG
 	!!#7<-   

  $//44   ##'')B--b1    r2   c                B    | j                   rt        d      d| _         | S )NzCannot nest client invocationsT)rR   r`   r'   s    r1   	__enter__zFlaskClient.__enter__   s$      ?@@ $r2   c                F    d| _         | j                  j                          y )NF)rR   rT   rt   )r'   exc_type	exc_valuetbs       r1   __exit__zFlaskClient.__exit__   s     !&!!#r2   )r+   r:   r,   r:   r;   r<   )r+   r:   r,   r:   r;   zt.Iterator[SessionMixin])ro   r   r;   r   )r+   ztuple[t.Any, ...]r,   zdict[str, t.Any]r;   r~   )
r+   r:   rx   r   ry   r   r,   r:   r;   r   )r;   rM   )r   ztype | Noner   zBaseException | Noner   zTracebackType | Noner;   r<   )r=   r>   r?   r@   __annotations__r&   r   rl   rq   rv   r   r   r   rA   rB   s   @r1   rM   rM   l   s     
 /
/
&+/
	!/
 /
b	%	/?			 !&	++ + 	+
 + 
+Z$$ ($ !	$
 
$r2   rM   c                  B     e Zd ZdZd fdZ	 d	 	 	 	 	 	 	 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                2    || _         t        |   di | y )NrJ   )r$   r%   r&   )r'   r$   r,   r0   s      r1   r&   zFlaskCliRunner.__init__  s    "6"r2   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.
        r6   c                      j                   S )N)r$   r   s   r1   <lambda>z'FlaskCliRunner.invoke.<locals>.<lambda>'  s	    $((r2   )
create_app)r$   clir   r%   invoke)r'   r   r+   r,   r0   s   `   r1   r   zFlaskCliRunner.invoke  sD    " ;((,,C&2BCF5Mw~c42622r2   )r$   r   r,   r:   r;   r<   )NN)r   r:   r+   r:   r,   r:   r;   r:   )r=   r>   r?   r@   r&   r   rA   rB   s   @r1   r   r     s<    
#
 0433',3?D3	3 3r2   r   )r;   r8   )&
__future__r   importlib.metadatarG   typingt
contextlibr   r   r   typesr   urllib.parser   werkzeug.testrE   click.testingr	   r
   werkzeug.wrappersr   r~   r   r   sessionsr   TYPE_CHECKING_typeshed.wsgir   r   r$   r   r|   r   rF   rK   rM   r   rJ   r2   r1   <module>r      s    "   %     !  #   4  "??.*C2X]]11 C2L  Y$& Y$x!3Y !3r2   