ó
è¾bc           @   s»   d  Z  d d l Z d d d d d d g Z d d d	 „  ƒ  YZ d
 „  Z d „  Z d d „ Z d „  Z d „  Z i d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6j	 Z
 d „  Z d S(   s$   Miscellaneous WSGI-related UtilitiesiÿÿÿÿNt   FileWrappert   guess_schemet   application_urit   request_urit   shift_path_infot   setup_testing_defaultsc           B   s5   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z RS(   s1   Wrapper to convert file-like objects to iterablesi    c         C   s4   | |  _  | |  _ t | d ƒ r0 | j |  _ n  d  S(   Nt   close(   t   fileliket   blksizet   hasattrR   (   t   selfR   R   (    (    s"   /usr/lib/python2.7/wsgiref/util.pyt   __init__   s    		c         C   s)   |  j  j |  j ƒ } | r | St ‚ d  S(   N(   R   t   readR   t
   IndexError(   R
   t   keyt   data(    (    s"   /usr/lib/python2.7/wsgiref/util.pyt   __getitem__   s    c         C   s   |  S(   N(    (   R
   (    (    s"   /usr/lib/python2.7/wsgiref/util.pyt   __iter__   s    c         C   s)   |  j  j |  j ƒ } | r | St ‚ d  S(   N(   R   R   R   t   StopIteration(   R
   R   (    (    s"   /usr/lib/python2.7/wsgiref/util.pyt   next   s    (   t   __name__t
   __module__t   __doc__R   R   R   R   (    (    (    s"   /usr/lib/python2.7/wsgiref/util.pyR       s
   		c         C   s!   |  j  d ƒ d k r d Sd Sd S(	   sM   Return a guess for whether 'wsgi.url_scheme' should be 'http' or 'https'
    t   HTTPSt   yest   ont   1t   httpst   httpN(   R   R   R   (   t   get(   t   environ(    (    s"   /usr/lib/python2.7/wsgiref/util.pyR   #   s    c         C   sÌ   |  d d } d d l  m } |  j d ƒ r> | |  d 7} nk | |  d 7} |  d d k r„ |  d d	 k r© | d
 |  d 7} q© n% |  d d k r© | d
 |  d 7} n  | | |  j d ƒ pÁ d ƒ 7} | S(   s@   Return the application's base URI (no PATH_INFO or QUERY_STRING)s   wsgi.url_schemes   ://iÿÿÿÿ(   t   quotet	   HTTP_HOSTt   SERVER_NAMER   t   SERVER_PORTt   443t   :t   80t   SCRIPT_NAMEt   /(   t   urllibR   R   (   R   t   urlR   (    (    s"   /usr/lib/python2.7/wsgiref/util.pyR   +   s    i   c         C   s’   t  |  ƒ } d d l m } | |  j d d ƒ d d ƒ} |  j d ƒ sZ | | d 7} n
 | | 7} | rŽ |  j d	 ƒ rŽ | d
 |  d	 7} n  | S(   sB   Return the full request URI, optionally including the query stringiÿÿÿÿ(   R   t	   PATH_INFOt    t   safes   /;=,R&   i   t   QUERY_STRINGt   ?(   R   R(   R   R   (   R   t   include_queryR)   R   t	   path_info(    (    s"   /usr/lib/python2.7/wsgiref/util.pyR   ?   s    
c         C   s  |  j  d d ƒ } | s d S| j d ƒ } g  | d d !D] } | r9 | d k r9 | ^ q9 | d d +| d } | d =|  j  d d ƒ } t j | d | ƒ } | j d ƒ rº | d  } n  | rÞ | j d ƒ rÞ | d 7} n  | |  d <d j | ƒ |  d <| d k rd } n  | S(	   sZ  Shift a name from PATH_INFO to SCRIPT_NAME, returning it

    If there are no remaining path segments in PATH_INFO, return None.
    Note: 'environ' is modified in-place; use a copy if you need to keep
    the original PATH_INFO or SCRIPT_NAME.

    Note: when PATH_INFO is just a '/', this returns '' and appends a trailing
    '/' to SCRIPT_NAME, even though empty path segments are normally ignored,
    and SCRIPT_NAME doesn't normally end in a '/'.  This is intentional
    behavior, to ensure that an application can tell the difference between
    '/x' and '/x/' when traversing to objects.
    R*   R+   R'   i   iÿÿÿÿt   .R&   N(   R   t   Nonet   splitt	   posixpatht   normpatht   endswitht   join(   R   R0   t
   path_partst   pt   namet   script_name(    (    s"   /usr/lib/python2.7/wsgiref/util.pyR   L   s$    9

	c         C   sX  |  j  d d ƒ |  j  d d ƒ |  j  d |  d ƒ |  j  d d ƒ d |  k r d	 |  k r |  j  d d
 ƒ |  j  d	 d ƒ n  |  j  d d ƒ |  j  d d ƒ |  j  d d ƒ |  j  d d ƒ d d l m } |  j  d | d
 ƒ ƒ |  j  d | ƒ  ƒ |  j  d t |  ƒ ƒ |  d d k r1|  j  d d ƒ n# |  d d k rT|  j  d d ƒ n  d S(   s:  Update 'environ' with trivial defaults for testing purposes

    This adds various parameters required for WSGI, including HTTP_HOST,
    SERVER_NAME, SERVER_PORT, REQUEST_METHOD, SCRIPT_NAME, PATH_INFO,
    and all of the wsgi.* variables.  It only supplies default values,
    and does not replace any existing settings for these variables.

    This routine is intended to make it easier for unit tests of WSGI
    servers and applications to set up dummy environments.  It should *not*
    be used by actual WSGI servers or applications, since the data is fake!
    R!   s	   127.0.0.1t   SERVER_PROTOCOLs   HTTP/1.0R    t   REQUEST_METHODt   GETR&   R*   R+   R'   s   wsgi.versioni   i    s   wsgi.run_onces   wsgi.multithreads   wsgi.multiprocessiÿÿÿÿ(   t   StringIOs
   wsgi.inputs   wsgi.errorss   wsgi.url_schemeR   R"   R%   R   R#   N(   i   i    (   t
   setdefaultR?   R   (   R   R?   (    (    s"   /usr/lib/python2.7/wsgiref/util.pyR   u   s&    t
   connections
   keep-alives   proxy-authenticates   proxy-authorizationt   tet   trailerss   transfer-encodingt   upgradec         C   s   t  |  j ƒ  ƒ S(   s?   Return true if 'header_name' is an HTTP/1.1 "Hop-by-Hop" header(   t   _hoppisht   lower(   t   header_name(    (    s"   /usr/lib/python2.7/wsgiref/util.pyt   is_hop_by_hop£   s    (    (   R   R4   t   __all__R    R   R   R   R   R   t   __contains__RE   RH   (    (    (    s"   /usr/lib/python2.7/wsgiref/util.pyt   <module>   s   			)	(