ó
j1dEc           @   sß   d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z d  d l Td  d l Te  j Z e  j Z d Z	 d f  d „  ƒ  YZ
 d e f d „  ƒ  YZ d e f d	 „  ƒ  YZ d
 f  d „  ƒ  YZ d „  Z d „  Z d e d „ Z d S(   iÿÿÿÿN(   t   *iXÿ  t   Fieldc           B   s8   e  Z d  „  Z i  d „ Z d „  Z d „  Z d „  Z RS(   c         O   s,   | |  _  | s | r( |  j | | Ž  n  d  S(   N(   t   namet   __bc_init__(   t   selfR   t   argst   kwargs(    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyt   __init__3   s    	c         C   sb   | |  _  | |  _ | |  _ | |  _ | |  _ | j d ƒ rL | d |  _ n	 d  |  _ | |  _ d  S(   Nt   filename(	   t   filet   typet   type_optionst   dispositiont   disposition_optionst   has_keyR   t   Nonet   headers(   R   R	   t   ctypeR   t   dispt   disp_optionsR   (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyR   G   s    						c         C   s   d |  j  |  j f S(   s    Return printable representation.s   Field(%s, %s)(   R   t   value(   R   (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyt   __repr__T   s    c         C   s]   | d k r t  | ‚ n  |  j rS |  j j d ƒ |  j j ƒ  } |  j j d ƒ n d  } | S(   NR   i    (   t   AttributeErrorR	   t   seekt   readR   (   R   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyt   __getattr__X   s    	c         C   s   |  j  j ƒ  d  S(   N(   R	   t   close(   R   (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyt   __del__c   s    (   t   __name__t
   __module__R   R   R   R   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyR   2   s
   			t   StringFieldc           B   sM   e  Z d  Z d Z i  Z d Z i  Z d Z d Z	 d „  Z
 d „  Z d „  Z RS(   s   This class is basically a string with
    added attributes for compatibility with std lib cgi.py. Basically, this
    works the opposite of Field, as it stores its data in a string, but creates
    a file on demand. Field creates a value on demand and stores data in a file.
    s
   text/plainc         C   s   t  j |  | ƒ | |  _ d S(   s>   Create StringField instance. You'll have to set name yourself.N(   t   strR   R   (   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyR   u   s    c         C   s4   | d k r t  | ‚ n  t j |  j ƒ |  _ |  j S(   NR	   (   R   t	   cStringIOt   StringIOR   R	   (   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyR   z   s    c         C   s   d |  j  |  j f S(   s5   Return printable representation (to pass unit tests).s   Field(%s, %s)(   R   R   (   R   (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyR   €   s    N(   R   R   t   __doc__R   R   R   R   R   R   R   R   R   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyR   f   s   		t	   FieldListc           B   s}   e  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 RS(   c         C   s   d  |  _ t j |  ƒ d  S(   N(   R   t   _FieldList__tablet   listR   (   R   (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyR   †   s    	c         C   sr   |  j  d  k rk i  |  _  xP |  D]E } | j |  j  k rQ |  j  | j j | ƒ q | g |  j  | j <q Wn  |  j  S(   N(   R$   R   R   t   append(   R   t   item(    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyt   tableŠ   s    	c         G   s   d  |  _ t j |  | Œ S(   N(   R   R$   R%   t   __delitem__(   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyR)   ”   s    	c         G   s   d  |  _ t j |  | Œ S(   N(   R   R$   R%   t   __delslice__(   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyR*   ˜   s    	c         G   s   d  |  _ t j |  | Œ S(   N(   R   R$   R%   t   __iadd__(   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyR+   œ   s    	c         G   s   d  |  _ t j |  | Œ S(   N(   R   R$   R%   t   __imul__(   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyR,       s    	c         G   s   d  |  _ t j |  | Œ S(   N(   R   R$   R%   t   __setitem__(   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyR-   ¤   s    	c         G   s   d  |  _ t j |  | Œ S(   N(   R   R$   R%   t   __setslice__(   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyR.   ¨   s    	c         G   s   d  |  _ t j |  | Œ S(   N(   R   R$   R%   R&   (   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyR&   ¬   s    	c         G   s   d  |  _ t j |  | Œ S(   N(   R   R$   R%   t   extend(   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyR/   °   s    	c         G   s   d  |  _ t j |  | Œ S(   N(   R   R$   R%   t   insert(   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyR0   ´   s    	c         G   s   d  |  _ t j |  | Œ S(   N(   R   R$   R%   t   pop(   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyR1   ¸   s    	c         G   s   d  |  _ t j |  | Œ S(   N(   R   R$   R%   t   remove(   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyR2   ¼   s    	(   R   R   R   R(   R)   R*   R+   R,   R-   R.   R&   R/   R0   R1   R2   (    (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyR#   „   s   		
										t   FieldStoragec           B   s­   e  Z d  d  d d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z e Z d „  Z d d „ Z d „  Z d „  Z d „  Z d „  Z RS(   i    c         C   s  t  ƒ  |  _ | j rS t | j | ƒ } x) | D] } |  j | d | d ƒ q. Wn  | j d k rf d  Sy t | j d ƒ } Wn& t t	 f k
 r¥ t
 j t
 j ‚ n X| j j d ƒ sÁ d }	 n | j d }	 |	 j d ƒ r"t | j | ƒ | ƒ } x& | D] } |  j | d | d ƒ qü Wd  S|	 j d ƒ sCt
 j t
 j ‚ n  y |	 j ƒ  j d ƒ }
 |	 |
 d	 } t | ƒ d
 k r¯| d | d k ošd k n r¯| d d !} n  t j d t j | ƒ d ƒ } Wn  t	 k
 ròt
 j t
 j ‚ n X|  j | | d  ƒ t } x| sd i  }	 } d  i  } } t
 j ƒ  } | j t ƒ } | j | ƒ } | sf| rˆ| p| j d ƒ d  k	 } qn  t } x1| d k rÁ| j t ƒ } x3 | rá| d d k rá| | } | j t ƒ } q¯W| j  d d ƒ \ } } | j! | | ƒ | j ƒ  } | d k r7t" | ƒ \ } } n? | d k rvt" | ƒ \ }	 } |	 j# d ƒ d k rvd }	 qvn  | } | j | ƒ } | s˜| r‘t$ } | p·| j d ƒ d  k	 } Pq‘q‘W| rÎqn  | j d ƒ rê| d } n d  } | j d ƒ r6| r$t% | ƒ r$| | d ƒ } q`t& j' d ƒ } n* | rTt% | ƒ rT| ƒ  } n t( j) ƒ  } |  j | | | ƒ | j* d ƒ | j d ƒ r«t+ | ƒ } | d | _, n t- | j ƒ  ƒ } | | _. | | _/ |	 | _0 | | _1 | | _2 | | _3 | | _4 |  j j5 | ƒ qWd  S(   Ni    i   t   POSTs   content-lengths   content-types!   application/x-www-form-urlencodeds
   multipart/s	   boundary=i	   i   iÿÿÿÿt   "s   --s   (--)??
