o bG@sdZddlZddlZddlmZddlmZddlmZm Z ddl m Z ddl m Z mZmZmZmZdZGd d d eZGd d d Zed deZddZddZGdddejZGdddejZGdddejZdS)zH I contain PythonScript, which is a very simple python script resource. N)StringIO) copyright)execfile networkString)_coerceToFilesystemEncoding)httpresourceserverstaticutilz

You forgot to assign to the variable "resource" in your script. For example:

# MyCoolWebApp.rpy

import mygreatresource

resource = mygreatresource.MyGreatResource()
c@seZdZdZdS) AlreadyCachedzG This exception is raised when a path has already been cached. N)__name__ __module__ __qualname____doc__rr4/usr/lib/python3/dist-packages/twisted/web/script.pyr sr c@s$eZdZddZddZddZdS) CacheScannercCs||_||_d|_dS)Nr)pathregistrydoCacheselfrrrrr__init__%s zCacheScanner.__init__cCs*|j|j}|durt||dSN)r getCachedPathrr recache)rcrrrcache*s zCacheScanner.cachecCs d|_dS)N)r)rrrrr0s zCacheScanner.recacheN)r rrrrrrrrrr$s rWhoops! Internal Errorc Cst||}td|t||j|jd}zt|||Wnty1}z |jdWYd}~Sd}~ww|d}|jrC|turC| |||S)z I am a normal py file which must define a 'resource' global, which should be an instance of (a subclass of) web.resource.Resource; it will be renderred. )__file__rrrrrNr) rrnoRsrcrrrr argsr cachePath)rrcsglobacrsrcrrrResourceScript7s"  r+cCs|ddlm}td|tddt|d}t|}|||}Wdn1s)wYt|dd}t ||||d S) Nr) ptl_compiler"r r!)r#rrzexecr) quixoter,rr ErrorPage rpyNoResourceopencompile_templatecompileeval)rrr,r(fecoderrrResourceTemplateOs     r8c@s&eZdZdddZddZddZdS) ResourceScriptWrapperNcC$tj|||_|pt|_dSrrResourcerrr Registryrrrrrr` zResourceScriptWrapper.__init__cCst|j|j}||Sr)r+rrrender)rrequestresrrrr?es zResourceScriptWrapper.rendercCst|j|j}|||Sr)r+rrgetChildWithDefault)rrr@rArrrrBis z)ResourceScriptWrapper.getChildWithDefaultr)r rrrr?rBrrrrr9_s  r9c@s*eZdZdZd ddZddZddZdS) ResourceScriptDirectorya  L{ResourceScriptDirectory} is a resource which serves scripts from a filesystem directory. File children of a L{ResourceScriptDirectory} will be served using L{ResourceScript}. Directory children will be served using another L{ResourceScriptDirectory}. @ivar path: A C{str} giving the filesystem path in which children will be looked up. @ivar registry: A L{static.Registry} instance which will be used to decide how to interpret scripts found as children of this resource. NcCr:rr;)rpathnamerrrrr|r>z ResourceScriptDirectory.__init__cCsHtj|j|}tj|rt||jStj|r t||jSt Sr) osrjoinisdirrCrexistsr+r NoResource)rrr@fnrrrgetChilds     z ResourceScriptDirectory.getChildcCst|Sr)rrIr?)rr@rrrr?szResourceScriptDirectory.renderr)r rrrrrKr?rrrrrCns   rCc@s$eZdZdZdZddZddZdS) PythonScriptz I am an extremely simple dynamic resource; an embedded python script. This will execute a file (usually of the extension '.epy') as Python code, internal to the webserver. TcCs||_||_dS)z3 Initialize me with a script name. N)filenamer)rrMrrrrrs zPythonScript.__init__c Cs|dtdtj|td|j|jd}z t|j||WnJtyG}z|j dkr=| t j | td|WYd}~n'd}~wtyit}tj|dt|}|d }| |Ynw|tjS) a4 Render me to a web client. Load my file, execute it in a special namespace (with 'request' and '__file__' global vars) and finish the request. Output to the web-page will NOT be handled with print - standard output goes to the log - but with request.write. s x-powered-byz Twisted/%sr")r@r#rzFile not found.N)fileutf8) setHeaderrrversionrrMrrOSErrorerrnosetResponseCoder NOT_FOUNDwriterrIr? BaseExceptionr traceback print_excr _PREgetvalueencodefinishr NOT_DONE_YET)rr@ namespacer6iooutputrrrr?s.       zPythonScript.renderN)r rrrisLeafrr?rrrrrLs  rL)rrErYrartwistedrtwisted.python.compatrrtwisted.python.filepathr twisted.webrrr r r r0 Exceptionr rr/r$r+r8r<r9rCrLrrrrs"