Ë
    6•±jº  ã                  óÀ   — d Z ddlmZ ddlZddlZddlZddlZddl	m
Z
 	 ddlmZ ej                  rddlmZ ddlmZ ddlmZ  G d	„ d
«      Zy# e$ r	 ddlmZ Y Œ6w xY w)a9  
Application Profiler
====================

This module provides a middleware that profiles each request with the
:mod:`cProfile` module. This can help identify bottlenecks in your code
that may be slowing down your application.

.. autoclass:: ProfilerMiddleware

:copyright: 2007 Pallets
:license: BSD-3-Clause
é    )ÚannotationsN)ÚStats)ÚProfile)ÚStartResponse)ÚWSGIApplication)ÚWSGIEnvironmentc                  óf   — e Zd ZdZej
                  ddddf	 	 	 	 	 	 	 	 	 	 	 	 	 dd„Z	 	 	 	 	 	 d	d„Zy)
ÚProfilerMiddlewarea	  Wrap a WSGI application and profile the execution of each
    request. Responses are buffered so that timings are more exact.

    If ``stream`` is given, :class:`pstats.Stats` are written to it
    after each request. If ``profile_dir`` is given, :mod:`cProfile`
    data files are saved to that directory, one file per request.

    The filename can be customized by passing ``filename_format``. If
    it is a string, it will be formatted using :meth:`str.format` with
    the following fields available:

    -   ``{method}`` - The request method; GET, POST, etc.
    -   ``{path}`` - The request path or 'root' should one not exist.
    -   ``{elapsed}`` - The elapsed time of the request in milliseconds.
    -   ``{time}`` - The time of the request.

    If it is a callable, it will be called with the WSGI ``environ`` and
    be expected to return a filename string. The ``environ`` dictionary
    will also have the ``"werkzeug.profiler"`` key populated with a
    dictionary containing the following fields (more may be added in the
    future):
    -   ``{elapsed}`` - The elapsed time of the request in milliseconds.
    -   ``{time}`` - The time of the request.

    :param app: The WSGI application to wrap.
    :param stream: Write stats to this stream. Disable with ``None``.
    :param sort_by: A tuple of columns to sort stats by. See
        :meth:`pstats.Stats.sort_stats`.
    :param restrictions: A tuple of restrictions to filter stats by. See
        :meth:`pstats.Stats.print_stats`.
    :param profile_dir: Save profile data files to this directory.
    :param filename_format: Format string for profile data file names,
        or a callable returning a name. See explanation above.

    .. code-block:: python

        from werkzeug.middleware.profiler import ProfilerMiddleware
        app = ProfilerMiddleware(app)

    .. versionchanged:: 3.0
        Added the ``"werkzeug.profiler"`` key to the ``filename_format(environ)``
        parameter with the  ``elapsed`` and ``time`` fields.

    .. versionchanged:: 0.15
        Stats are written even if ``profile_dir`` is given, and can be
        disable by passing ``stream=None``.

    .. versionadded:: 0.15
        Added ``filename_format``.

    .. versionadded:: 0.9
        Added ``restrictions`` and ``profile_dir``.
    )ÚtimeÚcalls© Nz/{method}.{path}.{elapsed:.0f}ms.{time:.0f}.profc                óX   — || _         || _        || _        || _        || _        || _        y ©N)Ú_appÚ_streamÚ_sort_byÚ_restrictionsÚ_profile_dirÚ_filename_format)ÚselfÚappÚstreamÚsort_byÚrestrictionsÚprofile_dirÚfilename_formats          úg/var/www/passport.vulcan-creative.com/venv/lib/python3.12/site-packages/werkzeug/middleware/profiler.pyÚ__init__zProfilerMiddleware.__init__Y   s1   € ð ˆŒ	ØˆŒØˆŒØ)ˆÔØ'ˆÔØ /ˆÕó    c                ó  ‡ ‡‡‡‡— g Šdˆˆfd„	Šdˆˆˆˆ fd„}t        «       }t        j                  «       }|j                  |«       dj                  ‰«      }t        j                  «       |z
  }‰ j                  �Üt        ‰ j                  «      r/|dz  t        j                  «       dœ‰d<   ‰ j                  ‰«      }n]‰ j                  j                  ‰d   ‰d   j                  d	«      j                  d	d
