ó
³Ebc           @  sœ   d  Z  d d l m Z d d l Z d d l Z d d l Z d d l m Z y d d l	 m
 Z
 Wn! e k
 r d d l m
 Z
 n Xd e f d „  ƒ  YZ d S(   s9  
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
iÿÿÿÿ(   t   print_functionN(   t   Stats(   t   Profilet   ProfilerMiddlewarec           B  s2   e  Z d  Z e j d d d d d „ Z d „  Z RS(	   s  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.
    -   ``{time}`` - The time of the request.

    If it is a callable, it will be called with the WSGI ``environ``
    dict and should return a filename.

    :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:: 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``.
    t   timet   callss/   {method}.{path}.{elapsed:.0f}ms.{time:.0f}.profc         C  s:   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ d  S(   N(   t   _appt   _streamt   _sort_byt   _restrictionst   _profile_dirt   _filename_format(   t   selft   appt   streamt   sort_byt   restrictionst   profile_dirt   filename_format(    (    st   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/profiler.pyt   __init__I   s    						c   
   	     sÍ  g  ‰ d  ‡ ‡ f d † ‰  ‡  ‡ ‡ ‡ f d †  } t ƒ  } t j ƒ  } | j | ƒ d j ˆ ƒ } t j ƒ  | } ˆ j d  k	 r%t ˆ j ƒ r¤ ˆ j ˆ ƒ } nY ˆ j j d ˆ d d ˆ j	 d ƒ j
 d ƒ j d d	 ƒ pá d
 d | d d t j ƒ  ƒ } t j j ˆ j | ƒ } | j | ƒ n  ˆ j d  k	 rÆt | d ˆ j ƒ}	 |	 j ˆ j Œ  t d d d ˆ j ƒt d j ˆ j	 d d ƒ ƒ d ˆ j ƒ|	 j ˆ j Œ  t d d d d ˆ j ƒn  | g S(   Nc           s   ˆ |  | | ƒ ˆ  j  S(   N(   t   append(   t   statust   headerst   exc_info(   t   response_bodyt   start_response(    st   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/profiler.pyt   catching_start_response\   s    c            s?   ˆ j  ˆ ˆ  ƒ }  ˆ j |  ƒ t |  d ƒ r; |  j ƒ  n  d  S(   Nt   close(   R   t   extendt   hasattrR   (   t   app_iter(   R   t   environR   R   (    st   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/profiler.pyt   runapp`   s    t    t   methodt   REQUEST_METHODt   patht	   PATH_INFOt   /t   .t   roott   elapsedg     @@R   R   t   -iP   t   files
   PATH: {!r}s   
(   t   NoneR   R   t   runcallt   joinR
   t   callableR   t   formatt   gett   stript   replacet   osR$   t
   dump_statsR   R   t
   sort_statsR   t   printt   print_statsR	   (
   R   R   R   R    t   profilet   startt   bodyR)   t   filenamet   stats(    (   R   R   R   R   R   st   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/profiler.pyt   __call__Y   s4    	
*
((   R   R   (    N(   t   __name__t
   __module__t   __doc__t   syst   stdoutR,   R   R>   (    (    (    st   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/profiler.pyR      s   ,	(   RA   t
   __future__R    t   os.pathR4   RB   R   t   pstatsR   t   cProfileR   t   ImportErrorR9   t   objectR   (    (    (    st   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/profiler.pyt   <module>   s   