s
   text/plains   s   
t    s   	t   :s   content-dispositiont   /s   application/octet-streamR   R   s   w+b(   s   s   
(   R6   s   	(6   R#   R%   R   t	   parse_qslt	   add_fieldt   methodt   intt
   headers_int   KeyErrort
   ValueErrort   apachet   SERVER_RETURNt   HTTP_LENGTH_REQUIREDR   t
   startswithR   t   HTTP_NOT_IMPLEMENTEDt   lowert   rindext   lent   ret   compilet   escapet   HTTP_BAD_REQUESTt   read_to_boundaryR   t   Falset
   make_tablet   readlinet   readBlockSizet   matcht   groupt   splitt   addt   parse_headert   findt   Truet   callablet   tempfilet   TemporaryFileR    R!   R   R   R   R   R   R	   R
   R   R   R   R   R&   (   R   t   reqt   keep_blank_valuest   strict_parsingt   file_callbackt   field_callbackt   pairst   pairt   clenR   t   it   boundaryt   end_of_streamR   R   R   R   t   lineRQ   t   skip_this_partt   nextlinet   ht   vR   R	   t   field(    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyR   Ã   s®    		6$	
							c         C   s)   t  | ƒ } | | _ |  j j | ƒ d S(   s    Insert a field as key/value pairN(   R   R   R%   R&   (   R   t   keyR   R'   (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyR:   X  s    	c         C   su   |  j  j ƒ  } | j | ƒ rL | | } x! | D] } |  j  j | ƒ q/ Wn  t | ƒ } | | _ |  j  j | ƒ d  S(   N(   R%   R(   R   R2   R   R   R&   (   R   Rl   R   R(   t   itemsR'   (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyR-   ^  s    
	c         C   s¡  d  } x”t rœ| j t ƒ } | sP | d  k	 rL | d  k	 rL | j | ƒ n  t S| j | ƒ } | rx | j d ƒ d  k	 S| d d k rÍ | d  k	 rÄ | d  k	 r° | j | ƒ n  | j | d  ƒ n  d } q	 | d d k r:t | ƒ t k sõ t ‚ | d  k	 r1| d  k	 r| j | ƒ n  | j | d  ƒ n  d } q	 | d k r[| d k r[d } q	 | d  k	 r“| d  k	 rƒ| j | ƒ n  | j | ƒ n  d  } q	 Wd  S(   Ni   iþÿÿÿs   
iÿÿÿÿs   s   
(	   R   RW   RO   RP   t   writeRQ   RR   RG   t   AssertionError(   R   R[   Rd   R	   t   previous_delimiterRf   RQ   (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyRL   h  s<    	 	 		 c         C   s5   |  j  j ƒ  | } t | ƒ d k r- | d S| Sd S(   s   Dictionary style indexing.i   i    N(   R%   R(   RG   (   R   Rl   t   found(    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyt   __getitem__™  s    c         C   s0   y |  j  | ƒ SWn t t f k
 r+ | SXd  S(   N(   Rr   t	   TypeErrorR>   (   R   Rl   t   default(    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyt   get¡  s    c         C   s   |  j  j ƒ  j ƒ  S(   s   Dictionary style keys() method.(   R%   R(   t   keys(   R   (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyRv   §  s    c         C   s   t  |  j ƒ  ƒ S(   N(   t   iterRv   (   R   (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyt   __iter__«  s    c         C   s   t  |  j j ƒ  ƒ S(   N(   t   reprR%   R(   (   R   (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyR   ®  s    c         C   s   | |  j  j ƒ  k S(   s"   Dictionary style has_key() method.(   R%   R(   (   R   Rl   (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyR   ±  s    c         C   s   t  |  j j ƒ  ƒ S(   s    Dictionary style len(x) support.(   RG   R%   R(   (   R   (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyt   __len__·  s    c         C   s2   y |  j  j ƒ  | d SWn t k
 r- | SXd S(   s!    return the first value received i    N(   R%   R(   R>   (   R   Rl   Rt   (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyt   getfirst»  s    c         C   s.   y |  j  j ƒ  | SWn t k
 r) g  SXd S(   s"    return a list of received values N(   R%   R(   R>   (   R   Rl   (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyt   getlistÂ  s    c         C   s#   g  |  j  D] } | j | f ^ q
 S(   su   Dictionary-style items(), except that items are returned in the same
        order as they were supplied in the form.(   R%   R   (   R   R'   (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyRm   É  s    c         C   s>   |  j  j ƒ  } | | } x | D] } |  j  j | ƒ q  Wd  S(   N(   R%   R(   R2   (   R   Rl   R(   t   valuesR   (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyR)   Î  s    
c         C   s   t  ƒ  |  _ d  S(   N(   R#   R%   (   R   (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyt   clearÔ  s    N(   R   R   R   R   R:   R-   RL   Rr   Ru   Rv   Rx   R   R   t   __contains__Rz   R{   R|   Rm   R)   R~   (    (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyR3   Á   s"   •		
	1										c         C   së   t  d „  |  j d ƒ ƒ } | d j ƒ  } | d =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 !} n  | | | <q? q? W| | f S(	   sf   Parse a Content-type like header.

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

    c         S   s
   |  j  ƒ  S(   N(   t   strip(   t   a(    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyt   <lambda>ß  s    t   ;i    t   =i   i   iÿÿÿÿR5   (   t   mapRS   RE   RV   R€   RG   (   Rf   t   plistRl   t   pdictt   pRc   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyRU   Ø  s    6c   	      K   s!  d } g  } t |  d ƒ r: |  j } | j d | j !} nî t |  d ƒ rk |  j j } | j d | j !} n½ t |  ƒ t t f k r¨ |  j	 j j } | j d | j !} n€ t |  ƒ t
 k rÉ d } g  } n_ t |  d ƒ r(t |  j ƒ t k r|  j j j } | j d | j !} q(t |  j | |  Sn  xH | j D]= } | j rJ| } n	 | j } | j | j g  ƒ j | ƒ q2WxO | D]G } t | | ƒ t k rzt | | ƒ d k rz| | d | | <qzqzW| d k rÚi  } n= | j d @sx- | j ƒ  D] } | | k rô| | =qôqôWn  |  |   S(   s­   
    Apply FieldStorage data to an object - the object must be
    callable. Examine the args, and match then with fs data,
    then call the object, return the result.
    t	   func_codei    t   im_funci   t   __call__i   N(   R   t   hasattrR‰   t   co_varnamest   co_argcountRŠ   R
   t   TypeTypet	   ClassTypeR   t   BuiltinFunctionTypeR‹   t
   MethodTypet   apply_fs_dataR%   R   R   t
   setdefaultR   R&   t   ListTypeRG   t   co_flagsRv   (	   t   objectt   fsR   t   fct   expectedRk   t   valt   argR   (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyR“   í  sF    					 	i    c         C   sƒ   |  j  r t d ‚ n  | |  j d <| r7 t j |  _ n t j |  _ | d k rc |  j d | ƒ n |  j | ƒ t j	 t j
 ‚ d S(   s7   
    A convenience function to provide redirection
    s5   Cannot redirect after headers have already been sent.t   Locations4   <p>The document has moved <a href="%s">here</a></p>
N(   t   sent_bodyctt   IOErrort   err_headers_outR@   t   HTTP_MOVED_PERMANENTLYt   statust   HTTP_MOVED_TEMPORARILYR   Rn   RA   t   DONE(   R[   t   locationt	   permanentt   text(    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyt   redirect,  s    		(   t   _apacheR@   R    RY   RH   t   typest
   exceptionst   parse_qsR9   RP   R   R   R   R%   R#   R3   RU   R“   R   R¨   (    (    (    s3   /usr/lib/python2.7/dist-packages/mod_python/util.pyt   <module>   s"   

		4=ÿ 		?