«      xs d|dz  t        j                  «       ¬«      }t        j                  j                  ‰ j                  |«      }|j                  |«       ‰ j                  �¦t        |‰ j                  ¬«      }	 |	j                  ‰ j                   Ž  t#        d‰ j                  ¬«       ‰j%                  dd«      }
t#        d|
›�‰ j                  ¬«        |	j&                  ‰ j(                  Ž  t#        d› d�‰ j                  ¬«       |gS )Nc                ó0   •—  ‰| ||«       ‰j                   S r   )Úappend)ÚstatusÚheadersÚexc_infoÚresponse_bodyÚstart_responses      €€r   Úcatching_start_responsez<ProfilerMiddleware.__call__.<locals>.catching_start_responsen   s   ø€ Ù˜6 7¨HÔ5Ø ×'Ñ'Ð'r   c                 ó®   •— ‰j                  ‰t        j                  d‰«      «      } ‰j                  | «       t	        | d«      r| j                  «        y y )Nr   Úclose)r   ÚtÚcastÚextendÚhasattrr*   )Úapp_iterr(   Úenvironr&   r   s    €€€€r   Úrunappz+ProfilerMiddleware.__call__.<locals>.runappr   sK   ø€ Ø—y‘yØœŸ™ Ð1HÓIóˆHð × Ñ  Ô*ä�x Ô)Ø—‘Õ ð *r   r   g     @�@)Úelapsedr   zwerkzeug.profilerÚREQUEST_METHODÚ	PATH_INFOú/ú.Úroot)ÚmethodÚpathr2   r   )r   zP--------------------------------------------------------------------------------)ÚfileÚ zPATH: ú
r   )ÚreturnÚNone)r   r   ÚruncallÚjoinr   Úcallabler   ÚformatÚstripÚreplaceÚosr9   Ú
dump_statsr   r   Ú
sort_statsr   ÚprintÚgetÚprint_statsr   )r   r0   r'   r1   ÚprofileÚstartÚbodyr2   ÚfilenameÚstatsÚ	path_infor(   r&   s   ```        @@r   Ú__call__zProfilerMiddleware.__call__i   s·  ü€ ð &(ˆö	(÷	!ð 	!ô “)ˆÜ—	‘	“ˆØ�‰˜ÔØ�x‰x˜Ó&ˆÜ—)‘)“+ Ñ%ˆà×ÑÐ(Ü˜×-Ñ-Ô.à&¨Ñ/Ü ŸI™I›Kñ0�Ð+Ñ,ð  ×0Ñ0°Ó9‘à×0Ñ0×7Ñ7Ø"Ð#3Ñ4Ø  Ñ-×3Ñ3°CÓ8×@Ñ@ÀÀcÓJÒTÈfØ# fÑ,ÜŸ™›ð	 8ó �ô —w‘w—|‘| D×$5Ñ$5°xÓ@ˆHØ×Ñ˜xÔ(à�<‰<Ð#Ü˜'¨$¯,©,Ô7ˆEØˆE×Ñ˜dŸm™mÑ,Ü�( §¡Õ.ØŸ™ K°Ó4ˆIÜ�F˜9˜-Ð(¨t¯|©|Õ<ØˆE×Ñ˜t×1Ñ1Ñ2Ü�X�J˜b�/¨¯©Õ5àˆvˆr   )r   r   r   zt.IO[str] | Noner   zt.Iterable[str]r   zt.Iterable[str | int | float]r   z
str | Noner   Ústrr=   r>   )r0   r   r'   r   r=   zt.Iterable[bytes])Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚsysÚstdoutr   rQ   r   r   r   r
   r
   "   sƒ   „ ñ4ðr $'§:¡:Ø#4Ø68Ø"&ØPð0àð0ð !ð0ð !ð	0ð
 4ð0ð  ð0ð ð0ð 
ó0ð 2Ø&ð2Ø8Eð2à	ô2r   r
   )rV   Ú
__future__r   Úos.pathrE   rW   r   Útypingr+   Úpstatsr   ÚcProfiler   ÚImportErrorrK   ÚTYPE_CHECKINGÚ_typeshed.wsgir   r   r   r
   r   r   r   ú<module>ra      sX   ðñõ #ã Û 
Û Û Ý ð Ý ð ‡?‚?Ý,Ý.Ý.÷yò yøð ò  ßð ús    A ÁAÁA