§
    „ß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 n# e$ r	 ddlmZ Y nw xY wej        rddlmZ ddlmZ ddlmZ  G d	„ d
¦  «        ZdS )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                  ó8   — e Zd ZdZej        ddddfdd„Zdd„ZdS )Ú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}.profÚappr   Ústreamút.IO[str] | NoneÚsort_byút.Iterable[str]Úrestrictionsút.Iterable[str | int | float]Úprofile_dirú
str | NoneÚfilename_formatÚstrÚreturnÚNonec                óZ   — || _         || _        || _        || _        || _        || _        d S ©N)Ú_appÚ_streamÚ_sort_byÚ_restrictionsÚ_profile_dirÚ_filename_format)Úselfr   r   r   r   r   r   s          úO/var/www/html/venv/lib/python3.11/site-packages/werkzeug/middleware/profiler.pyÚ__init__zProfilerMiddleware.__init__Y   s7   € ð ˆŒ	ØˆŒØˆŒØ)ˆÔØ'ˆÔØ /ˆÔÐÐó    Úenvironr   Ústart_responser   út.Iterable[bytes]c                ó  ‡ ‡‡‡‡— g Šdˆˆfd„	Šdˆˆˆˆ fd„}t          ¦   «         }t          j        ¦   «         }|                     |¦  «         d                     ‰¦  «        }t          j        ¦   «         |z
  }‰ j        �çt          ‰ j        ¦  «        r2|dz  t          j        ¦   «         dœ‰d<   ‰                      ‰¦  «        }ng‰ j                             ‰d	         ‰d
                              d¦  «         	                    dd¦  «        pd|dz  t          j        ¦   «         ¬¦  «        }t          j                             ‰ j        |¦  «        }|                     |¦  «         ‰ j        �’t          |‰ j        ¬¦  «        }	 |	j        ‰ j        Ž  t#          d‰ j        ¬¦  «         ‰                     d
d¦  «        }
t#          d|
›�‰ j        ¬¦  «          |	j        ‰ j        Ž  t#          d› d�‰ j        ¬¦  «         |gS )Nc                ó,   •—  ‰| ||¦  «         ‰j         S r   )Úappend)ÚstatusÚheadersÚexc_infoÚresponse_bodyr(   s      €€r$   Úcatching_start_responsez<ProfilerMiddleware.__call__.<locals>.catching_start_responsen   s    ø€ ØˆN˜6 7¨HÑ5Ô5Ð5Ø Ô'Ð'r&   r   r   c                 óÐ   •— ‰                      ‰t          j        d‰¦  «        ¦  «        } ‰                     | ¦  «         t	          | d¦  «        r|                      ¦   «          d S d S )Nr   Úclose)r   ÚtÚcastÚextendÚhasattrr3   )Úapp_iterr1   r'   r0   r#   s    €€€€r$   Úrunappz+ProfilerMiddleware.__call__.<locals>.runappr   sp   ø€ Ø—y’yØ�œ Ð1HÑIÔIñô ˆHð × Ò  Ñ*Ô*Ð*å�x Ñ)Ô)ð !Ø—’Ñ Ô Ð Ð Ð ð!ð !r&   r&   g     @�@)Úelapsedr   zwerkzeug.profilerÚREQUEST_METHODÚ	PATH_INFOú/ú.Úroot)ÚmethodÚpathr:   r   )r   zP--------------------------------------------------------------------------------)ÚfileÚ zPATH: ú
r   )r   r   )r   r   ÚruncallÚjoinr!   Úcallabler"   ÚformatÚstripÚreplaceÚosrA   Ú
dump_statsr   r   Ú
sort_statsr   ÚprintÚgetÚprint_statsr    )r#   r'   r(   r9   ÚprofileÚstartÚbodyr:   ÚfilenameÚstatsÚ	path_infor1   r0   s   ```        @@r$   Ú__call__zProfilerMiddleware.__call__i   s6  øøøøø€ ð &(ˆð	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð	!ð 	!ð 	!ð 	!ð 	!ð 	!ð 	!ð 	!ð 	!õ ‘)”)ˆÝ”	‘”ˆØ�Š˜ÑÔÐØ�xŠx˜Ñ&Ô&ˆÝ”)‘+”+ Ñ%ˆàÔÐ(Ý˜Ô-Ñ.Ô.ð à&¨Ñ/Ý œI™KœKð0ð 0�Ð+Ñ,ð  ×0Ò0°Ñ9Ô9��àÔ0×7Ò7Ø"Ð#3Ô4Ø  Ô-×3Ò3°CÑ8Ô8×@Ò@ÀÀcÑJÔJÐTÈfØ# fÑ,Ýœ™œð	 8ñ ô �õ ”w—|’| DÔ$5°xÑ@Ô@ˆHØ×Ò˜xÑ(Ô(Ð(àŒ<Ð#Ý˜'¨$¬,Ð7Ñ7Ô7ˆEØˆEÔ˜dœmÐ,Ð,Ý�( ¤Ð.Ñ.Ô.Ð.ØŸš K°Ñ4Ô4ˆIÝÐ(˜9Ð(Ð(¨t¬|Ð<Ñ<Ô<Ð<ØˆEÔ˜tÔ1Ð2Ð2Ý�X�/�/�/¨¬Ð5Ñ5Ô5Ð5àˆvˆr&   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r'   r   r(   r   r   r)   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚsysÚstdoutr%   rW   r   r&   r$   r
   r
   "   s_   € € € € € ð4ð 4ðr $'¤:Ø#4Ø68Ø"&ØPð0ð 0ð 0ð 0ð 0ð 2ð 2ð 2ð 2ð 2ð 2r&   r
   )r[   Ú
__future__r   Úos.pathrK   r\   r   Útypingr4   Úpstatsr   ÚcProfiler   ÚImportErrorrQ   ÚTYPE_CHECKINGÚ_typeshed.wsgir   r   r   r
   r   r&   r$   ú<module>rf      s'  ððð ð #Ð "Ð "Ð "Ð "Ð "à €€€Ø 
€
€
€
Ø €€€Ø Ð Ð Ð Ø Ð Ð Ð Ð Ð ð Ø Ð Ð Ð Ð Ð Ð øØð  ð  ð  ØÐÐÐÐÐÐÐð øøøð „?ð /Ø,Ð,Ð,Ð,Ð,Ð,Ø.Ð.Ð.Ð.Ð.Ð.Ø.Ð.Ð.Ð.Ð.Ð.ðyð yð yð yð yñ yô yð yð yð ys    ' §5´5