³ò
+e|Mc        	   @   s§   d  Z  d d k Z y d d k l Z Wn n Xd d k l Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d	 Z	 d
 e f d „  ƒ  YZ
 d a d a h  a d „  Z d S(   s½  WSGI Paste wrapper for mod_python. Requires Python 2.2 or greater.


Example httpd.conf section for a Paste app with an ini file::

    <Location />
        SetHandler python-program
        PythonHandler paste.modpython
        PythonOption paste.ini /some/location/your/pasteconfig.ini
    </Location>
    
Or if you want to load a WSGI application under /your/homedir in the module
``startup`` and the WSGI app is ``app``::

    <Location />
        SetHandler python-program
        PythonHandler paste.modpython
        PythonPath "['/virtual/project/directory'] + sys.path"
        PythonOption wsgi.application startup::app
    </Location>


If you'd like to use a virtual installation, make sure to add it in the path
like so::

    <Location />
        SetHandler python-program
        PythonHandler paste.modpython
        PythonPath "['/virtual/project/directory', '/virtual/lib/python2.4/'] + sys.path"
        PythonOption paste.ini /virtual/project/directory/pasteconfig.ini
    </Location>

Some WSGI implementations assume that the SCRIPT_NAME environ variable will
always be equal to "the root URL of the app"; Apache probably won't act as
you expect in that case. You can add another PythonOption directive to tell
modpython_gateway to force that behavior:

    PythonOption SCRIPT_NAME /mcontrol

Some WSGI applications need to be cleaned up when Apache exits. You can
register a cleanup handler with yet another PythonOption directive:

    PythonOption wsgi.cleanup module::function

The module.function will be called with no arguments on server shutdown,
once for each child process or thread.

This module highly based on Robert Brewer's, here:
http://projects.amor.org/misc/svn/modpython_gateway.py
iÿÿÿÿN(   t   apache(   t   loadappt   InputWrapperc           B   sG   e  Z d  „  Z d „  Z d d „ Z d d „ Z d d „ Z d „  Z RS(   c         C   s   | |  _  d  S(   N(   t   req(   t   selfR   (    (    s^   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/modpython.pyt   __init__>   s    c         C   s   d  S(   N(    (   R   (    (    s^   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/modpython.pyt   closeA   s    iÿÿÿÿc         C   s   |  i  i | ƒ S(   N(   R   t   read(   R   t   size(    (    s^   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/modpython.pyR   D   s    c         C   s   |  i  i | ƒ S(   N(   R   t   readline(   R   R   (    (    s^   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/modpython.pyR	   G   s    c         C   s   |  i  i | ƒ S(   N(   R   t	   readlines(   R   t   hint(    (    s^   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/modpython.pyR
   J   s    c         c   s0   |  i  ƒ  } x | o | V|  i  ƒ  } q Wd  S(   N(   R	   (   R   t   line(    (    s^   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/modpython.pyt   __iter__M   s
     (   t   __name__t
   __module__R   R   R   R	   R
   R   (    (    (    s^   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/modpython.pyR   <   s   		t   ErrorWrapperc           B   s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         C   s   | |  _  d  S(   N(   R   (   R   R   (    (    s^   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/modpython.pyR   X   s    c         C   s   d  S(   N(    (   R   (    (    s^   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/modpython.pyt   flush[   s    c         C   s   |  i  i | ƒ d  S(   N(   R   t	   log_error(   R   t   msg(    (    s^   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/modpython.pyt   write^   s    c         C   s   |  i  d i | ƒ ƒ d  S(   Nt    (   R   t   join(   R   t   seq(    (    s^   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/modpython.pyt
   writelinesa   s    (   R   R   R   R   R   R   (    (    (    s^   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/modpython.pyR   V   s   			sf   You must provide a PythonOption '%s', either 'on' or 'off', when running a version of mod_python < 3.1t   Handlerc           B   s/   e  Z d  „  Z d „  Z d d „ Z d „  Z RS(   c         C   sò  t  |  _ | i ƒ  } y+ t i } | t i ƒ } | t i ƒ } Wn¿ t j
 o³ | i d d ƒ i	 ƒ  } | d j o
 t
 } n( | d j o
 t  } n t t d ƒ ‚ | i d d ƒ i	 ƒ  } | d j o
 t
 } q| d j o
 t  } qt t d ƒ ‚ n Xt t i | ƒ ƒ } |  _ d | j o- | d | d <| i t | d ƒ | d <n d | d <| i | d <t | ƒ | d <t | ƒ | d	 <d | d <t  | d <| i d ƒ d j o d | d <n d | d <| | d <| | d <| |  _ d  S(   Nt   multithreadR   t   ont   offt   multiprocesst   SCRIPT_NAMEt	   PATH_INFOs
   wsgi.inputs   wsgi.errorsi   i    s   wsgi.versions   wsgi.run_oncet   HTTPSt   yest   1t   httpss   wsgi.url_schemet   https   wsgi.multithreads   wsgi.multiprocess(   i   i    (   s   yess   onR"   (   t   Falset   startedt   get_optionsR    t	   mpm_queryt   AP_MPMQ_IS_THREADEDt   AP_MPMQ_IS_FORKEDt   AttributeErrort   gett   lowert   Truet
   ValueErrort	   bad_valuet   dictt   build_cgi_envt   environt   urit   lenR   R   t   request(   R   R   t   optionst   qt   threadedt   forkedt   env(    (    s^   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/modpython.pyR   k   sF    		









c         C   sê   ys | |  i  |  i ƒ } x | D] } |  i | ƒ q W|  i p |  i i d ƒ n t | d ƒ o | i ƒ  n Wnp t i	 d  |  i  d ƒ |  i pH d |  i _ d |  i _ d } |  i i t | ƒ ƒ |  i i | ƒ qæ n Xd  S(   Ni    R   s   wsgi.errorsiô  s
   text/plains:   A server error occurred. Please contact the administrator.(   R3   t   start_responseR   R&   R6   t   set_content_lengtht   hasattrR   t	   tracebackt	   print_exct   Nonet   statust   content_typeR5   (   R   t   applicationt   resultt   data(    (    s^   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/modpython.pyt   run   s"     

c         C   sÙ   | o8 z* |  i  o | d | d | d ‚ n Wd  d  } Xn t | d  ƒ |  i _ xz | D]r \ } } | i ƒ  d j o |  i i t | ƒ ƒ q\ | i ƒ  d j o | |  i _ q\ |  i i i	 | | ƒ q\ W|  i
 S(   Ni    i   i   i   s   content-lengths   content-type(   R&   RA   t   intR6   RB   R-   R=   RC   t   headers_outt   addR   (   R   RB   t   headerst   exc_infot   keyt   val(    (    s^   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/modpython.pyR<   ¯   s    
  c         C   s+   |  i  p t |  _  n |  i i | ƒ d  S(   N(   R&   R.   R6   R   (   R   RF   (    (    s^   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/modpython.pyR   Ã   s    
N(   R   R   R   RG   RA   R<   R   (    (    (    s^   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/modpython.pyR   i   s   	2	c         C   s  |  i  ƒ  } d | j os t ok | d } | oV | i d d ƒ \ } } t | t ƒ  t ƒ  d g ƒ } t i | | ƒ a t |  ƒ qŒ n d | j o¬ t o¤ | d } | o | i d d ƒ \ } } t | t ƒ  t ƒ  d g ƒ } t i | | ƒ a d „  } y t i	 | ƒ WqAt
 j
 o |  i i	 |  | ƒ qAXqEn | i d ƒ } d  } | o3 | t j o t d | ƒ t | <n t | } n | i d	 ƒ }	 |	 oQ | oI |	 i d d ƒ \ }
 } t |
 t ƒ  t ƒ  d g ƒ } t | | ƒ } n t |  ƒ i | ƒ t i S(
   Ns   wsgi.startups   ::i   R   s   wsgi.cleanupc         S   s   t  ƒ  d  S(   N(   t   cleanup(   RF   (    (    s^   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/modpython.pyt   cleanerá   s    s	   paste.inis	   config:%ss   wsgi.application(   R'   t   startupt   splitt
   __import__t   globalst   localsR    t   resolve_objectRO   t   register_cleanupR+   t   serverR,   RA   t   wsgiappsR   t   getattrR   RG   t   OK(   R   R7   t   funct   module_namet
   object_strt   moduleRP   t   appinit   appt   appwsgit   modnamet   objname(    (    s^   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/modpython.pyt   handlerÍ   s@    

	 (   t   __doc__R?   t
   mod_pythonR    t   paste.deployR   t   objectR   R   R0   R   RA   RQ   RO   RY   Re   (    (    (    s^   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/modpython.pys   <module>2   s   `