
bc           @   s  d  Z  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	 m
 Z
 m Z e
   I e j r e	 d d e  e	 d d e  n  d d l Z d d l Z Wd QXy d d	 l m Z Wn! e k
 r d d	 l m Z n Xd
 d d d d d d d d d d d d d d d d d g Z d Z e a d   Z d   Z d   Z e a d  a e e j d  d  d!  Z d  d  d"  Z d  d  e d#  Z d$   Z  d%   Z! d&   Z" d
 f  d'     YZ# d f  d(     YZ$ d e j f d)     YZ% d e% f d*     YZ& d e& f d+     YZ' d e% f d,     YZ( e j d-  Z) e e e e d.  Z* e j d/  Z+ d0   Z, d1   Z- d2   Z. d3   Z/ e d4  Z0 d5 d6  Z1 e2 d7 k re)   n  d S(8   s   Support module for CGI (Common Gateway Interface) scripts.

This module defines a number of utilities for use by CGI scripts
written in Python.
s   2.6i(   t
   attrgetterN(   t   filterwarningst   catch_warningst   warnt   ignores   .*mimetools has been removeds   .*rfc822 has been removed(   t   StringIOt   MiniFieldStoraget   FieldStoraget   FormContentDictt   SvFormContentDictt   InterpFormContentDictt   FormContentt   parset   parse_qst	   parse_qslt   parse_multipartt   parse_headert   print_exceptiont   print_environt
   print_formt   print_directoryt   print_argumentst   print_environ_usaget   escapet    c          G   sZ   t  r7 t r7 y t t  d  a Wq7 t k
 r3 q7 Xn  t sF t a n t a t |    d S(   s  Write a log message, if there is a log file.

    Even though this function is called initlog(), you should always
    use log(); log is a variable that is set either to initlog
    (initially), to dolog (once the log file has been opened), or to
    nolog (when logging is disabled).

    The first argument is a format string; the remaining arguments (if
    any) are arguments to the % operator, so e.g.
        log("%s: %s", "a", "b")
    will write "a: b" to the log file, followed by a newline.

    If the global logfp is not None, it should be a file object to
    which log data is written.

    If the global logfp is None, the global logfile may be a string
    giving a filename to open, in append mode.  This file should be
    world writable!!!  If the file can't be opened, logging is
    silently disabled (since there is no safe place where we could
    send an error message).

    t   aN(   t   logfilet   logfpt   opent   IOErrort   nologt   logt   dolog(   t   allargs(    (    s   /usr/lib/python2.7/cgi.pyt   initlogG   s    	c         G   s   t  j |  | d  d S(   s=   Write a log message to the log file.  See initlog() for docs.s   
N(   R   t   write(   t   fmtt   args(    (    s   /usr/lib/python2.7/cgi.pyR    j   s    c          G   s   d S(   s9   Dummy function, assigned to log when logging is disabled.N(    (   R!   (    (    s   /usr/lib/python2.7/cgi.pyR   n   s    i    c         C   s  |  d k r t j }  n  d | k r1 d | d <n  | d d k r3t | d  \ } } | d k rp t |  |  S| d k r t | d  } t r | t k r t d  n  |  j |  } n d	 } d
 | k r | r | d } n  | | d
 } n4 t j	 d r&| r| d } n  | t j	 d } n  | | d
 <nF d
 | k rL| d
 } n- t j	 d rit j	 d } n d	 } | | d
 <t
 j | | |  S(   s   Parse a query in the environment or from a file (default stdin)

        Arguments, all optional:

        fp              : file pointer; default: sys.stdin

        environ         : environment dictionary; default: os.environ

        keep_blank_values: flag indicating whether blank values in
            percent-encoded forms should be treated as blank strings.
            A true value indicates that blanks should be retained as
            blank strings.  The default false value indicates that
            blank values are to be ignored and treated as if they were
            not included.

        strict_parsing: flag indicating what to do with parsing errors.
            If false (the default), errors are silently ignored.
            If true, errors raise a ValueError exception.
    t   REQUEST_METHODt   GETt   POSTt   CONTENT_TYPEs   multipart/form-datas!   application/x-www-form-urlencodedt   CONTENT_LENGTHs   Maximum content length exceededR   t   QUERY_STRINGt   &i   N(   t   Nonet   syst   stdinR   R   t   intt   maxlent
   ValueErrort   readt   argvt   urlparseR   (   t   fpt   environt   keep_blank_valuest   strict_parsingt   ctypet   pdictt   clengtht   qs(    (    s   /usr/lib/python2.7/cgi.pyR   |   s<      
c         C   s#   t  d t d  t j |  | |  S(   s)   Parse a query given as a string argument.s9   cgi.parse_qs is deprecated, use urlparse.parse_qs insteadi   (   R   t   PendingDeprecationWarningR5   R   (   R=   R8   R9   (    (    s   /usr/lib/python2.7/cgi.pyR      s    
c         C   s&   t  d t d  t j |  | | |  S(   s)   Parse a query given as a string argument.s;   cgi.parse_qsl is deprecated, use urlparse.parse_qsl insteadi   (   R   R>   R5   R   (   R=   R8   R9   t   max_num_fields(    (    s   /usr/lib/python2.7/cgi.pyR      s    
c         C   s  d } d | k r | d } n  t  |  s> t d | f  n  d | } d | d } i  } d } x'| | k rd } d } | rt j |   }	 |	 j d  }
 |
 r y t |
  } Wq t k
 r q Xn  | d k r
t r | t k r t d  n  |  j |  } qd } n  g  } xb |  j	   } | s8| } Pn  | d	  d k rm| j
   } | | | f k rmPqmn  | j |  qW| d k rqe n  | d k  r| r| d } | d
 d k r| d
  } n | d d k r| d  } n  | | d <d j |  } qn  |	 d } | sqe n  t |  \ } } | d k r?qe n  d | k re | d } n qe | | k r{| | j |  qe | g | | <qe W| S(   s  Parse multipart input.

    Arguments:
    fp   : input file
    pdict: dictionary containing other parameters of content-type header

    Returns a dictionary just like parse_qs(): keys are the field names, each
    value is a list of values for that field.  This is easy to use but not
    much good if you are expecting megabytes to be uploaded -- in that case,
    use the FieldStorage class instead which is much more flexible.  Note
    that content-type is the raw, unparsed contents of the content-type
    header.

    XXX This does not parse nested multipart parts -- use FieldStorage for
    that.

    XXX This should really be subsumed by FieldStorage altogether -- no
    point in having two implementations of the same parsing algorithm.
    Also, FieldStorage protects itself better against certain DoS attacks
    by limiting the size of the data read in one chunk.  The API here
    does not support that kind of protection.  This also affects parse()
    since it can call parse_multipart().

    R   t   boundarys&   Invalid boundary in multipart form: %rs   --is   content-lengthi    s   Maximum content length exceededi   is   
s   
s   content-dispositions	   form-datat   nameN(   t   valid_boundaryR2   R-   t	   mimetoolst   Messaget	   getheaderR0   R1   R3   t   readlinet   stript   appendt   joinR   (   R6   R;   R@   t   nextpartt   lastpartt   partdictt
   terminatort   bytest   datat   headersR<   t   linest   linet   keyt   paramsRA   (    (    s   /usr/lib/python2.7/cgi.pyR      sz    
	


c         c   s   x |  d  d k r |  d }  |  j  d  } xR | d k r |  j d d |  |  j d d |  d r |  j  d | d  } q/ W| d k  r t |   } n  |  |  } | j   V|  | }  q Wd  S(   Ni   t   ;i    t   "s   \"i   (   t   findt   countt   lenRG   (   t   st   endt   f(    (    s   /usr/lib/python2.7/cgi.pyt   _parseparam$  s    
;
c         C   s   t  d |   } | j   } i  } x | D] } | j d  } | d k r) | |  j   j   } | | d j   } t |  d k r | d | d k o d k n r | d d !} | j d d	  j d
 d  } n  | | | <q) q) W| | f S(   sf   Parse a Content-type like header.

    Return the main content-type and a dictionary of options.

    RU   t   =i    i   i   iRV   s   \\s   \s   \"(   R]   t   nextRW   RG   t   lowerRY   t   replace(   RR   t   partsRS   R;   t   pt   iRA   t   value(    (    s   /usr/lib/python2.7/cgi.pyR   0  s    6!c           B   sP   e  Z d  Z d Z d Z d Z d Z i  Z d Z	 i  Z
 i  Z d   Z d   Z RS(   s=   Like FieldStorage, for use when no file uploads are possible.c         C   s   | |  _  | |  _ d S(   s&   Constructor from field name and value.N(   RA   Re   (   t   selfRA   Re   (    (    s   /usr/lib/python2.7/cgi.pyt   __init__V  s    	c         C   s   d |  j  |  j f S(   s    Return printable representation.s   MiniFieldStorage(%r, %r)(   RA   Re   (   Rf   (    (    s   /usr/lib/python2.7/cgi.pyt   __repr__\  s    N(   t   __name__t
   __module__t   __doc__R-   t   filenamet   listt   typet   filet   type_optionst   dispositiont   disposition_optionsRP   Rg   Rh   (    (    (    s   /usr/lib/python2.7/cgi.pyR   H  s   	c           B   s
  e  Z d  Z d d d e j d d d d  Z d   Z d   Z d   Z	 d   Z
 d d  Z d d	  Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d Z d   Z d   Z d Z d   Z d   Z d   Z d   Z d   Z d   Z d d  Z RS(   s  Store a sequence of fields, reading multipart/form-data.

    This class provides naming, typing, files stored on disk, and
    more.  At the top level, it is accessible like a dictionary, whose
    keys are the field names.  (Note: None can occur as a field name.)
    The items are either a Python list (if there's multiple values) or
    another FieldStorage or MiniFieldStorage object.  If it's a single
    object, it has the following attributes:

    name: the field name, if specified; otherwise None

    filename: the filename, if specified; otherwise None; this is the
        client side filename, *not* the file name on which it is
        stored (that's a temporary file you don't deal with)

    value: the value as a *string*; for file uploads, this
        transparently reads the file every time you request the value

    file: the file(-like) object from which you can read the data;
        None if the data is stored a simple string

    type: the content-type, or None if not specified

    type_options: dictionary of options specified on the content-type
        line

    disposition: content-disposition, or None if not specified

    disposition_options: dictionary of corresponding options

    headers: a dictionary(-like) object (sometimes rfc822.Message or a
        subclass thereof) containing *all* headers

    The class is subclassable, mostly for the purpose of overriding
    the make_file() method, which is called internally to come up with
    a file open for reading and writing.  This makes it possible to
    override the default choice of storing all files in a temporary
    directory and unlinking them as soon as they have been opened.

    R   i    c         C   sh  d } | |  _  | |  _ | |  _ d | k r@ | d j   } n  d |  _ | d k sa | d k r d | k rz | d }	 n# t j d r t j d }	 n d }	 t |	  } | d k r i d d 6} q n  | d k rLi  } | d	 k r d | d <n  d
 | k r| d
 | d <n  d | k r,| d |  _ n  d | k rL| d | d <qLn  | pXt j	 |  _
 | |  _ | |  _ d i  }
 } d |  j k rt |  j d  \ }
 } n  |
 |  _ | |  _ d |  _ d | k r| d |  _ n  d |  _ d | k r| d |  _ n  d |  j k r/t |  j d  \ } } n2 |  j sD| d	 k rTd i  } } n d i  } } | |  _ | |  _ d |  _ d | k r| d |  _ n  d } d |  j k ry t |  j d  } Wn t k
 rn Xt r| t k rt d  qn  | |  _ d |  _ |  _ d |  _ | d k r4|  j   n0 | d  d k rZ|  j | | |  n
 |  j   d S(   s  Constructor.  Read multipart/* until last part.

        Arguments, all optional:

        fp              : file pointer; default: sys.stdin
            (not used when the request method is GET)

        headers         : header dictionary-like object; default:
            taken from environ as per CGI spec

        outerboundary   : terminating multipart boundary
            (for internal use only)

        environ         : environment dictionary; default: os.environ

        keep_blank_values: flag indicating whether blank values in
            percent-encoded forms should be treated as blank strings.
            A true value indicates that blanks should be retained as
            blank strings.  The default false value indicates that
            blank values are to be ignored and treated as if they were
            not included.

        strict_parsing: flag indicating what to do with parsing errors.
            If false (the default), errors are silently ignored.
            If true, errors raise a ValueError exception.

        max_num_fields: int. If set, then __init__ throws a ValueError
            if there are more than n fields read by parse_qsl().

        R'   R&   t   HEADR+   i   R   s!   application/x-www-form-urlencodeds   content-typeR(   R)   R*   s   content-lengths   content-dispositionRA   Rl   s
   text/plainR@   is   Maximum content length exceededi    i
   s
   multipart/N(   R8   R9   R?   t   upperR-   t
   qs_on_postR.   R4   R   R/   R6   RP   t   outerboundaryR   Rq   Rr   RA   Rl   Rn   Rp   t   innerboundaryR0   R2   R1   t   lengthRm   Ro   t   donet   read_urlencodedt
   read_multit   read_single(   Rf   R6   RP   Rv   R7   R8   R9   R?   t   methodR=   t   cdispR;   R:   t   clen(    (    s   /usr/lib/python2.7/cgi.pyRg     s    !															c         C   s   d |  j  |  j |  j f S(   s"   Return a printable representation.s   FieldStorage(%r, %r, %r)(   RA   Rl   Re   (   Rf   (    (    s   /usr/lib/python2.7/cgi.pyRh     s    c         C   s   t  |  j    S(   N(   t   itert   keys(   Rf   (    (    s   /usr/lib/python2.7/cgi.pyt   __iter__
  s    c         C   sx   | d k r t  |  n  |  j rS |  j j d  |  j j   } |  j j d  n! |  j d  k	 rn |  j } n d  } | S(   NRe   i    (   t   AttributeErrorRo   t   seekR3   Rm   R-   (   Rf   RA   Re   (    (    s   /usr/lib/python2.7/cgi.pyt   __getattr__  s    	c         C   s   |  j  d k r t d  n  g  } x0 |  j  D]% } | j | k r+ | j |  q+ q+ W| sf t |  n  t |  d k r | d S| Sd S(   s   Dictionary style indexing.s   not indexablei   i    N(   Rm   R-   t	   TypeErrorRA   RH   t   KeyErrorRY   (   Rf   RS   t   foundt   item(    (    s   /usr/lib/python2.7/cgi.pyt   __getitem__  s     c         C   sS   | |  k rK |  | } t  |  t  g   k rA t t d  |  S| j Sn | Sd S(   s8   Dictionary style get() method, including 'value' lookup.Re   N(   Rn   t   mapR    Re   (   Rf   RS   t   defaultRe   (    (    s   /usr/lib/python2.7/cgi.pyt   getvalue(  s    

c         C   sK   | |  k rC |  | } t  |  t  g   k r9 | d j S| j Sn | Sd S(   s!    Return the first value received.i    N(   Rn   Re   (   Rf   RS   R   Re   (    (    s   /usr/lib/python2.7/cgi.pyt   getfirst3  s    

c         C   sV   | |  k rN |  | } t  |  t  g   k rA t t d  |  S| j g Sn g  Sd S(   s     Return list of received values.Re   N(   Rn   R   R    Re   (   Rf   RS   Re   (    (    s   /usr/lib/python2.7/cgi.pyt   getlist>  s    
c         C   s8   |  j  d k r t d  n  t  t d   |  j  D   S(   s   Dictionary style keys() method.s   not indexablec         s   s   |  ] } | j  Vq d  S(   N(   RA   (   t   .0R   (    (    s   /usr/lib/python2.7/cgi.pys	   <genexpr>M  s    N(   Rm   R-   R   t   set(   Rf   (    (    s   /usr/lib/python2.7/cgi.pyR   I  s    c            s8   |  j  d k r t d  n  t   f d   |  j  D  S(   s"   Dictionary style has_key() method.s   not indexablec         3   s   |  ] } | j    k Vq d  S(   N(   RA   (   R   R   (   RS   (    s   /usr/lib/python2.7/cgi.pys	   <genexpr>S  s    N(   Rm   R-   R   t   any(   Rf   RS   (    (   RS   s   /usr/lib/python2.7/cgi.pyt   has_keyO  s    c            s8   |  j  d k r t d  n  t   f d   |  j  D  S(   s%   Dictionary style __contains__ method.s   not indexablec         3   s   |  ] } | j    k Vq d  S(   N(   RA   (   R   R   (   RS   (    s   /usr/lib/python2.7/cgi.pys	   <genexpr>Y  s    N(   Rm   R-   R   R   (   Rf   RS   (    (   RS   s   /usr/lib/python2.7/cgi.pyt   __contains__U  s    c         C   s   t  |  j    S(   s    Dictionary style len(x) support.(   RY   R   (   Rf   (    (    s   /usr/lib/python2.7/cgi.pyt   __len__[  s    c         C   s   t  |  j  S(   N(   t   boolRm   (   Rf   (    (    s   /usr/lib/python2.7/cgi.pyt   __nonzero___  s    c         C   s   |  j  j |  j  } |  j r2 | d |  j 7} n  t j | |  j |  j |  j  } g  | D] \ } } t	 | |  ^ qZ |  _
 |  j   d S(   s+   Internal: read data in query string format.R,   N(   R6   R3   Rx   Ru   R5   R   R8   R9   R?   R   Rm   t
   skip_lines(   Rf   R=   t   queryRS   Re   (    (    s   /usr/lib/python2.7/cgi.pyRz   b  s    	+c         C   s  |  j  } t |  s( t d | f  n  g  |  _ |  j r t j |  j |  j |  j |  j	  } |  j j
 d   | D  d } n  |  j	 } | d k	 r | t |  j  8} n  |  j p |  j } | |  j i  | | | | |  }	 x |	 j st j |  j  }
 | |  j |
 | | | | |  }	 | d k	 rq| d 8} |	 j rS| t |	 j  8} n  | d k  rqt d   qqn  |  j j |	  q W|  j   d S(   s/   Internal: read a part that is itself multipart.s&   Invalid boundary in multipart form: %rc         s   s$   |  ] \ } } t  | |  Vq d  S(   N(   R   (   R   RS   Re   (    (    s   /usr/lib/python2.7/cgi.pys	   <genexpr>y  s   i   i    s   Max number of fields exceededN(   Rw   RB   R2   Rm   Ru   R5   R   R8   R9   R?   t   extendR-   RY   t   FieldStorageClasst	   __class__R6   Ry   t   rfc822RD   RH   R   (   Rf   R7   R8   R9   t   ibR   R   R?   t   klasst   partRP   (    (    s   /usr/lib/python2.7/cgi.pyR{   n  s@    									
	c         C   sD   |  j  d k r& |  j   |  j   n
 |  j   |  j j d  d S(   s   Internal: read an atomic part.i    N(   Rx   t   read_binaryR   t
   read_linesRo   R   (   Rf   (    (    s   /usr/lib/python2.7/cgi.pyR|     s
    

i   i   c         C   s   |  j  d  |  _ |  j } | d k r xd | d k r |  j j t | |  j   } | sg d |  _ Pn  |  j j |  | t	 |  } q* Wn  d S(   s   Internal: read binary data.t   bi    iN(
   t	   make_fileRo   Rx   R6   R3   t   mint   bufsizeRy   R#   RY   (   Rf   t   todoRO   (    (    s   /usr/lib/python2.7/cgi.pyR     s    		c         C   s7   t    |  _ |  _ |  j r) |  j   n
 |  j   d S(   s0   Internal: read lines until EOF or outerboundary.N(   R   Ro   t   _FieldStorage__fileRv   t   read_lines_to_outerboundaryt   read_lines_to_eof(   Rf   (    (    s   /usr/lib/python2.7/cgi.pyR     s    	c         C   s|   |  j  d  k	 rh |  j  j   t |  d k rh |  j d  |  _ |  j j |  j  j    d  |  _  qh n  |  j j |  d  S(   Ni  R   (   R   R-   t   tellRY   R   Ro   R#   R   (   Rf   RR   (    (    s   /usr/lib/python2.7/cgi.pyt   __write  s    c         C   s=   x6 |  j  j d  } | s( d |  _ Pn  |  j |  q Wd S(   s   Internal: read lines until EOF.i   i   iNi   (   R6   RF   Ry   t   _FieldStorage__write(   Rf   RR   (    (    s   /usr/lib/python2.7/cgi.pyR     s    	c         C   s^  d |  j  } | d } d } t } x4|  j j d  } | sK d |  _ Pn  | d k rj | | } d } n  | d  d k r | r | j   } | | k r Pn  | | k r d |  _ Pq n  | } | d d	 k r d	 } | d  } t } n^ | d d
 k rd
 } | d  } t } n5 | d d k r9d } | d  } t } n d } t } |  j | |  q& Wd S(   s)   Internal: read lines until outerboundary.s   --R   i   i   is   i   is   
s   
Ni   (   Rv   t   TrueR6   RF   Ry   RG   t   FalseR   (   Rf   R_   t   lastt   delimt   last_line_lfendRR   t   strippedlinet   odelim(    (    s   /usr/lib/python2.7/cgi.pyR     sF    
	
		
	
	
	c         C   s   |  j  s |  j r d Sd |  j  } | d } t } x |  j j d  } | s\ d |  _ Pn  | d  d k r | r | j   } | | k r Pn  | | k r d |  _ Pq n  | j d  } q7 Wd S(	   s5   Internal: skip lines until outer boundary if defined.Ns   --i   i   ii   s   
i   (   Rv   Ry   R   R6   RF   RG   t   endswith(   Rf   R_   R   R   RR   R   (    (    s   /usr/lib/python2.7/cgi.pyR     s$    
		c         C   s   d d l  } | j d  S(   s  Overridable: return a readable & writable file.

        The file will be used as follows:
        - data is written to it
        - seek(0)
        - data is read from it

        The 'binary' argument is unused -- the file is always opened
        in binary mode.

        This version opens a temporary file for reading and writing,
        and immediately deletes (unlinks) it.  The trick (on Unix!) is
        that the file can still be used, but it can't be opened by
        another process, and it will automatically be deleted when it
        is closed or when the current process terminates.

        If you want a more permanent file, you derive a class which
        overrides this method.  If you want a visible temporary file
        that is nevertheless automatically deleted when the script
        terminates, try defining a __del__ method in a derived class
        which unlinks the temporary files you have created.

        iNs   w+b(   t   tempfilet   TemporaryFile(   Rf   t   binaryR   (    (    s   /usr/lib/python2.7/cgi.pyR     s    Ni    (   Ri   Rj   Rk   R-   t   osR7   Rg   Rh   R   R   R   R   R   R   R   R   R   R   R   Rz   R   R{   R|   R   R   R   R   R   R   R   R   (    (    (    s   /usr/lib/python2.7/cgi.pyR   a  s8   )	w											
	*								)	c           B   s#   e  Z d  Z e j d d d  Z RS(   sx  Form content as dictionary with a list of values per field.

    form = FormContentDict()

    form[key] -> [value, value, ...]
    key in form -> Boolean
    form.keys() -> [key, key, ...]
    form.values() -> [[val, val, ...], [val, val, ...], ...]
    form.items() ->  [(key, [val, val, ...]), (key, [val, val, ...]), ...]
    form.dict == {key: [val, val, ...], ...}

    i    c         C   s6   t  d | d | d |  |  _ |  _ | d |  _ d  S(   NR7   R8   R9   R+   (   R   t   dictRO   t   query_string(   Rf   R7   R8   R9   (    (    s   /usr/lib/python2.7/cgi.pyRg   4  s    (   Ri   Rj   Rk   R   R7   Rg   (    (    (    s   /usr/lib/python2.7/cgi.pyR   '  s   c           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   s  Form content as dictionary expecting a single value per field.

    If you only expect a single value for each field, then form[key]
    will return that single value.  It will raise an IndexError if
    that expectation is not true.  If you expect a field to have
    possible multiple values, than you can use form.getlist(key) to
    get all of the values.  values() and items() are a compromise:
    they return single strings where there is a single value, and
    lists of strings otherwise.

    c         C   s4   t  |  j |  d k r% t d  n  |  j | d S(   Ni   s   expecting a single valuei    (   RY   R   t
   IndexError(   Rf   RS   (    (    s   /usr/lib/python2.7/cgi.pyR   G  s    c         C   s   |  j  | S(   N(   R   (   Rf   RS   (    (    s   /usr/lib/python2.7/cgi.pyR   K  s    c         C   sW   g  } xJ |  j  j   D]9 } t |  d k rB | j | d  q | j |  q W| S(   Ni   i    (   R   t   valuesRY   RH   (   Rf   t   resultRe   (    (    s   /usr/lib/python2.7/cgi.pyR   M  s    c         C   si   g  } x\ |  j  j   D]K \ } } t |  d k rN | j | | d f  q | j | | f  q W| S(   Ni   i    (   R   t   itemsRY   RH   (   Rf   R   RS   Re   (    (    s   /usr/lib/python2.7/cgi.pyR   T  s    (   Ri   Rj   Rk   R   R   R   R   (    (    (    s   /usr/lib/python2.7/cgi.pyR	   ;  s
   			c           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   s7   This class is present for backwards compatibility only.c         C   ss   t  j |  |  } | d d k ri y t |  SWqi t k
 re y t |  SWqf t k
 ra qf Xqi Xn  | j   S(   Ni    s   0123456789+-.(   R	   R   R0   R2   t   floatRG   (   Rf   RS   t   v(    (    s   /usr/lib/python2.7/cgi.pyR   _  s       c         C   s^   g  } xQ |  j    D]C } y | j |  |  Wq t k
 rU | j |  j |  q Xq W| S(   N(   R   RH   R   R   (   Rf   R   RS   (    (    s   /usr/lib/python2.7/cgi.pyR   g  s    c         C   sj   g  } x] |  j    D]O } y | j | |  | f  Wq t k
 ra | j | |  j | f  q Xq W| S(   N(   R   RH   R   R   (   Rf   R   RS   (    (    s   /usr/lib/python2.7/cgi.pyR   o  s    "(   Ri   Rj   Rk   R   R   R   (    (    (    s   /usr/lib/python2.7/cgi.pyR
   ]  s   		c           B   sD   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s7   This class is present for backwards compatibility only.c         C   s"   | |  j  k r |  j  | Sd  Sd  S(   N(   R   R-   (   Rf   RS   (    (    s   /usr/lib/python2.7/cgi.pyR   {  s     c         C   sF   | |  j  k r> t |  j  |  | k r7 |  j  | | Sd  Sn d  Sd  S(   N(   R   RY   R-   (   Rf   RS   t   location(    (    s   /usr/lib/python2.7/cgi.pyt   indexed_value~  s
    c         C   s&   | |  j  k r |  j  | d Sd  Sd  S(   Ni    (   R   R-   (   Rf   RS   (    (    s   /usr/lib/python2.7/cgi.pyRe     s     c         C   s   t  |  j |  S(   N(   RY   R   (   Rf   RS   (    (    s   /usr/lib/python2.7/cgi.pyRx     s    c         C   s,   | |  j  k r$ |  j  | d j   Sd  Sd  S(   Ni    (   R   RG   R-   (   Rf   RS   (    (    s   /usr/lib/python2.7/cgi.pyt   stripped  s     c         C   s   |  j  S(   N(   R   (   Rf   (    (    s   /usr/lib/python2.7/cgi.pyt   pars  s    (	   Ri   Rj   Rk   R   R   Re   Rx   R   R   (    (    (    s   /usr/lib/python2.7/cgi.pyR   y  s   					c         C   s   d GHHt  j t  _ yW t   } t   t   t |  t |   t   d   } | d  } d GH|   Wn t	   n Xd GHd a
 y/ t   } t   t   t |  t |   Wn t	   n Xd S(   s   Robust test CGI script, usable as main program.

    Write minimal HTTP headers and dump all information provided to
    the script in HTML form.

    s   Content-type: text/htmlc           R   s   d d  Ud  S(   Ns,   testing print_exception() -- <I>italics?</I>(    (    (    (    s   /usr/lib/python2.7/cgi.pyR\     s    c         S   s   |    d  S(   N(    (   R\   (    (    s   /usr/lib/python2.7/cgi.pyt   g  s    s9   <H3>What follows is a test, not an actual exception:</H3>s*   <H1>Second try with a small maxlen...</H1>i2   N(   R.   t   stdoutt   stderrR   R   R   R   R   R   R   R1   (   R7   t   formR\   R   (    (    s   /usr/lib/python2.7/cgi.pyt   test  s4    	

		
c         C   s   |  d  k r$ t j   \ }  } } n  d d  l } Hd GH| j | |  | j |  |  } d t d j | d    t | d  f GH~ d  S(   Nis+   <H3>Traceback (most recent call last):</H3>s   <PRE>%s<B>%s</B></PRE>R   (   R-   R.   t   exc_infot	   tracebackt	   format_tbt   format_exception_onlyR   RI   (   Rn   Re   t   tbt   limitR   Rm   (    (    s   /usr/lib/python2.7/cgi.pyR     s    c         C   s]   |  j    } | j   Hd GHd GHx/ | D]' } d Gt |  Gd Gt |  |  GHq( Wd GHHd S(   s#   Dump the shell environment as HTML.s   <H3>Shell Environment:</H3>s   <DL>s   <DT>s   <DD>s   </DL>N(   R   t   sortR   (   R7   R   RS   (    (    s   /usr/lib/python2.7/cgi.pyR     s    
%c         C   s   |  j    } | j   Hd GH| s* d GHn  d GHx^ | D]V } d t |  d G|  | } d t t t |    d GHd t t |   GHq6 Wd	 GHHd
 S(   s$   Dump the contents of a form as HTML.s   <H3>Form Contents:</H3>s   <P>No form fields.s   <DL>s   <DT>t   :s   <i>s   </i>s   <DD>s   </DL>N(   R   R   R   t   reprRn   (   R   R   RS   Re   (    (    s   /usr/lib/python2.7/cgi.pyR     s    

c          C   sT   Hd GHy t  j   }  Wn+ t  j k
 rC } d Gt t |   GHn Xt |   GHHd S(   s#   Dump the current directory as HTML.s#   <H3>Current Working Directory:</H3>s	   os.error:N(   R   t   getcwdt   errorR   t   str(   t   pwdt   msg(    (    s   /usr/lib/python2.7/cgi.pyR     s    c           C   s   Hd GHHt  j GHHd  S(   Ns    <H3>Command Line Arguments:</H3>(   R.   R4   (    (    (    s   /usr/lib/python2.7/cgi.pyR     s
    c           C   s	   d GHd S(   s9   Dump a list of environment variables used by CGI as HTML.s  
<H3>These environment variables could have been set:</H3>
<UL>
<LI>AUTH_TYPE
<LI>CONTENT_LENGTH
<LI>CONTENT_TYPE
<LI>DATE_GMT
<LI>DATE_LOCAL
<LI>DOCUMENT_NAME
<LI>DOCUMENT_ROOT
<LI>DOCUMENT_URI
<LI>GATEWAY_INTERFACE
<LI>LAST_MODIFIED
<LI>PATH
<LI>PATH_INFO
<LI>PATH_TRANSLATED
<LI>QUERY_STRING
<LI>REMOTE_ADDR
<LI>REMOTE_HOST
<LI>REMOTE_IDENT
<LI>REMOTE_USER
<LI>REQUEST_METHOD
<LI>SCRIPT_NAME
<LI>SERVER_NAME
<LI>SERVER_PORT
<LI>SERVER_PROTOCOL
<LI>SERVER_ROOT
<LI>SERVER_SOFTWARE
</UL>
In addition, HTTP headers sent by the server may be passed in the
environment as well.  Here are some common variable names:
<UL>
<LI>HTTP_ACCEPT
<LI>HTTP_CONNECTION
<LI>HTTP_HOST
<LI>HTTP_PRAGMA
<LI>HTTP_REFERER
<LI>HTTP_USER_AGENT
</UL>
N(    (    (    (    s   /usr/lib/python2.7/cgi.pyR     s    )c         C   sU   |  j  d d  }  |  j  d d  }  |  j  d d  }  | rQ |  j  d d  }  n  |  S(	   s   Replace special characters "&", "<" and ">" to HTML-safe sequences.
    If the optional flag quote is true, the quotation mark character (")
    is also translated.R,   s   &amp;t   <s   &lt;t   >s   &gt;RV   s   &quot;(   Ra   (   RZ   t   quote(    (    s   /usr/lib/python2.7/cgi.pyR   '  s    s   ^[ -~]{0,200}[!-~]$c         C   s   d d  l  } | j | |   S(   Ni(   t   ret   match(   RZ   t   _vb_patternR   (    (    s   /usr/lib/python2.7/cgi.pyRB   2  s    t   __main__(3   Rk   t   __version__t   operatorR    R.   R   t   UserDictR5   t   warningsR   R   R   t   py3kwarningt   DeprecationWarningRC   R   t	   cStringIOR   t   ImportErrort   __all__R   R-   R   R"   R    R   R   R1   R7   R   R   R   R   R]   R   R   R   R   R	   R
   R   R   R   R   R   R   R   R   R   RB   Ri   (    (    (    s   /usr/lib/python2.7/cgi.pyt   <module>   sp   
			
					#		8	b		 "'				/