� a�Nc@s�dZddlZyddlmZWnnXddlmZdefd��YZdefd��YZd Z d efd ��YZ da da iad �ZdS( 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(tapache(tloadappt InputWrappercBsGeZd�Zd�Zdd�Zdd�Zdd�Zd�ZRS(cCs ||_dS(N(treq(tselfR((s@/opt/alt/python27/lib/python2.7/site-packages/paste/modpython.pyt__init__>scCsdS(N((R((s@/opt/alt/python27/lib/python2.7/site-packages/paste/modpython.pytcloseAsi����cCs|jj|�S(N(Rtread(Rtsize((s@/opt/alt/python27/lib/python2.7/site-packages/paste/modpython.pyRDscCs|jj|�S(N(Rtreadline(RR((s@/opt/alt/python27/lib/python2.7/site-packages/paste/modpython.pyR GscCs|jj|�S(N(Rt readlines(Rthint((s@/opt/alt/python27/lib/python2.7/site-packages/paste/modpython.pyR Jsccs.|j�}x|r)|V|j�}qWdS(N(R (Rtline((s@/opt/alt/python27/lib/python2.7/site-packages/paste/modpython.pyt__iter__Ms  (t__name__t __module__RRRR R R (((s@/opt/alt/python27/lib/python2.7/site-packages/paste/modpython.pyR<s      t ErrorWrappercBs,eZd�Zd�Zd�Zd�ZRS(cCs ||_dS(N(R(RR((s@/opt/alt/python27/lib/python2.7/site-packages/paste/modpython.pyRXscCsdS(N((R((s@/opt/alt/python27/lib/python2.7/site-packages/paste/modpython.pytflush[scCs|jj|�dS(N(Rt log_error(Rtmsg((s@/opt/alt/python27/lib/python2.7/site-packages/paste/modpython.pytwrite^scCs|jdj|��dS(Nt(Rtjoin(Rtseq((s@/opt/alt/python27/lib/python2.7/site-packages/paste/modpython.pyt writelinesas(RRRRRR(((s@/opt/alt/python27/lib/python2.7/site-packages/paste/modpython.pyRVs   sfYou must provide a PythonOption '%s', either 'on' or 'off', when running a version of mod_python < 3.1tHandlercBs/eZd�Zd�Zdd�Zd�ZRS(cCs�t|_|j�}y+tj}|tj�}|tj�}Wn�tk r�|jdd�j �}|dkr}t }n%|dkr�t}nt t d��|jdd�j �}|dkr�t }q�|dkr�t}q�t t d��nXt tj|��}|_d|krL|d|d<|jt|d�|d<nd|d<|j|d<t|�|d<t|�|d <d|d <t|d <|jd�dkr�d|d<n d|d<||d<||d<||_dS(Nt multithreadRtontofft multiprocesst SCRIPT_NAMEt PATH_INFOs wsgi.inputs wsgi.errorsiis wsgi.versions wsgi.run_oncetHTTPStyest1thttpsswsgi.url_schemethttpswsgi.multithreadswsgi.multiprocess(ii(syesRR"(tFalsetstartedt get_optionsRt mpm_querytAP_MPMQ_IS_THREADEDtAP_MPMQ_IS_FORKEDtAttributeErrortgettlowertTruet ValueErrort bad_valuetdictt build_cgi_envtenvironturitlenRRtrequest(RRtoptionstqtthreadedtforkedtenv((s@/opt/alt/python27/lib/python2.7/site-packages/paste/modpython.pyRksF                     cCs�yo||j|j�}x|D]}|j|�qW|jsR|jjd�nt|d�rn|j�nWnntj d|jd�|js�d|j_ d|j_ d}|jjt |��|jj|�q�nXdS(NiRs wsgi.errorsi�s text/plains:A server error occurred. Please contact the administrator.(R3tstart_responseRR&R6tset_content_lengththasattrRt tracebackt print_exctNonetstatust content_typeR5(Rt applicationtresulttdata((s@/opt/alt/python27/lib/python2.7/site-packages/paste/modpython.pytrun�s      cCs�|r;z(|jr-|d|d|d�nWdd}Xnt|d �|j_xv|D]n\}}|j�dkr�|jjt|��qX|j�dkr�||j_qX|jjj ||�qXW|j S(Niiiiscontent-lengths content-type( R&RAtintR6RBR-R=RCt headers_outtaddR(RRBtheaderstexc_infotkeytval((s@/opt/alt/python27/lib/python2.7/site-packages/paste/modpython.pyR<�s  cCs)|jst|_n|jj|�dS(N(R&R.R6R(RRF((s@/opt/alt/python27/lib/python2.7/site-packages/paste/modpython.pyR�s  N(RRRRGRAR<R(((s@/opt/alt/python27/lib/python2.7/site-packages/paste/modpython.pyRis 2  c Cs|j�}d|kr�t r�|d}|r�|jdd�\}}t|t�t�dg�}tj||�at|�q�nd|kr9t r9|d}|r9|jdd�\}}t|t�t�dg�}tj||�ad�}ytj |�Wq6t k r2|j j ||�q6Xq9n|j d�}d}|r�|tkrwtd|�t|<nt|}n|j d �} | r�| r�| jdd�\} } t| t�t�dg�}t|| �}nt|�j|�tjS( Ns wsgi.startups::iRs wsgi.cleanupcSs t�dS(N(tcleanup(RF((s@/opt/alt/python27/lib/python2.7/site-packages/paste/modpython.pytcleaner�ss paste.inis config:%sswsgi.application(R'tstartuptsplitt __import__tglobalstlocalsRtresolve_objectROtregister_cleanupR+tserverR,RAtwsgiappsRtgetattrRRGtOK( RR7tfunct module_namet object_strtmoduleRPtappinitapptappwsgitmodnametobjname((s@/opt/alt/python27/lib/python2.7/site-packages/paste/modpython.pythandler�s@        (t__doc__R?t mod_pythonRt paste.deployRtobjectRRR0RRARQRORYRe(((s@/opt/alt/python27/lib/python2.7/site-packages/paste/modpython.pyt<module>2s `