ó »ÏâIc@sËdZddlZddlZddlZddlmZmZddlmZd„Z ddd„ƒYZ e Z e a d„Ze d „ZddlZddlZd d „Zd efd „ƒYZdS(sINative adapter for serving CherryPy via mod_python Basic usage: ########################################## # Application in a module called myapp.py ########################################## import cherrypy class Root: @cherrypy.expose def index(self): return 'Hi there, Ho there, Hey there' # We will use this method from the mod_python configuration # as the entry point to our application def setup_server(): cherrypy.tree.mount(Root()) cherrypy.config.update({'environment': 'production', 'log.screen': False, 'show_tracebacks': False}) ########################################## # mod_python settings for apache2 # This should reside in your httpd.conf # or a file that will be loaded at # apache startup ########################################## # Start DocumentRoot "/" Listen 8080 LoadModule python_module /usr/lib/apache2/modules/mod_python.so PythonPath "sys.path+['/path/to/my/application']" SetHandler python-program PythonHandler cherrypy._cpmodpy::handler PythonOption cherrypy.setup myapp::setup_server PythonDebug On # End The actual path to your mod_python.so is dependent on your environment. In this case we suppose a global mod_python installation on a Linux distribution such as Ubuntu. We do set the PythonPath configuration setting so that your application can be found by from the user running the apache2 instance. Of course if your application resides in the global site-package this won't be needed. Then restart apache2 and access http://127.0.0.1:8080 iÿÿÿÿN(t format_exct bare_error(thttpc s²ddlm‰ˆjƒ}d|kr²|djddƒ}t|ƒdkrot|dtƒtƒƒ}q²|\}}t|tƒtƒ|gƒ}t||ƒ}|ƒnt j j it d6t d6d gd 6ƒt j‰tˆd ƒrˆjjƒntˆd ƒr!ˆjjƒnˆjjƒt jjƒ‡‡fd †}ˆjd|ƒˆjƒ‡fd†}yˆj|ƒWn$tk r­ˆjjˆ|ƒnXdS(Niÿÿÿÿ(tapachescherrypy.setups::iis log.screenstools.ignore_headers.ontRangestools.ignore_headers.headerstsignal_handlertconsole_control_handlercstˆj}tj|kr$ˆj}n6tj|kr?ˆj}ntj|krZˆj}nˆj||ˆj ƒdS(N( t APLOG_ERRtloggingtDEBUGt APLOG_DEBUGtINFOt APLOG_INFOtWARNINGt APLOG_WARNINGt log_errortserver(tmsgtleveltnewlevel(Rtreq(s7/usr/lib/python2.7/vendor-packages/cherrypy/_cpmodpy.pyt_logcs    tlogcsˆjƒdS(N(texit(tdata(tengine(s7/usr/lib/python2.7/vendor-packages/cherrypy/_cpmodpy.pytcherrypy_cleanupss(t mod_pythonRt get_optionstsplittlent __import__tglobalstlocalstgetattrtcherrypytconfigtupdatetFalsetTrueRthasattrRt unsubscribeRt autoreloadRt subscribetstarttregister_cleanuptAttributeError( RtoptionstatomstmodtmodnametfnametfuncRR((RRRs7/usr/lib/python2.7/vendor-packages/cherrypy/_cpmodpy.pytsetupGs8          t_ReadOnlyRequestcBseZdZd„ZRS(treadtreadlinet readlinescCs.x'|jD]}t||ƒ|j|(((s7/usr/lib/python2.7/vendor-packages/cherrypy/_cpmodpy.pyR6|scCsòddlm}yŠts,t|ƒtan|jj}tj|d|d|jj p[dƒ}|jj }tj|d|d|jj pdƒ}|j dp¦d}|j ƒy+|j}||jƒ}||jƒ}Wn»tk r›d}tjddƒjƒ}|d kr!t}n%|d kr6t}nt|dƒ‚tjd dƒjƒ}|d krst}qœ|d krˆt}qœt|d ƒ‚nXtjj|jp±d ƒ} | dkrÙt|d gdƒnÀtjj| } |j} |j} |jpd} |j }|j!j"ƒ}t#|ƒ}d}zWg}x(trg| j$|||dƒ\}}|j%|_&t'|ƒ|_(t'|ƒ|_)| |_*||_+y!|j,| | | |||ƒPWq@tj-k rc}| j.ƒ|}t/s<|j0|krt1d|j0ƒ‚q<| r$d| } n|j2| | | ƒnd} |j0} |j3} t4j4ƒ}q@Xq@Wt||j5|j6|j7|j8ƒWd| j.ƒXWnNt9ƒ}tj:|ddt;j<ƒt=ƒ\}}}t||||ƒnX|j>S(Niÿÿÿÿ(RiitRsfYou must provide a PythonOption '%s', either 'on' or 'off', when running a version of mod_python < 3.1t multithreadtontofft multiprocesst/s 404 Not FoundsHTTP/1.1s1InternalRedirector visited the same URL twice: %rt?tGETt MOD_PYTHONtseverity(?RRt_isSetUpR5R't connectiont local_addrRtHostt local_hostt remote_addrt remote_hostt parsed_uritget_basic_auth_pwt mpm_querytAP_MPMQ_IS_THREADEDtAP_MPMQ_IS_FORKEDR.R/tgettlowerR&t ValueErrorR#ttreet script_nameturitNonet send_responsetappsR=targstprotocolt headers_intitemsR6t get_servingtusertlogintboolRBREtapptprevtruntInternalRedirecttrelease_servingt recursivetpatht RuntimeErrortappendt query_stringtStringIOtstatust header_listtbodytstreamRRRtERRORRtOK(RRtlocaltremotetschemetqtthreadedtforkedt bad_valuetsnRhR=RntqstreqprototheaderstrfileRit redirectionstrequesttresponsetirttbtsthtb((s7/usr/lib/python2.7/vendor-packages/cherrypy/_cpmodpy.pythandler†s˜   ) )                         cCs»t|d ƒ|_d|_xH|D]@\}}|jƒdkrP||_q#n|jj||ƒq#W|rz|jƒnt|tƒr™|j |ƒnx|D]}|j |ƒq WdS(Nis text/plains content-type( tintRst content_typeRXt headers_outtaddtflusht isinstancet basestringtwrite(RRsRƒRuRvtheadertvaluetseg((s7/usr/lib/python2.7/vendor-packages/cherrypy/_cpmodpy.pyR^ís    RAcCs|tjd||fƒ\}}zK|jƒ}tjd|tjƒrYtd|ƒ‚n||jƒ}Wd|jƒX|S(Ns%s %ss'(not recognized|No such file|not found)s%s must be on your system path.( tostpopen4R8tretsearcht IGNORECASEtIOErrorR7tclose(tcmdR`tpipeintpipeoutt firstlinetoutput((s7/usr/lib/python2.7/vendor-packages/cherrypy/_cpmodpy.pyt read_process s    tModPythonServercBs8eZdZdddddd„Zd„Zd„ZRS( s # Apache2 server configuration file for running CherryPy with mod_python. DocumentRoot "/" Listen %(port)s LoadModule python_module modules/mod_python.so SetHandler python-program PythonHandler %(handler)s PythonDebug On %(opts)s RFiPRscherrypy._cpmodpy::handlercCs1||_||_||_||_||_dS(N(tloctporttoptst apache_pathR(R<R§R¨R©RªR((s7/usr/lib/python2.7/vendor-packages/cherrypy/_cpmodpy.pyR>+s     cCsÙdjg|jD]\}}d||f^qƒ}|ji|jd6|jd6|d6|jd6}tjjtjjt ƒdƒ}t |dƒ}z|j |ƒWd|j ƒXt |jd |ƒ}t|_|S( NRAs PythonOption %s %s R¨R§R©Rs cpmodpy.conftwbs-k start -f %s(tjoinR©ttemplateR¨R§RR™Rntdirnamet__file__topenR•RŸR¥RªR'tready(R<tktvR©t conf_datatmpconftfR‡((s7/usr/lib/python2.7/vendor-packages/cherrypy/_cpmodpy.pyR,3s , !  cCstjdƒt|_dS(Nsapache -k stop(R™tpopenR&R±(R<((s7/usr/lib/python2.7/vendor-packages/cherrypy/_cpmodpy.pytstopGs N(R?R@R­R]R>R,R¸(((s7/usr/lib/python2.7/vendor-packages/cherrypy/_cpmodpy.pyR¦s    ((t__doc__RRrR#tcherrypy._cperrorRRt cherrypy.libRR5R6R&RmRKRR^R™R›R¥tobjectR¦(((s7/usr/lib/python2.7/vendor-packages/cherrypy/_cpmodpy.pyt8s    5 g