ó
³Ebc           @   s^  d  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 y d d
 l m Z Wn! e k
 r­ d d
 l m Z n Xd e f d „  ƒ  YZ d e f d „  ƒ  YZ d d „ Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ e d e f d „  ƒ  Yƒ Z d e f d „  ƒ  YZ d S(   s‹  
WSGI Protocol Linter
====================

This module provides a middleware that performs sanity checks on the
behavior of the WSGI server and application. It checks that the
:pep:`3333` WSGI spec is properly implemented. It also warns on some
common HTTP errors such as non-empty responses for 304 status codes.

.. autoclass:: LintMiddleware

:copyright: 2007 Pallets
:license: BSD-3-Clause
iÿÿÿÿ(   t   warni   (   t   implements_iterator(   t   PY2(   t   string_types(   t   Headers(   t   is_entity_header(   t   FileWrapper(   t   urlparset   WSGIWarningc           B   s   e  Z d  Z RS(   s    Warning class for WSGI warnings.(   t   __name__t
   __module__t   __doc__(    (    (    sp   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/lint.pyR      s   t   HTTPWarningc           B   s   e  Z d  Z RS(   s    Warning class for HTTP warnings.(   R	   R
   R   (    (    (    sp   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/lint.pyR   "   s   i   c         C   s9   t  | ƒ t k	 r5 t d |  t  | ƒ j f t ƒ n  d  S(   Ns   '%s' requires strings, got '%s'(   t   typet   strR    R	   R   (   t   contextt   objt
   stacklevel(    (    sp   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/lint.pyt   check_string&   s    t   InputStreamc           B   s5   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s   | |  _  d  S(   N(   t   _stream(   t   selft   stream(    (    sp   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/lint.pyt   __init__/   s    c         G   s`   t  | ƒ d k r( t d t d d ƒn( t  | ƒ d k rP t d t d d ƒn  |  j j | Œ  S(   Ni    sŸ   WSGI does not guarantee an EOF marker on the input stream, thus making calls to 'wsgi.input.read()' unsafe. Conforming servers may never return from this call.R   i   i   s2   Too many parameters passed to 'wsgi.input.read()'.(   t   lenR    R   R   t   read(   R   t   args(    (    sp   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/lint.pyR   2   s    

c         G   sl   t  | ƒ d k r( t d t d d ƒn4 t  | ƒ d k rP t d t d d ƒn t d ƒ ‚ |  j j | Œ  S(   Ni    s_   Calls to 'wsgi.input.readline()' without arguments are unsafe. Use 'wsgi.input.read()' instead.R   i   i   s~   'wsgi.input.readline()' was called with a size hint. WSGI does not support this, although it's available on all major servers.s5   Too many arguments passed to 'wsgi.input.readline()'.(   R   R    R   t	   TypeErrorR   t   readline(   R   R   (    (    sp   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/lint.pyR   C   s    

c         C   sC   y t  |  j ƒ SWn+ t k
 r> t d t d d ƒt  d ƒ SXd  S(   Ns   'wsgi.input' is not iterable.R   i   (    (   t   iterR   R   R    R   (   R   (    (    sp   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/lint.pyt   __iter__V   s
    c         C   s$   t  d t d d ƒ|  j j ƒ  d  S(   Ns(   The application closed the input stream!R   i   (   R    R   R   t   close(   R   (    (    sp   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/lint.pyR   ]   s    (   R	   R
   R   R   R   R   R   (    (    (    sp   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/lint.pyR   .   s
   				t   ErrorStreamc           B   s5   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s   | |  _  d  S(   N(   R   (   R   R   (    (    sp   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/lint.pyR   c   s    c         C   s!   t  d | ƒ |  j j | ƒ d  S(   Ns   wsgi.error.write()(   R   R   t   write(   R   t   s(    (    sp   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/lint.pyR!   f   s    c         C   s   |  j  j ƒ  d  S(   N(   R   t   flush(   R   (    (    sp   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/lint.pyR#   j   s    c         C   s"   x | D] } |  j  | ƒ q Wd  S(   N(   R!   (   R   t   seqt   line(    (    sp   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/lint.pyt
   writelinesm   s    c         C   s$   t  d t d d ƒ|  j j ƒ  d  S(   Ns(   The application closed the error stream!R   i   (   R    R   R   R   (   R   (    (    sp   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/lint.pyR   q   s    (   R	   R
   R   R!   R#   R&   R   (    (    (    sp   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/lint.pyR    b   s
   				t   GuardedWritec           B   s   e  Z d  „  Z d „  Z RS(   c         C   s   | |  _  | |  _ d  S(   N(   t   _writet   _chunks(   R   R!   t   chunks(    (    sp   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/lint.pyR   w   s    	c         C   s7   t  d | ƒ |  j j | ƒ |  j j t | ƒ ƒ d  S(   Ns   write()(   R   R(   R!   R)   t   appendR   (   R   R"   (    (    sp   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/lint.pyt   __call__{   s    (   R	   R
   R   R,   (    (    (    sp   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/lint.pyR'   v   s   	t   GuardedIteratorc           B   s5   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   sU   | |  _  t r$ t | ƒ j |  _ n t | ƒ j |  _ t |  _ | |  _ | |  _	 d  S(   N(
   t	   _iteratorR   R   t   nextt   _nextt   __next__t   Falset   closedt   headers_setR*   (   R   t   iteratorR4   R*   (    (    sp   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/lint.pyR   ƒ   s    			c         C   s   |  S(   N(    (   R   (    (    sp   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/lint.pyR      s    c         C   sq   |  j  r t d t d d ƒn  |  j ƒ  } |  j sJ t d t d d ƒn  t d | ƒ |  j j t | ƒ ƒ | S(   Ns    Iterated over closed 'app_iter'.R   i   s8   The application returned before it started the response.s   application iterator items(	   R3   R    R   R0   R4   R   R*   R+   R   (   R   t   rv(    (    sp   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/lint.pyR1      s    		
c         C   so  t  |  _ t |  j d ƒ r+ |  j j ƒ  n  |  j rk|  j \ } } t |  j ƒ } | j d d t	 ƒ} | d k rÛ xL | D]D \ } } | j
 ƒ  } | d k rz t | ƒ rz t d | t ƒ qz qz W| rht d t ƒ qhqkd	 | k oò d
 k  n s| d k r@| d k r#t d | t ƒ n  | rht d | t ƒ qhqk| d  k	 rk| | k rkt d t ƒ qkn  d  S(   NR   s   content-lengthR   i0  t   expiress   content-locations'   Entity header %r found in 304 response.s#   304 responses must not have a body.id   iÈ   iÌ   i    s/   %r responses must have an empty content length.s"   %r responses must not have a body.sG   Content-Length and the number of bytes sent to the client do not match.(   R7   s   content-location(   t   TrueR3   t   hasattrR.   R   R4   t   sumR*   t   gett   intt   lowerR   R    R   t   NoneR   (   R   t   status_codet   headerst
   bytes_sentt   content_lengtht   keyt   _value(    (    sp   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/lint.pyR   ¡   s8    			(
c         C   s5   |  j  s1 y t d t ƒ Wq1 t k
 r- q1 Xn  d  S(   Ns4   Iterator was garbage collected before it was closed.(   R3   R    R   t	   Exception(   R   (    (    sp   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/lint.pyt   __del__È   s    	(   R	   R
   R   R   R1   R   RF   (    (    (    sp   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/lint.pyR-      s
   	
			't   LintMiddlewarec           B   sD   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s¡  Warns about common errors in the WSGI and HTTP behavior of the
    server and wrapped application. Some of the issues it check are:

    -   invalid status codes
    -   non-bytestrings sent to the WSGI server
    -   strings returned from the WSGI application
    -   non-empty conditional responses
    -   unquoted etags
    -   relative URLs in the Location header
    -   unsafe calls to wsgi.input
    -   unclosed iterators

    Error information is emitted using the :mod:`warnings` module.

    :param app: The WSGI application to wrap.

    .. code-block:: python

        from werkzeug.middleware.lint import LintMiddleware
        app = LintMiddleware(app)
    c         C   s   | |  _  d  S(   N(   t   app(   R   RH   (    (    sp   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/lint.pyR   é   s    c      	   C   s  t  | ƒ t k	 r( t d t d d ƒn  x4 d D], } | | k r/ t d | t d d ƒq/ q/ W| d d k r… t d t d d ƒn  | j d d ƒ } | j d d ƒ } | rÙ | d d k rÙ t d | t d d ƒn  | r	| d d k r	t d | t d d ƒn  d  S(   Ns/   WSGI environment is not a standard Python dict.R   i   t   REQUEST_METHODt   SERVER_NAMEt   SERVER_PORTs   wsgi.versions
   wsgi.inputs   wsgi.errorss   wsgi.multithreads   wsgi.multiprocesss   wsgi.run_onces%   Required environment key %r not foundi   i   i    s"   Environ is not a WSGI 1.0 environ.t   SCRIPT_NAMEt    t	   PATH_INFOt   /s-   'SCRIPT_NAME' does not start with a slash: %rs+   'PATH_INFO' does not start with a slash: %r(	   RI   RJ   RK   s   wsgi.versions
   wsgi.inputs   wsgi.errorss   wsgi.multithreads   wsgi.multiprocesss   wsgi.run_once(   i   i    (   R   t   dictR    R   R;   (   R   t   environRC   t   script_namet	   path_info(    (    sp   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/lint.pyt   check_environì   sD    
        

c         C   s  t  d | ƒ | j d  d ƒ d } t | ƒ d k sB | j ƒ  r[ t t d ƒ d d ƒn  t | ƒ d k  s} | d d k r– t t d	 ƒ d d ƒn  t | ƒ } | d
 k  rÇ t t d ƒ d d ƒn  t | ƒ t	 k	 rò t t d ƒ d d ƒn  x¿ | D]· } t | ƒ t
 k	 s#t | ƒ d k r<t t d ƒ d d ƒn  | \ } } t | ƒ t k	 slt | ƒ t k	 r…t t d ƒ d d ƒn  | j ƒ  d k rù t t d ƒ d d ƒqù qù W| d  k	 rét | t
 ƒ rét t d ƒ d d ƒn  t | ƒ } |  j | ƒ | | f S(   Nt   statusi   i    i   s    Status code must be three digitsR   i   t    se   Invalid value for status %r.  Valid status strings are three digits, a space and a status explanationid   s   status code < 100 detecteds   header list is not a listi   s    Headers must tuple 2-item tupless   header items must be stringssF   The status header is not supported due to conflicts with the CGI spec.s   invalid value for exc_info(   R   t   splitR>   R   t   isdigitR    R   R<   R   t   listt   tupleR   R=   t
   isinstanceR   t   check_headers(   R   RU   R@   t   exc_infoR?   t   itemt   namet   value(    (    sp   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/lint.pyt   check_start_response  s<    "	
$$	c         C   sé   | j  d ƒ } | d  k	 rŸ | j d ƒ r_ | j d ƒ rR t t d ƒ d d ƒn  | d } n  | d  | d	 k o~ d
 k n sŸ t t d ƒ d d ƒqŸ n  | j  d ƒ } | d  k	 rå t | ƒ j så t t d ƒ d d ƒqå n  d  S(   Nt   etags   W/s   w/s%   weak etag indicator should be upcase.R   i   i   i   iÿÿÿÿt   "s   unquoted etag emitted.t   locations*   absolute URLs required for location header(   s   W/s   w/(   R;   R>   t
   startswithR    R   R   t   netloc(   R   R@   Rb   Rd   (    (    sp   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/lint.pyR\   H  s     
$c         C   s)   t  | t ƒ r% t d t d d ƒn  d  S(   NsŸ   The application returned astring. The response will send one character at a time to the client, which will kill performance. Return a list or iterable instead.R   i   (   R[   R   R    R   (   R   t   app_iter(    (    sp   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/lint.pyt   check_iteratora  s
    c            sâ   t  | ƒ d k r( t d t d d ƒn  | rD t d t d d ƒn  | \ } ‰ ˆ j | ƒ t | d ƒ | d <t | d ƒ | d <t | d <g  ‰ g  ‰  ‡  ‡ ‡ ‡ f d †  } ˆ j | | ƒ } ˆ j | ƒ t	 | ˆ ˆ  ƒ S(	   Ni   s   A WSGI app takes two arguments.R   s+   A WSGI app does not take keyword arguments.s
   wsgi.inputs   wsgi.errorss   wsgi.file_wrapperc             s¬   t  |  ƒ d k r2 t d t  |  ƒ t d d ƒn  | rH t d t ƒ n  |  d  \ } } t  |  ƒ d k rw |  d } n d  } ˆ j | | | ƒ ˆ (t ˆ | | | ƒ ˆ  ƒ S(   Ni   i   s1   Invalid number of arguments: %s, expected 2 or 3.R   s1   'start_response' does not take keyword arguments.(   i   i   (   R   R    R   R>   Ra   R'   (   R   t   kwargsRU   R@   R]   (   R*   R4   R   t   start_response(    sp   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/lint.pyt   checking_start_response  s    
(
   R   R    R   RT   R   R    R   RH   Rh   R-   (   R   R   Ri   RQ   Rk   Rg   (    (   R*   R4   R   Rj   sp   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/lint.pyR,   k  s     
(	   R	   R
   R   R   RT   Ra   R\   Rh   R,   (    (    (    sp   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/lint.pyRG   Ò   s   		,	0		
N(   R   t   warningsR    t   _compatR   R   R   t   datastructuresR   t   httpR   t   wsgiR   t   urllib.parseR   t   ImportErrort   WarningR   R   R   t   objectR   R    R'   R-   RG   (    (    (    sp   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/werkzeug/middleware/lint.pyt   <module>   s(   4P