
Ebc           @   s  d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l 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 d d l m Z d d l m Z d d l m Z d d	 l m Z d d
 l m Z d d l m Z d d l m Z d d l m Z d d l m  Z  d d l m! Z! d Z" d   Z# d a% d   Z& d e' f d     YZ( d   Z) d e' f d     YZ* d S(   s   
    werkzeug.debug
    ~~~~~~~~~~~~~~

    WSGI application traceback debugger.

    :copyright: 2007 Pallets
    :license: BSD-3-Clause
iN(   t   chain(   t   basename(   t   joini   (   t	   text_type(   t   _log(   t   parse_cookie(   t   gen_salt(   t   BaseRequest(   t   BaseResponsei   (   t   Console(   t   get_current_traceback(   t   render_console_htmli<   i   i   c         C   s?   t  |  t  r$ |  j d d  }  n  t j |  d  j   d  S(   Ns   utf-8t   replacet
   shittysalti   (   t
   isinstanceR   t   encodet   hashlibt   md5t	   hexdigest(   t   pin(    (    so   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/debug/__init__.pyt   hash_pin'   s    c          C   s&   t  d  k	 r t  Sd   }  |    a  t  S(   Nc          S   s6  d }  xg d D]_ } y. t  | d   } | j   j   } Wd  QXWn t k
 rW q n X| r |  | 7}  Pq q Wy? t  d d  * } |  | j   j   j d  d 7}  Wd  QXWn t k
 r n X|  r |  Syp d d	 l m } m } | d
 d d d d g d | j   d } t	 j
 d |  } | d  k	 r<| j d  SWn t t f k
 rVn Xy d d  l } Wn; t k
 ry d d  l } Wqt k
 rd  } qXn X| d  k	 r2yj | j | j d d | j | j B ? }	 | j |	 d  \ }
 } | | j k r|
 j d  S|
 SWd  QXWq2t k
 r.q2Xn  d  S(   Nt    s   /etc/machine-ids   /proc/sys/kernel/random/boot_idt   rbs   /proc/self/cgroupt   /i   i(   t   Popent   PIPEt   ioregs   -ct   IOPlatformExpertDevices   -dt   2t   stdouti    s   "serial-number" = <([^>]+)i   s   SOFTWARE\Microsoft\Cryptographyt   MachineGuids   utf-8(   s   /etc/machine-ids   /proc/sys/kernel/random/boot_id(   t   opent   readlinet   stript   IOErrort
   rpartitiont
   subprocessR   R   t   communicatet   ret   searcht   Nonet   groupt   OSErrort   ImportErrort   winregt   _winregt   OpenKeyt   HKEY_LOCAL_MACHINEt   KEY_READt   KEY_WOW64_64KEYt   QueryValueExt   REG_SZR   t   WindowsError(   t   linuxt   filenamet   ft   valueR   R   t   dumpt   matcht   wrt   rkt   guidt	   guid_type(    (    so   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/debug/__init__.pyt	   _generate6   s`    
-!(   t   _machine_idR(   (   R?   (    (    so   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/debug/__init__.pyt   get_machine_id0   s
    	E	t   _ConsoleFramec           B   s   e  Z d  Z d   Z RS(   s]   Helper class so that we can reuse the frame console code for the
    standalone console.
    c         C   s   t  |  |  _ d |  _ d  S(   Ni    (   R	   t   consolet   id(   t   selft	   namespace(    (    so   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/debug/__init__.pyt   __init__   s    (   t   __name__t
   __module__t   __doc__RG   (    (    (    so   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/debug/__init__.pyRB      s   c            sM  t  j j d  } d } d  | d k r. d S| d k	 rp | j d d  j   rp d | k rg | } qp |  n  t |  d |  j j  } y t	 j
   } Wn t t f k
 r d } n Xt j j |  } | | t |  d |  j j  t | d d  g } t t j    t   g } t j   } xQ t | |  D]@ }	 |	 sCq1n  t |	 t  rd|	 j d  }	 n  | j |	  q1W| j d	  d
 | j   d  }
  d k r| j d  d t | j   d  d   n  | d k rCxe d D]T   t     d k rd j    f d   t d t      D  } PqqW } n  | |
 f S(   sQ  Given an application object this returns a semi-stable 9 digit pin
    code and a random key.  The hope is that this is stable between
    restarts to not make debugging particularly frustrating.  If the pin
    was forcefully disabled this returns `None`.

    Second item in the resulting tuple is the cookie name for remembering.
    t   WERKZEUG_DEBUG_PINt   offt   -R   RI   RH   t   __file__s   utf-8t
   cookiesaltt   __wzdi   t   pinsalts   %09di   i	   i   i   i   i    c         3   s,   |  ]" }  | |   !j    d   Vq d S(   t   0N(   t   rjust(   t   .0t   x(   t
   group_sizet   num(    so   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/debug/__init__.pys	   <genexpr>   s   N(   NN(   i   i   i   (    t   ost   environt   getR(   R   t   isdigitt   getattrt	   __class__RI   t   getpasst   getuserR+   t   KeyErrort   syst   modulesRH   t   strt   uuidt   getnodeRA   R   R   R    R   R   R   t   updateR   t   intt   lenR   t   range(   t   appR   t   rvt   modnamet   usernamet   modt   probably_public_bitst   private_bitst   ht   bitt   cookie_name(    (   RV   RW   so   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/debug/__init__.pyt   get_pin_and_cookie_name   sR    $		
 	t   DebuggedApplicationc           B   s   e  Z d  Z e d d d e e e d  Z e d    Z e j	 d    Z e d    Z
 d   Z d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s  Enables debugging support for a given application::

        from werkzeug.debug import DebuggedApplication
        from myapp import app
        app = DebuggedApplication(app, evalex=True)

    The `evalex` keyword argument allows evaluating expressions in a
    traceback's frame context.

    :param app: the WSGI application to run debugged.
    :param evalex: enable exception evaluation feature (interactive
                   debugging).  This requires a non-forking server.
    :param request_key: The key that points to the request object in ths
                        environment.  This parameter is ignored in current
                        versions.
    :param console_path: the URL for a general purpose console.
    :param console_init_func: the function that is executed before starting
                              the general purpose console.  The return value
                              is used as initial namespace.
    :param show_hidden_frames: by default hidden traceback frames are skipped.
                               You can show them by setting this parameter
                               to `True`.
    :param pin_security: can be used to disable the pin based security system.
    :param pin_logging: enables the logging of the pin system.
    s   werkzeug.requests   /consolec	   	      C   s   | s d  } n  | |  _ | |  _ i  |  _ i  |  _ | |  _ | |  _ | |  _ | |  _ t	 d  |  _
 d |  _ | |  _ | r t j j d  d k r | r t d d  |  j d  k r t d d  q t d d	 |  j  q n	 d  |  _ d  S(
   Ni   i    t   WERKZEUG_RUN_MAINt   truet   warnings    * Debugger is active!s-    * Debugger PIN disabled. DEBUGGER UNSECURED!t   infos    * Debugger PIN: %s(   R(   Rj   t   evalext   framest
   tracebackst   request_keyt   console_patht   console_init_funct   show_hidden_framesR   t   secrett   _failed_pin_autht   pin_loggingRX   RY   RZ   R   R   (	   RE   Rj   Rz   R}   R~   R   R   t   pin_securityR   (    (    so   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/debug/__init__.pyRG      s(    											c         C   s4   t  |  d  s- t |  j  \ |  _ |  _ n  |  j S(   Nt   _pin(   t   hasattrRt   Rj   R   t   _pin_cookie(   RE   (    (    so   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/debug/__init__.pyR     s    c         C   s   | |  _  d  S(   N(   R   (   RE   R8   (    (    so   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/debug/__init__.pyR   !  s    c         C   s4   t  |  d  s- t |  j  \ |  _ |  _ n  |  j S(   s   The name of the pin cookie.R   (   R   Rt   Rj   R   R   (   RE   (    (    so   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/debug/__init__.pyt   pin_cookie_name%  s    c         c   se  d } yH |  j | |  } x | D] } | Vq" Wt | d  rM | j   n  Wnt k
 r`t | d  rz | j   n  t d d d |  j d t  } x! | j D] } | |  j | j	 <q W| |  j
 | j	 <y | d d d g  Wn" t k
 r| d j d  nE Xt |  j |   } | j d |  j d | d |  j  j d d  V| j | d  n Xd S(   s6   Run the application and conserve the traceback frames.t   closet   skipi   R   t   ignore_system_exceptionss   500 INTERNAL SERVER ERRORs   Content-Types   text/html; charset=utf-8s   X-XSS-ProtectionRR   s   wsgi.errorssp   Debugging middleware caught exception in streamed response at a point where response headers were already sent.
Rz   t   evalex_trustedR   s   utf-8R   N(   s   Content-Types   text/html; charset=utf-8(   s   X-XSS-ProtectionRR   (   R(   Rj   R   R   t	   ExceptionR
   R   t   TrueR{   RD   R|   t   writet   boolt   check_pin_trustt   render_fullRz   R   R   t   log(   RE   RY   t   start_responset   app_itert   itemt	   tracebackt   framet
   is_trusted(    (    so   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/debug/__init__.pyt   debug_application,  s<    			
	c         C   s   t  | j j |  d d S(   s   Execute a command in a console.t   mimetypes	   text/html(   t   ResponseRC   t   eval(   RE   t   requestt   commandR   (    (    so   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/debug/__init__.pyt   execute_command]  s    c         C   s   d |  j  k rb |  j d k r' i  } n t |  j    } | j d |  j  t |  |  j  d <n  t |  j | j	   } t
 t d |  j d |  d d S(   s   Display a standalone shell.i    Rj   R   R   R   s	   text/htmlN(   R{   R   R(   t   dictt
   setdefaultRj   RB   R   R   RY   R   R   R   (   RE   R   t   nsR   (    (    so   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/debug/__init__.pyt   display_consolea  s    	c         C   s%   | j    } t t j |  d d S(   s/   Paste the traceback and return a JSON response.R   s   application/json(   t   pasteR   t   jsont   dumps(   RE   R   R   Rk   (    (    so   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/debug/__init__.pyt   paste_tracebackp  s    c         C   s   t  d t |   } y t j t |  } Wn t k
 rD d } n X| d k	 rz t j |  d pg d } t	 | d | St	 d d d S(	   s0   Return a static resource from the shared folder.t   sharedi    s   application/octet-streamR   s	   Not Foundt   statusi  N(
   R   R   t   pkgutilt   get_datat   __package__R*   R(   t	   mimetypest
   guess_typeR   (   RE   R   R6   t   dataR   (    (    so   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/debug/__init__.pyt   get_resourceu  s    
c         C   s   |  j  d k r t St |  j |  j  } | s> d | k rB t S| j d d  \ } } | j   sj t S| t	 |  j   k r d St
 j
   t t |  k  S(   s!  Checks if the request passed the pin test.  This returns `True` if the
        request is trusted on a pin/cookie basis and returns `False` if not.
        Additionally if the cookie's stored pin hash is wrong it will return
        `None` so that appropriate action can be taken.
        t   |i   N(   R   R(   R   R   RZ   R   t   Falset   splitR[   R   t   timet   PIN_TIMERg   (   RE   RY   t   valt   tst   pin_hash(    (    so   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/debug/__init__.pyR     s    c         C   s5   t  j |  j d k r d n d  |  j d 7_ d  S(   Ni   g      @g      ?i   (   R   t   sleepR   (   RE   (    (    so   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/debug/__init__.pyt   _fail_pin_auth  s    "c         C   sL  t  } t  } |  j | j  } t  } | d k rC |  j   t } n | rR t } ns |  j d k rj t } n[ | j j d  } | j	   j
 d d  |  j j
 d d  k r d |  _ t } n
 |  j   t t j i | d 6| d 6 d d	 } | r/| j |  j d
 t t j    t |  j  f d t n | rH| j |  j  n  | S(   s   Authenticates with the pin.i
   R   RM   R   i    t   autht	   exhaustedR   s   application/jsons   %s|%st   httponlyN(   R   R   RY   R(   R   R   R   t   argsRZ   R!   R   R   R   R   R   t
   set_cookieR   Rg   R   R   t   delete_cookie(   RE   R   R   R   t   trustt
   bad_cookiet   entered_pinRk   (    (    so   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/debug/__init__.pyt   pin_auth  s6    
			-		
	%
c         C   sF   |  j  r< |  j d k	 r< t d d  t d d |  j  n  t d  S(   s   Log the pin if needed.Ry   s=    * To enable the debugger you need to enter the security pin:s    * Debugger pin code: %sR   N(   R   R   R(   R   R   (   RE   (    (    so   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/debug/__init__.pyt   log_pin_request  s
    
c   
      C   s  t  |  } |  j } | j j d  d k r| j j d  } | j j d  } | j j d  } |  j j | j j d d t  } |  j j | j j d d t  }	 | d	 k r | r |  j | |  } q| d
 k r| d k	 r| |  j	 k r|  j
 | |  } q| d k r;| |  j	 k r;|  j |  } q| d k re| |  j	 k re|  j   } q|  j r| d k	 r|	 d k	 r|  j	 | k r|  j |  r|  j | | |	  } qn< |  j r|  j d k	 r| j |  j k r|  j |  } n  | | |  S(   s   Dispatch the requests.t   __debugger__t   yest   cmdR7   t   st   tbt   typet   frmt   resourceR   t   pinautht   printpinN(   t   RequestR   R   RZ   R|   Rg   R{   R   R(   R   R   R   R   Rz   R   R   R~   t   pathR   (
   RE   RY   R   R   t   responseR   t   argR   R   R   (    (    so   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/debug/__init__.pyt   __call__  s6    	$$'		N(   RH   RI   RJ   R   R(   R   RG   t   propertyR   t   setterR   R   R   R   R   R   R   R   R   R   R   (    (    (    so   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/debug/__init__.pyRu      s*   	1							/		i  iQ i:	 (+   RJ   R^   R   R   R   RX   R   R&   Ra   R   Rd   t	   itertoolsR    t   os.pathR   R   t   _compatR   t	   _internalR   t   httpR   t   securityR   t   wrappersR   R   R   R   RC   R	   t   tbtoolsR
   R   R   R   R(   R@   RA   t   objectRB   Rt   Ru   (    (    (    so   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/debug/__init__.pyt   <module>
   s:   		O
	S