Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
helpers.cpython-313.pyc402 linesDownload Raw Back to __pycache__
1�

2��j�[���SSKJr SSKrSSKrSSKrSSKrSSKJr SSK	J3r4 SSK	Jr SSKr
SSKJr SSKJr SSKJr S	S5KJr S	SKJr S	SKJr S	S
KJr S	SKJr S	SKJr S	SKJr \R>(aS	SK Jr S#Sjr!S$S%Sjjr"\RFS&Sj5r$\RFS'Sj5r$S(Sjr$S)Sjr%SSSSS.S*Sjjr&S+S,SjjrS-SjrS.Sjr'S/S0Sjjr(S1S2Sjjr)S3Sjr*S4S5Sjjr+S6S jr,S7S!jr-\6S8S"j5r.g)9�)�annotationsN)�datetime)�cache)�update_wrapper)�abort)�redirect)�Response�)�_cv_app)�_cv_request)�current_app)�request)�request_ctx)�session)�message_flashedc��[RRS5n[U=(a UR	5S;5$)z�Get whether debug mode should be enabled for the app, indicated by the7:envvar:`FLASK_DEBUG` environment variable. The default is ``False``.8�FLASK_DEBUG>�0�no�false)�os�environ�get�bool�lower)�vals �SD:\code\apps\devtools\python\user_packages\Python313\site-packages\flask/helpers.py�get_debug_flagrs2��
�*�*�.�.��9'�C���?��	�	��+?�?�@�@�c�x�[RRS5nU(dU$UR5S;$)z�Get whether the user has disabled loading default dotenv files by10setting :envvar:`FLASK_SKIP_DOTENV`. The default is ``True``, load11the files.12 13:param default: What to return if the env var isn't set.14�FLASK_SKIP_DOTENV)rrr)rrrr)�defaultrs  r�get_load_dotenvr#$s1��
�*�*�.�.�,�15-�C�����9�9�;�.�.�.rc��g�N���generator_or_functions r�stream_with_contextr)3s��rc��gr%r&r's rr)r)9s	��@Crc�^^�[T5mSU4SjjnU"5n[U5 U$![a SU4Sjjn[UT5s$f=f)a�Wrap a response generator function so that it runs inside the current16request context. This keeps :data:`request`, :data:`session`, and :data:`g`17available, even though at the point the generator runs the request context18will typically have ended.19 20Use it as a decorator on a generator function:21 22.. code-block:: python23 24    from flask import stream_with_context, request, Response25 26    @app.get("/stream")27    def streamed_response():28        @stream_with_context29        def generate():30            yield "Hello "31            yield request.args["name"]32            yield "!"33 34        return Response(generate())35 36Or use it as a wrapper around a created generator:37 38.. code-block:: python39 40    from flask import stream_with_context, request, Response41 42    @app.get("/stream")43    def streamed_response():44        def generate():45            yield "Hello "46            yield request.args["name"]47            yield "!"48 49        return Response(stream_with_context(generate()))50 51.. versionadded:: 0.952c�*>�T"U0UD6n[U5$r%)r))�args�kwargs�genr(s   �r�	decorator�&stream_with_context.<locals>.decoratorls���'��8��8�C�&�s�+�+rc3�># �[R"S5=nc[S5e[R"5nSv� U U TShv�N [	TS5(aTR5 SSS5 SSS5 gN6![	TS5(aTR5 ff=f!,(df   N@=f!,(df   g=f7f)Nzd'stream_with_context' can only be used when a request context is active, such as in a view function.�close)rr�RuntimeErrorr�hasattrr3)�req_ctx�app_ctxr/s  �r�	generator�&stream_with_context.<locals>.generatorrs�����"���t�,�,�G�5��B��
�53�+�+�-��54�55��g�
 �����3��(�(��I�I�K�
�W�W����3��(�(��I�I�K�)���g��W�W�s`�AC�B>�B-�B�
B�B�!B-�3B>�;	C�B�$B*�*B-�-56B;	�7B>�>57C�C)r-�t.Anyr.r:�returnr:)r;�t.Iterator[t.AnyStr])�iter�	TypeErrorr�next)r(r0r8�	wrapped_gr/s`   @rr)r)?sY���R@��(�)�� �6��I���O����K�@�	,��i�)>�?�?�
@�s�+�A�Ac��U(d[R"5$[U5S:XaUSn[R"U5$)aSometimes it is necessary to set additional headers in a view.  Because58views do not have to return response objects but can return a value that59is converted into a response object by Flask itself, it becomes tricky to60add headers to it.  This function can be called instead of using a return61and you will get a response object which you can use to attach headers.62 63If view looked like this and you want to add a new header::64 65    def index():66        return render_template('index.html', foo=42)67 68You can now do something like this::69 70    def index():71        response = make_response(render_template('index.html', foo=42))72        response.headers['X-Parachutes'] = 'parachutes are cool'73        return response74 75This function accepts the very same arguments you can return from a76view function.  This for example creates a response with a 404 error77code::78 79    response = make_response(render_template('not_found.html'), 404)80 81The other use case of this function is to force the return value of a82view function into a response which is helpful with view83decorators::84 85    response = make_response(view_function())86    response.headers['X-Parachutes'] = 'parachutes are cool'87 88Internally this function does the following things:89 90-   if no arguments are passed, it creates a new response argument91-   if one argument is passed, :meth:`flask.Flask.make_response`92    is invoked with it.93-   if more than one argument is passed, the arguments are passed94    to the :meth:`flask.Flask.make_response` function as tuple.95 96.. versionadded:: 0.697r98r)r
�response_class�len�
make_response)r-s rrDrD�s<��T��)�)�+�+�99�4�y�A�~��A�w���$�$�T�*�*r��_anchor�_method�_scheme�	_externalc�:�[R"U4UUUUS.UD6$)a,Generate a URL to the given endpoint with the given values.100 101This requires an active request or application context, and calls102:meth:`current_app.url_for() <flask.Flask.url_for>`. See that method103for full documentation.104 105:param endpoint: The endpoint name associated with the URL to106    generate. If this starts with a ``.``, the current blueprint107    name (if any) will be used.108:param _anchor: If given, append this as ``#anchor`` to the URL.109:param _method: If given, generate the URL associated with this110    method for the endpoint.111:param _scheme: If given, the URL will have this scheme if it is112    external.113:param _external: If given, prefer the URL to be internal (False) or114    require it to be external (True). External URLs include the115    scheme and domain. When not in an active request, URLs are116    external by default.117:param values: Values to use for the variable parts of the URL rule.118    Unknown keys are appended as query string arguments, like119    ``?a=b&c=d``.120 121.. versionchanged:: 2.2122    Calls ``current_app.url_for``, allowing an app to override the123    behavior.124 125.. versionchanged:: 0.10126   The ``_scheme`` parameter was added.127 128.. versionchanged:: 0.9129   The ``_anchor`` and ``_method`` parameters were added.130 131.. versionchanged:: 0.9132   Calls ``app.handle_url_build_error`` on build errors.133rE)r
�url_for)�endpointrFrGrHrI�valuess      rrKrK�s6��X�����������
�rc�T�[(a[R"XS9$[XUS9$)aCreate a redirect response object.134 135If :data:`~flask.current_app` is available, it will use its136:meth:`~flask.Flask.redirect` method, otherwise it will use137:func:`werkzeug.utils.redirect`.138 139:param location: The URL to redirect to.140:param code: The status code for the redirect.141:param Response: The response class to use. Not used when142    ``current_app`` is active, which uses ``app.response_class``.143 144.. versionadded:: 2.2145    Calls ``current_app.redirect`` if available instead of always146    using Werkzeug's default ``redirect``.147)�code)rOr	)r
r�_wz_redirect)�locationrOr	s   rrr�s'��$�{��#�#�H�8�8���h�?�?rc�l�[(a[R"U/UQ70UD6 [U/UQ70UD6 g)aRaise an :exc:`~werkzeug.exceptions.HTTPException` for the given148status code.149 150If :data:`~flask.current_app` is available, it will call its151:attr:`~flask.Flask.aborter` object, otherwise it will use152:func:`werkzeug.exceptions.abort`.153 154:param code: The status code for the exception, which must be155    registered in ``app.aborter``.156:param args: Passed to the exception.157:param kwargs: Passed to the exception.158 159.. versionadded:: 2.2160    Calls ``current_app.aborter`` if available instead of always161    using Werkzeug's default ``abort``.162N)r
�aborter�	_wz_abort)rOr-r.s   rrrs3��"�{����D�2�4�2�6�2�
�d�$�T�$�V�$rc�h�[[RRU5RU5$)a,Loads a macro (or variable) a template exports.  This can be used to163invoke a macro from within Python code.  If you for example have a164template named :file:`_cider.html` with the following contents:165 166.. sourcecode:: html+jinja167 168   {% macro hello(name) %}Hello {{ name }}!{% endmacro %}169 170You can access this from Python code like this::171 172    hello = get_template_attribute('_cider.html', 'hello')173    return hello('World')174 175.. versionadded:: 0.2176 177:param template_name: the name of the template178:param attribute: the name of the variable of macro to access179)�getattrr
�	jinja_env�get_template�module)�
template_name�	attributes  r�get_template_attributer\(s(��&�;�(�(�5�5�m�D�K�K�Y�W�Wrc���[R"S/5nURX45 U[S'[R"5n[180R"UURUUS9 g)alFlashes a message to the next request.  In order to remove the181flashed message from the session and to display it to the user,182the template has to call :func:`get_flashed_messages`.183 184.. versionchanged:: 0.3185   `category` parameter added.186 187:param message: the message to be flashed.188:param category: the category for the message.  The following values189                 are recommended: ``'message'`` for any kind of message,190                 ``'error'`` for errors, ``'info'`` for information191                 messages and ``'warning'`` for warnings.  However any192                 kind of string can be used as category.193�_flashes)�_async_wrapper�message�categoryN)rr�appendr
�_get_current_objectr�send�ensure_sync)r`ra�flashes�apps    r�flashrh>sY��,�k�k�*�b�)�G��N�N�H�&�'�!�G�J��194�195)�196)�197+�C����������	rc�198^�[RnUc-S[;a[R"S5O/nU[lT(a[	[U4SjU55nU(dUVs/sHo3SPM	 sn$U$s snf)a�Pulls all flashed messages from the session and returns them.199Further calls in the same request to the function will return200the same messages.  By default just the messages are returned,201but when `with_categories` is set to ``True``, the return value will202be a list of tuples in the form ``(category, message)`` instead.203 204Filter the flashed messages to one or more categories by providing those205categories in `category_filter`.  This allows rendering categories in206separate html blocks.  The `with_categories` and `category_filter`207arguments are distinct:208 209* `with_categories` controls whether categories are returned with message210  text (``True`` gives a tuple, where ``False`` gives just the message text).211* `category_filter` filters the messages down to only those matching the212  provided categories.213 214See :doc:`/patterns/flashing` for examples.215 216.. versionchanged:: 0.3217   `with_categories` parameter added.218 219.. versionchanged:: 0.9220    `category_filter` parameter added.221 222:param with_categories: set to ``True`` to also receive categories.223:param category_filter: filter of categories to limit return values.  Only224                        categories in the list will be returned.225r^c�>�UST;$)Nrr&)�f�category_filters �r�<lambda>�&get_flashed_messages.<locals>.<lambda>�s����!���(?rr226)rrfr�pop�list�filter)�with_categoriesrlrf�xs `  r�get_flashed_messagesrt`sm���>�!�!�G���-7�7�-B�'�+�+�j�)���%�����v�?��I�J���%�&�g��!��g�&�&��N��'s�-Bc���URS5c[RUS'UR[R227[RS[R[RS9 U$)N�max_age�USE_X_SENDFILE)r�use_x_sendfilerB�228_root_path)	rr
�get_send_file_max_age�updaterr�configrB�	root_path)r.s r�_prepare_send_file_kwargsr~�sa��
�z�z�)��$�'�=�=��y��229�M�M����"�)�)�*:�;�"�1�1��(�(�	���Mrc�|�[RR"S0[U[R230UUUUUUUS9	D6$)aSend the contents of a file to the client.231 232The first argument can be a file path or a file-like object. Paths233are preferred in most cases because Werkzeug can manage the file and234get extra information from the path. Passing a file-like object235requires that the file is opened in binary mode, and is mostly236useful when building a file in memory with :class:`io.BytesIO`.237 238Never pass file paths provided by a user. The path is assumed to be239trusted, so a user could craft a path to access a file you didn't240intend. Use :func:`send_from_directory` to safely serve241user-requested paths from within a directory.242 243If the WSGI server sets a ``file_wrapper`` in ``environ``, it is244used, otherwise Werkzeug's built-in wrapper is used. Alternatively,245if the HTTP server supports ``X-Sendfile``, configuring Flask with246``USE_X_SENDFILE = True`` will tell the server to send the given247path, which is much more efficient than reading it in Python.248 249:param path_or_file: The path to the file to send, relative to the250    current working directory if a relative path is given.251    Alternatively, a file-like object opened in binary mode. Make252    sure the file pointer is seeked to the start of the data.253:param mimetype: The MIME type to send for the file. If not254    provided, it will try to detect it from the file name.255:param as_attachment: Indicate to a browser that it should offer to256    save the file instead of displaying it.257:param download_name: The default name browsers will use when saving258    the file. Defaults to the passed file name.259:param conditional: Enable conditional and range responses based on260    request headers. Requires passing a file path and ``environ``.261:param etag: Calculate an ETag for the file, which requires passing262    a file path. Can also be a string to use instead.263:param last_modified: The last modified time to send for the file,264    in seconds. If not provided, it will try to detect it from the265    file path.266:param max_age: How long the client should cache the file, in267    seconds. If set, ``Cache-Control`` will be ``public``, otherwise268    it will be ``no-cache`` to prefer conditional caching.269 270.. versionchanged:: 2.0271    ``download_name`` replaces the ``attachment_filename``272    parameter. If ``as_attachment=False``, it is passed with273    ``Content-Disposition: inline`` instead.274 275.. versionchanged:: 2.0276    ``max_age`` replaces the ``cache_timeout`` parameter.277    ``conditional`` is enabled and ``max_age`` is not set by278    default.279 280.. versionchanged:: 2.0281    ``etag`` replaces the ``add_etags`` parameter. It can be a282    string to use instead of generating one.283 284.. versionchanged:: 2.0285    Passing a file-like object that inherits from286    :class:`~io.TextIOBase` will raise a :exc:`ValueError` rather287    than sending an empty file.288 289.. versionadded:: 2.0290    Moved the implementation to Werkzeug. This is now a wrapper to291    pass some Flask-specific arguments.292 293.. versionchanged:: 1.1294    ``filename`` may be a :class:`~os.PathLike` object.295 296.. versionchanged:: 1.1297    Passing a :class:`~io.BytesIO` object supports range requests.298 299.. versionchanged:: 1.0.3300    Filenames are encoded with ASCII instead of Latin-1 for broader301    compatibility with WSGI servers.302 303.. versionchanged:: 1.0304    UTF-8 filenames as specified in :rfc:`2231` are supported.305 306.. versionchanged:: 0.12307    The filename is no longer automatically inferred from file308    objects. If you want to use automatic MIME and etag support,309    pass a filename via ``filename_or_fp`` or310    ``attachment_filename``.311 312.. versionchanged:: 0.12313    ``attachment_filename`` is preferred over ``filename`` for MIME314    detection.315 316.. versionchanged:: 0.9317    ``cache_timeout`` defaults to318    :meth:`Flask.get_send_file_max_age`.319 320.. versionchanged:: 0.7321    MIME guessing and etag support for file-like objects was322    removed because it was unreliable. Pass a filename if you are323    able to, otherwise attach an etag yourself.324 325.. versionchanged:: 0.5326    The ``add_etags``, ``cache_timeout`` and ``conditional``327    parameters were added. The default behavior is to add etags.328 329.. versionadded:: 0.2330)	�path_or_filer�mimetype�
as_attachment�
download_name�conditional�etag�
last_modifiedrvr&)�werkzeug�utils�	send_filer~rr)r�r�r�r�r�r�r�rvs        rr�r��sH��^�>�>�#�#��331#�%��O�O��'�'�#��'��332333��rc	�V�[RR"X40[S0UD6D6$)a�Send a file from within a directory using :func:`send_file`.334 335.. code-block:: python336 337    @app.route("/uploads/<path:name>")338    def download_file(name):339        return send_from_directory(340            app.config['UPLOAD_FOLDER'], name, as_attachment=True341        )342 343This is a secure way to serve files from a folder, such as static344files or uploads. Uses :func:`~werkzeug.security.safe_join` to345ensure the path coming from the client is not maliciously crafted to346point outside the specified directory.347 348If the final path does not point to an existing regular file,349raises a 404 :exc:`~werkzeug.exceptions.NotFound` error.350 351:param directory: The directory that ``path`` must be located under,352    relative to the current application's root path. This *must not*353    be a value provided by the client, otherwise it becomes insecure.354:param path: The path to the file to send, relative to355    ``directory``.356:param kwargs: Arguments to pass to :func:`send_file`.357 358.. versionchanged:: 2.0359    ``path`` replaces the ``filename`` parameter.360 361.. versionadded:: 2.0362    Moved the implementation to Werkzeug. This is now a wrapper to363    pass some Flask-specific arguments.364 365.. versionadded:: 0.5366r&)r�r��send_from_directoryr~)�	directory�pathr.s   rr�r�s/��N�>�>�-�-���4�>�v�>��rc��[RRU5nUbd[US5(aSURbF[367RR[368RRUR55$[RRU5nUc[eURnUc[369R"5$[US5(aUR!U5nO>[#U5 [RUn[%USS5nUc['SU<S35e[370RR[371RRU55$![[4a SnN�f=f)z�Find the root path of a package, or the path that contains a372module. If it cannot be found, returns the current working373directory.374 375Not to be confused with the value returned by :func:`find_package`.376 377:meta private:378N�__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�modulesrr5r�rr��dirname�abspath�	importlib�util�	find_spec�379ValueError�loader�ImportError�getcwdr��380__import__rVr4)�import_name�mod�specr��filepaths     r�
get_root_pathr�AsE���+�+�/�/�+�381&�C�382��7�3�383�3�3����8P��w�w���r�w�w���s�|�|�<�=�=���~�~�'�'��4���<����384����385�~��y�y�{���v�~�&�&��&�&�{�3��	�;���k�k�+�&���3�386�D�1��387�����?�#���
��7�7�?�?�2�7�7�?�?�8�4�5�5��C
��$�����s�(E2�2F�Fc�p�U/nSU;a,UR[URS5S55 U$)N�.r)�extend�_split_blueprint_path�388rpartition)�name�outs  rr�r�zs5���V�C�389�d�{��390�391�(�����)=�a�)@�A�B��Jr)r;r)T)r"rr;r)r(r<r;r<)r(z%t.Callable[..., t.Iterator[t.AnyStr]]r;z8t.Callable[[t.Iterator[t.AnyStr]], t.Iterator[t.AnyStr]])r(z<t.Iterator[t.AnyStr] | t.Callable[..., t.Iterator[t.AnyStr]]r;zOt.Iterator[t.AnyStr] | t.Callable[[t.Iterator[t.AnyStr]], t.Iterator[t.AnyStr]])r-r:r;r	)rL�strrF�392str | NonerGr�rHr�rIzbool | NonerMr:r;r�)i.N)rQr�rO�intr	ztype[BaseResponse] | Noner;�BaseResponse)rOzint | BaseResponser-r:r.r:r;z393t.NoReturn)rZr�r[r�r;r:)r`)r`r�rar�r;�None)Fr&)rrrrlzt.Iterable[str]r;z!list[str] | list[tuple[str, str]])r.r:r;zdict[str, t.Any])NFNTTNN)r�z)os.PathLike[t.AnyStr] | str | t.IO[bytes]r�r�r�rr�r�r�rr�z394bool | strr�zdatetime | int | float | Nonervz3None | (int | t.Callable[[str | None], int | None])r;r	)r��os.PathLike[str] | strr�r�r.r:r;r	)r�r�r;r�)r�r�r;z	list[str])/�395__future__r�importlib.utilr�rr��typing�tr�	functoolsrr�werkzeug.utilsr��werkzeug.exceptionsrrTrrP�werkzeug.wrappersr	r��globalsrrr
rrr�signalsr�
TYPE_CHECKING�wrappersrr#�overloadr)rDrKr\rhrtr~r�r�r�r�r&rr�<module>r�sL��"��	�396����$��2�3�6�� � �� ��$��?�?�"�A�/�����/������397���C�@�C�=�C��C�398P�W�P�T�P�f.+�h���!�
3��3��3��	3�399�3��
3��3�	�3�nKO�@��@��@�.G�@��@�0%�.X�,�FGI�'��'�4C�'�&�'�T400� �� $���37�CG�{�;�{��{��{��	{�401�{��
{�1�{�A�{��{�|)�%�)�402 �)��)��	)�X66�r���r
codekingpro/portable-devtools · Team Ai