Format: application/x-python-code
⬇ Download File (21.6 KB)
   1  o
   2  
   3  D'h�[�@s�ddlmZddlZddlZddlZddlZddlmZddl	m
   4  Z
   5  ddl	mZddlZ
   6  ddlmZddlmZddlmZd	d
   7  lmZd	dlmZd	dlmZd	d
   8  lmZd	dlmZd	dlmZejrkd	dlmZdndd�Z dodpdd�Z!ej"dqdd��Z#ej"drdd��Z#dsd!d�Z#dtd%d&�Z$ddddd'�dud1d2�Z%	dvdwd9d:�Zdxd>d?�ZdydBdC�Z&dzd{dGdH�Z'	Jd|d}dOdP�Z(d~dRdS�Z)		I					dd�d`da�Z*d�dedf�Z+d�dhdi�Z,e
   9  d�dldm��Z-dS)��)�annotationsN)�datetime)�cache)�update_wrapper)�abort)�redirect)�Response�)�_cv_request)�current_app)�request)�request_ctx)�session)�message_flashed�return�boolcCs tj�d�}t|o|��dv�S)z�Get whether debug mode should be enabled for the app, indicated by the
  10      :envvar:`FLASK_DEBUG` environment variable. The default is ``False``.
  11      ZFLASK_DEBUG>�false�0�no)�os�environ�getr�lower)�val�r�CC:\Users\shubh\Videos\agent\nova\Lib\site-packages\flask/helpers.py�get_debug_flagsrT�defaultcCs tj�d�}|s
  12  |S|��dvS)z�Get whether the user has disabled loading default dotenv files by
  13      setting :envvar:`FLASK_SKIP_DOTENV`. The default is ``True``, load
  14      the files.
  15  
  16      :param default: What to return if the env var isn't set.
  17      ZFLASK_SKIP_DOTENV)rrr)rrrr)rrrrr�get_load_dotenv#sr�generator_or_function�t.Iterator[t.AnyStr]cC�dS�Nr�rrrr�stream_with_context2�r$�%t.Callable[..., t.Iterator[t.AnyStr]]�8t.Callable[[t.Iterator[t.AnyStr]], t.Iterator[t.AnyStr]]cCr!r"rr#rrrr$8r%�<t.Iterator[t.AnyStr] | t.Callable[..., t.Iterator[t.AnyStr]]�Ot.Iterator[t.AnyStr] | t.Callable[[t.Iterator[t.AnyStr]], t.Iterator[t.AnyStr]]csXzt���Wntyd�fdd�}t|��YSwd�fdd	�}|�}t|�|S)
  18  a�Request contexts disappear when the response is started on the server.
  19      This is done for efficiency reasons and to make it less likely to encounter
  20      memory leaks with badly written WSGI middlewares.  The downside is that if
  21      you are using streamed responses, the generator cannot access request bound
  22      information any more.
  23  
  24      This function however can help you keep the context around for longer::
  25  
  26          from flask import stream_with_context, request, Response
  27  
  28          @app.route('/stream')
  29          def streamed_response():
  30              @stream_with_context
  31              def generate():
  32                  yield 'Hello '
  33                  yield request.args['name']
  34                  yield '!'
  35              return Response(generate())
  36  
  37      Alternatively it can also be used around a specific generator::
  38  
  39          from flask import stream_with_context, request, Response
  40  
  41          @app.route('/stream')
  42          def streamed_response():
  43              def generate():
  44                  yield 'Hello '
  45                  yield request.args['name']
  46                  yield '!'
  47              return Response(stream_with_context(generate()))
  48  
  49      .. versionadded:: 0.9
  50      �args�t.Any�kwargsrcs�|i|��}t|�Sr")r$)r*r,�genr#rr�	decoratorfsz&stream_with_context.<locals>.decorator�t.Iterator[t.AnyStr | None]c
  51  3s��t�d�}|durtd��|�(dVz�EdHWt�d�r$���nt�d�r/���wwWd�dS1s;wYdS)Nzd'stream_with_context' can only be used when a request context is active, such as in a view function.�close)r
  52  r�RuntimeError�hasattrr0)�ctx)r-rr�	generatorls$�
  53  �
  54  �
  55  �
  56  ��"�z&stream_with_context.<locals>.generatorN)r*r+r,r+rr+)rr/)�iter�	TypeErrorr�next)rr.r4Z	wrapped_gr)r-rrr$>s$�r*r+rcGs*|st��St|�dkr|d}t�|�S)aySometimes it is necessary to set additional headers in a view.  Because
  57      views do not have to return response objects but can return a value that
  58      is converted into a response object by Flask itself, it becomes tricky to
  59      add headers to it.  This function can be called instead of using a return
  60      and you will get a response object which you can use to attach headers.
  61  
  62      If view looked like this and you want to add a new header::
  63  
  64          def index():
  65              return render_template('index.html', foo=42)
  66  
  67      You can now do something like this::
  68  
  69          def index():
  70              response = make_response(render_template('index.html', foo=42))
  71              response.headers['X-Parachutes'] = 'parachutes are cool'
  72              return response
  73  
  74      This function accepts the very same arguments you can return from a
  75      view function.  This for example creates a response with a 404 error
  76      code::
  77  
  78          response = make_response(render_template('not_found.html'), 404)
  79  
  80      The other use case of this function is to force the return value of a
  81      view function into a response which is helpful with view
  82      decorators::
  83  
  84          response = make_response(view_function())
  85          response.headers['X-Parachutes'] = 'parachutes are cool'
  86  
  87      Internally this function does the following things:
  88  
  89      -   if no arguments are passed, it creates a new response argument
  90      -   if one argument is passed, :meth:`flask.Flask.make_response`
  91          is invoked with it.
  92      -   if more than one argument is passed, the arguments are passed
  93          to the :meth:`flask.Flask.make_response` function as tuple.
  94  
  95      .. versionadded:: 0.6
  96      r	r)r�response_class�len�
  97  make_response)r*rrrr:�s
  98  *
  99  r:��_anchor�_method�_scheme�	_external�endpoint�strr<�
 100  str | Noner=r>r?�bool | None�valuescKstj|f||||d�|��S)a�Generate a URL to the given endpoint with the given values.
 101  
 102      This requires an active request or application context, and calls
 103      :meth:`current_app.url_for() <flask.Flask.url_for>`. See that method
 104      for full documentation.
 105  
 106      :param endpoint: The endpoint name associated with the URL to
 107          generate. If this starts with a ``.``, the current blueprint
 108          name (if any) will be used.
 109      :param _anchor: If given, append this as ``#anchor`` to the URL.
 110      :param _method: If given, generate the URL associated with this
 111          method for the endpoint.
 112      :param _scheme: If given, the URL will have this scheme if it is
 113          external.
 114      :param _external: If given, prefer the URL to be internal (False) or
 115          require it to be external (True). External URLs include the
 116          scheme and domain. When not in an active request, URLs are
 117          external by default.
 118      :param values: Values to use for the variable parts of the URL rule.
 119          Unknown keys are appended as query string arguments, like
 120          ``?a=b&c=d``.
 121  
 122      .. versionchanged:: 2.2
 123          Calls ``current_app.url_for``, allowing an app to override the
 124          behavior.
 125  
 126      .. versionchanged:: 0.10
 127         The ``_scheme`` parameter was added.
 128  
 129      .. versionchanged:: 0.9
 130         The ``_anchor`` and ``_method`` parameters were added.
 131  
 132      .. versionchanged:: 0.9
 133         Calls ``app.handle_url_build_error`` on build errors.
 134      r;)r�url_for)r@r<r=r>r?rDrrrrE�s,���rE�.�location�code�int�type[BaseResponse] | None�BaseResponsecCs tr	tj||d�St|||d�S)aBCreate a redirect response object.
 135  
 136      If :data:`~flask.current_app` is available, it will use its
 137      :meth:`~flask.Flask.redirect` method, otherwise it will use
 138      :func:`werkzeug.utils.redirect`.
 139  
 140      :param location: The URL to redirect to.
 141      :param code: The status code for the redirect.
 142      :param Response: The response class to use. Not used when
 143          ``current_app`` is active, which uses ``app.response_class``.
 144  
 145      .. versionadded:: 2.2
 146          Calls ``current_app.redirect`` if available instead of always
 147          using Werkzeug's default ``redirect``.
 148      )rH)rHr)rr�_wz_redirect)rGrHrrrrr�sr�int | BaseResponser,�
 149  t.NoReturncOs6trtj|g|�Ri|��t|g|�Ri|��dS)aJRaise an :exc:`~werkzeug.exceptions.HTTPException` for the given
 150      status code.
 151  
 152      If :data:`~flask.current_app` is available, it will call its
 153      :attr:`~flask.Flask.aborter` object, otherwise it will use
 154      :func:`werkzeug.exceptions.abort`.
 155  
 156      :param code: The status code for the exception, which must be
 157          registered in ``app.aborter``.
 158      :param args: Passed to the exception.
 159      :param kwargs: Passed to the exception.
 160  
 161      .. versionadded:: 2.2
 162          Calls ``current_app.aborter`` if available instead of always
 163          using Werkzeug's default ``abort``.
 164      N)rZaborter�	_wz_abort)rHr*r,rrrr
 165  sr�
 166  template_name�	attributecCsttj�|�j|�S)aXLoads a macro (or variable) a template exports.  This can be used to
 167      invoke a macro from within Python code.  If you for example have a
 168      template named :file:`_cider.html` with the following contents:
 169  
 170      .. sourcecode:: html+jinja
 171  
 172         {% macro hello(name) %}Hello {{ name }}!{% endmacro %}
 173  
 174      You can access this from Python code like this::
 175  
 176          hello = get_template_attribute('_cider.html', 'hello')
 177          return hello('World')
 178  
 179      .. versionadded:: 0.2
 180  
 181      :param template_name: the name of the template
 182      :param attribute: the name of the variable of macro to access
 183      )�getattrrZ	jinja_envZget_template�module)rPrQrrr�get_template_attribute!srT�message�category�NonecCsBt�dg�}|�||f�|td<t��}tj||j||d�dS)a�Flashes a message to the next request.  In order to remove the
 184      flashed message from the session and to display it to the user,
 185      the template has to call :func:`get_flashed_messages`.
 186  
 187      .. versionchanged:: 0.3
 188         `category` parameter added.
 189  
 190      :param message: the message to be flashed.
 191      :param category: the category for the message.  The following values
 192                       are recommended: ``'message'`` for any kind of message,
 193                       ``'error'`` for errors, ``'info'`` for information
 194                       messages and ``'warning'`` for warnings.  However any
 195                       kind of string can be used as category.
 196      �_flashes)Z_async_wrapperrUrVN)rr�appendrZ_get_current_objectr�sendZensure_sync)rUrV�flashesZapprrr�flash7s
 197  �r\Fr�with_categories�category_filter�t.Iterable[str]�!list[str] | list[tuple[str, str]]csZtj}|durdtvrt�d�ng}|t_�r"tt�fdd�|��}|s+dd�|D�S|S)a�Pulls all flashed messages from the session and returns them.
 198      Further calls in the same request to the function will return
 199      the same messages.  By default just the messages are returned,
 200      but when `with_categories` is set to ``True``, the return value will
 201      be a list of tuples in the form ``(category, message)`` instead.
 202  
 203      Filter the flashed messages to one or more categories by providing those
 204      categories in `category_filter`.  This allows rendering categories in
 205      separate html blocks.  The `with_categories` and `category_filter`
 206      arguments are distinct:
 207  
 208      * `with_categories` controls whether categories are returned with message
 209        text (``True`` gives a tuple, where ``False`` gives just the message text).
 210      * `category_filter` filters the messages down to only those matching the
 211        provided categories.
 212  
 213      See :doc:`/patterns/flashing` for examples.
 214  
 215      .. versionchanged:: 0.3
 216         `with_categories` parameter added.
 217  
 218      .. versionchanged:: 0.9
 219          `category_filter` parameter added.
 220  
 221      :param with_categories: set to ``True`` to also receive categories.
 222      :param category_filter: filter of categories to limit return values.  Only
 223                              categories in the list will be returned.
 224      NrXcs|d�vS)Nrr)�f�r^rr�<lambda>}sz&get_flashed_messages.<locals>.<lambda>cSsg|]}|d�qS)r	r)�.0�xrrr�
 225  <listcomp>sz(get_flashed_messages.<locals>.<listcomp>)r
 226  r[r�pop�list�filter)r]r^r[rrbr�get_flashed_messagesYsrj�dict[str, t.Any]cKs:|�d�durtj|d<|jtjtjdtjtjd�|S)N�max_ageZUSE_X_SENDFILE)rZuse_x_sendfiler8Z
 227  _root_path)	rrZget_send_file_max_age�updaterr�configr8�	root_path)r,rrr�_prepare_send_file_kwargs�s
 228  �rp�path_or_file�(os.PathLike[t.AnyStr] | str | t.BinaryIO�mimetype�
 229  as_attachment�
 230  download_name�conditional�etag�
 231  bool | str�
 232  last_modified�datetime | int | float | Nonerl�3None | (int | t.Callable[[str | None], int | None])cCs*tjjdit|tj|||||||d�	��S)a_Send the contents of a file to the client.
 233  
 234      The first argument can be a file path or a file-like object. Paths
 235      are preferred in most cases because Werkzeug can manage the file and
 236      get extra information from the path. Passing a file-like object
 237      requires that the file is opened in binary mode, and is mostly
 238      useful when building a file in memory with :class:`io.BytesIO`.
 239  
 240      Never pass file paths provided by a user. The path is assumed to be
 241      trusted, so a user could craft a path to access a file you didn't
 242      intend. Use :func:`send_from_directory` to safely serve
 243      user-requested paths from within a directory.
 244  
 245      If the WSGI server sets a ``file_wrapper`` in ``environ``, it is
 246      used, otherwise Werkzeug's built-in wrapper is used. Alternatively,
 247      if the HTTP server supports ``X-Sendfile``, configuring Flask with
 248      ``USE_X_SENDFILE = True`` will tell the server to send the given
 249      path, which is much more efficient than reading it in Python.
 250  
 251      :param path_or_file: The path to the file to send, relative to the
 252          current working directory if a relative path is given.
 253          Alternatively, a file-like object opened in binary mode. Make
 254          sure the file pointer is seeked to the start of the data.
 255      :param mimetype: The MIME type to send for the file. If not
 256          provided, it will try to detect it from the file name.
 257      :param as_attachment: Indicate to a browser that it should offer to
 258          save the file instead of displaying it.
 259      :param download_name: The default name browsers will use when saving
 260          the file. Defaults to the passed file name.
 261      :param conditional: Enable conditional and range responses based on
 262          request headers. Requires passing a file path and ``environ``.
 263      :param etag: Calculate an ETag for the file, which requires passing
 264          a file path. Can also be a string to use instead.
 265      :param last_modified: The last modified time to send for the file,
 266          in seconds. If not provided, it will try to detect it from the
 267          file path.
 268      :param max_age: How long the client should cache the file, in
 269          seconds. If set, ``Cache-Control`` will be ``public``, otherwise
 270          it will be ``no-cache`` to prefer conditional caching.
 271  
 272      .. versionchanged:: 2.0
 273          ``download_name`` replaces the ``attachment_filename``
 274          parameter. If ``as_attachment=False``, it is passed with
 275          ``Content-Disposition: inline`` instead.
 276  
 277      .. versionchanged:: 2.0
 278          ``max_age`` replaces the ``cache_timeout`` parameter.
 279          ``conditional`` is enabled and ``max_age`` is not set by
 280          default.
 281  
 282      .. versionchanged:: 2.0
 283          ``etag`` replaces the ``add_etags`` parameter. It can be a
 284          string to use instead of generating one.
 285  
 286      .. versionchanged:: 2.0
 287          Passing a file-like object that inherits from
 288          :class:`~io.TextIOBase` will raise a :exc:`ValueError` rather
 289          than sending an empty file.
 290  
 291      .. versionadded:: 2.0
 292          Moved the implementation to Werkzeug. This is now a wrapper to
 293          pass some Flask-specific arguments.
 294  
 295      .. versionchanged:: 1.1
 296          ``filename`` may be a :class:`~os.PathLike` object.
 297  
 298      .. versionchanged:: 1.1
 299          Passing a :class:`~io.BytesIO` object supports range requests.
 300  
 301      .. versionchanged:: 1.0.3
 302          Filenames are encoded with ASCII instead of Latin-1 for broader
 303          compatibility with WSGI servers.
 304  
 305      .. versionchanged:: 1.0
 306          UTF-8 filenames as specified in :rfc:`2231` are supported.
 307  
 308      .. versionchanged:: 0.12
 309          The filename is no longer automatically inferred from file
 310          objects. If you want to use automatic MIME and etag support,
 311          pass a filename via ``filename_or_fp`` or
 312          ``attachment_filename``.
 313  
 314      .. versionchanged:: 0.12
 315          ``attachment_filename`` is preferred over ``filename`` for MIME
 316          detection.
 317  
 318      .. versionchanged:: 0.9
 319          ``cache_timeout`` defaults to
 320          :meth:`Flask.get_send_file_max_age`.
 321  
 322      .. versionchanged:: 0.7
 323          MIME guessing and etag support for file-like objects was
 324          removed because it was unreliable. Pass a filename if you are
 325          able to, otherwise attach an etag yourself.
 326  
 327      .. versionchanged:: 0.5
 328          The ``add_etags``, ``cache_timeout`` and ``conditional``
 329          parameters were added. The default behavior is to add etags.
 330  
 331      .. versionadded:: 0.2
 332      )	rqrrsrtrurvrwryrlNr)�werkzeug�utils�	send_filerprr)rqrsrtrurvrwryrlrrrr~�s
 333  o��r~�	directory�os.PathLike[str] | str�pathcKs tjj||fitdi|����S)a
 334  Send a file from within a directory using :func:`send_file`.
 335  
 336      .. code-block:: python
 337  
 338          @app.route("/uploads/<path:name>")
 339          def download_file(name):
 340              return send_from_directory(
 341                  app.config['UPLOAD_FOLDER'], name, as_attachment=True
 342              )
 343  
 344      This is a secure way to serve files from a folder, such as static
 345      files or uploads. Uses :func:`~werkzeug.security.safe_join` to
 346      ensure the path coming from the client is not maliciously crafted to
 347      point outside the specified directory.
 348  
 349      If the final path does not point to an existing regular file,
 350      raises a 404 :exc:`~werkzeug.exceptions.NotFound` error.
 351  
 352      :param directory: The directory that ``path`` must be located under,
 353          relative to the current application's root path. This *must not*
 354          be a value provided by the client, otherwise it becomes insecure.
 355      :param path: The path to the file to send, relative to
 356          ``directory``.
 357      :param kwargs: Arguments to pass to :func:`send_file`.
 358  
 359      .. versionchanged:: 2.0
 360          ``path`` replaces the ``filename`` parameter.
 361  
 362      .. versionadded:: 2.0
 363          Moved the implementation to Werkzeug. This is now a wrapper to
 364          pass some Flask-specific arguments.
 365  
 366      .. versionadded:: 0.5
 367      Nr)r|r}�send_from_directoryrp)rr�r,rrrr�s
 368  '��r��import_namec	Cs�tj�|�}|durt|d�r|jdurtj�tj�|j��Szt	j
 369  �|�}|dur,t�Wn
 370  t
 371  tfy:d}Ynw|j}|durFt��St|d�rQ|�|�}nt|�tj|}t|dd�}|durltd|�d���tj�tj�|��S)z�Find the root path of a package, or the path that contains a
 372      module. If it cannot be found, returns the current working
 373      directory.
 374  
 375      Not to be confused with the value returned by :func:`find_package`.
 376  
 377      :meta private:
 378      N�__file__�get_filenamez2No root path can be found for the provided module z�. This can happen because the module came from an import hook that does not provide file name information or because it's a namespace package. In this case the root path needs to be explicitly provided.)�sys�modulesrr2r�rr��dirname�abspath�	importlib�util�	find_spec�
 379  ValueError�ImportError�loader�getcwdr��
 380  __import__rRr1)r��mod�specr��filepathrrr�
 381  get_root_path:s4
 382  ��
 383  
 384  ��
 385  r��name�	list[str]cCs*|g}d|vr|�t|�d�d��|S)N�.r)�extend�_split_blueprint_path�
 386  rpartition)r��outrrrr�ssr�)rr)T)rrrr)rr rr )rr&rr')rr(rr))r*r+rr)r@rAr<rBr=rBr>rBr?rCrDr+rrA)rFN)rGrArHrIrrJrrK)rHrMr*r+r,r+rrN)rPrArQrArr+)rU)rUrArVrArrW)Fr)r]rr^r_rr`)r,r+rrk)NFNTTNN)rqrrrsrBrtrrurBrvrrwrxryrzrlr{rr)rr�r�r�r,r+rr)r�rArrA)r�rArr�).�
 387  __future__r�importlib.utilr�rr��typing�tr�	functoolsrrZwerkzeug.utilsr|Zwerkzeug.exceptionsrrOrrLZwerkzeug.wrappersrrK�globalsr
 388  rrr
 389  rZsignalsr�
 390  TYPE_CHECKINGZwrappersrr�overloadr$r:rErTr\rjrpr~r�r�r�rrrr�<module>sj
 391  
 392  
 393  M4�7�
 394  
 395  #�
 396  *�
 397  ~
 398  ,9