Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib64/python3.7/site-packages/twisted/web/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/site-packages/twisted/web/__pycache__/script.cpython-37.pyc

B

;��]q�@s�dZddlmZmZddlZddlZddlmZddlm	Z	ddl
mZmZm
Z
mZddlmZmZmZmZmZdZGd	d
�d
e�ZGdd�d�Ze�d
de�Zdd�Zdd�ZGdd�dej�ZGdd�dej�ZGdd�dej�Z dS)zH
I contain PythonScript, which is a very simple python script resource.
�)�division�absolute_importN)�	copyright)�_coerceToFilesystemEncoding)�execfile�
networkString�NativeStringIO�_PY3)�http�server�static�resource�utilz�<p>You forgot to assign to the variable "resource" in your script. For example:</p>
<pre>
# MyCoolWebApp.rpy

import mygreatresource

resource = mygreatresource.MyGreatResource()
</pre>
c@seZdZdZdS)�
AlreadyCachedzG
    This exception is raised when a path has already been cached.
    N)�__name__�
__module__�__qualname__�__doc__�rr�E/opt/alt/python37/lib64/python3.7/site-packages/twisted/web/script.pyrsrc@s$eZdZdd�Zdd�Zdd�ZdS)�CacheScannercCs||_||_d|_dS)Nr)�path�registry�doCache)�selfrrrrr�__init__#szCacheScanner.__init__cCs*|j�|j�}|dk	rt|��|��dS)N)rZ
getCachedPathrr�recache)r�crrr�cache(szCacheScanner.cachecCs
d|_dS)N�)r)rrrrr.szCacheScanner.recacheN)rrrrrrrrrrr"sri�zWhoops! Internal Errorc
Cs�t||�}td|�t||j|jd�}yt|||�Wn(tk
r\}z
|jdSd}~XYnX|d}|jr�|tk	r�|�	||�|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__r
rrrrNr
)
rr�noRsrcrrrr�argsrZ	cachePath)rr�cs�globZacZrsrcrrr�ResourceScript3s

r&c	Cshddlm}td|�t�ddt�|d�}t|��}|�||�}WdQRXt|dd�}t	|||�|d	S)
Nr)�ptl_compiler i�zWhoops! Internal Error)r!r
rz<source>�execr
)
Zquixoter'rr
�	ErrorPage�
rpyNoResource�openZcompile_template�compile�eval)rrr'r%�f�e�coderrr�ResourceTemplateJs
r1c@s&eZdZddd�Zdd�Zdd�ZdS)	�ResourceScriptWrapperNcCs$tj�|�||_|pt��|_dS)N)r
�Resourcerrr�Registryr)rrrrrrr\szResourceScriptWrapper.__init__cCst|j|j�}|�|�S)N)r&rr�render)r�request�resrrrr5aszResourceScriptWrapper.rendercCst|j|j�}|�||�S)N)r&rr�getChildWithDefault)rrr6r7rrrr8esz)ResourceScriptWrapper.getChildWithDefault)N)rrrrr5r8rrrrr2Zs
r2c@s*eZdZdZd	dd�Zdd�Zdd�ZdS)
�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.
    NcCs$tj�|�||_|pt��|_dS)N)r
r3rrrr4r)r�pathnamerrrrrxsz ResourceScriptDirectory.__init__cCsHtj�|j|�}tj�|�r(t||j�Stj�|�r@t||j�St�	�S)N)
�osr�join�isdirr9r�existsr&r
�
NoResource)rrr6�fnrrr�getChild}sz ResourceScriptDirectory.getChildcCst���|�S)N)r
r?r5)rr6rrrr5�szResourceScriptDirectory.render)N)rrrrrrAr5rrrrr9ks
	r9c@s$eZdZdZdZdd�Zdd�ZdS)�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)rrCrrrrr�szPythonScript.__init__c
Cs�|�dtdtj��|td|j�|jd�}yt|j||�Wn�tk
r�}z0|j	dkr||�
tj�|�
t�d��|��Wdd}~XYnDt�}tj|d�t�|���}tr�|�d	�}|�
|�YnX|��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 )r6r!r�zFile not found.N)�file�utf8)Z	setHeaderrr�versionrrCrr�IOError�errnoZsetResponseCoder
Z	NOT_FOUND�writer
r?r5r�	traceback�	print_excrZ_PRE�getvaluer	�encodeZfinishrZNOT_DONE_YET)rr6�	namespacer/�io�outputrrrr5�s&	


&
zPythonScript.renderN)rrrrZisLeafrr5rrrrrB�srB)!r�
__future__rrr;rKZtwistedrZtwisted.python.filepathrZtwisted.python.compatrrrr	Ztwisted.webr
rrr
rr*�	Exceptionrrr)r"r&r1r3r2r9rBrrrr�<module>s