Ë
    ojŽ  ã                   óH  — d Z ddlZddlZddlmZ ddlmZ ddlmZm	Z	 ddl
mZ ddlmZmZmZmZmZ dZ G d	„ d
e«      Z G d„ d«      Z ej,                  dde«      Zd„ Zd„ Z G d„ dej4                  «      Z G d„ dej4                  «      Z G d„ dej4                  «      Zy)zH
I contain PythonScript, which is a very simple python script resource.
é    N)ÚStringIO)Ú	copyright)ÚexecfileÚnetworkString)Ú_coerceToFilesystemEncoding)ÚhttpÚresourceÚserverÚstaticÚ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                   ó   — e Zd ZdZy)ÚAlreadyCachedzG
    This exception is raised when a path has already been cached.
    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© ó    ú4/usr/lib/python3/dist-packages/twisted/web/script.pyr   r      s   „ òr   r   c                   ó   — e Zd Zd„ Zd„ Zd„ Zy)ÚCacheScannerc                 ó.   — || _         || _        d| _        y )Nr   )ÚpathÚregistryÚdoCache©Úselfr   r   s      r   Ú__init__zCacheScanner.__init__%   s   € ØˆŒ	Ø ˆŒØˆ�r   c                 óˆ   — | j                   j                  | j                  «      }|�t        |«      ‚| j	                  «        y ©N)r   ÚgetCachedPathr   r   Úrecache)r   Úcs     r   ÚcachezCacheScanner.cache*   s3   € Ø�M‰M×'Ñ'¨¯	©	Ó2ˆØˆ=Ü Ó"Ð"Ø�‰�r   c                 ó   — d| _         y )Né   )r   )r   s    r   r"   zCacheScanner.recache0   s	   € Øˆ�r   N)r   r   r   r   r$   r"   r   r   r   r   r   $   s   „ òò
ór   r   éô  úWhoops! Internal Errorc                 ó.  — t        | |«      }t        d| «      t        ||j                  |j                  dœ}	 t        | ||«       |d   }|j                  r|t        ur|j                  | |«       |S # t        $ r}|j                  d   cY d}~S d}~ww xY w)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	   r   r$   r"   r   Nr	   )
r   r   ÚnoRsrcr$   r"   r   r   Úargsr   Ú	cachePath)r   r   ÚcsÚglobÚacÚrsrcs         r   ÚResourceScriptr3   7   s•   € ô 
�d˜HÓ	%€Bä/°°DÓ9ÜØØ—‘Ø—:‘:ñ€DðÜ��t˜TÔ"ð �
Ñ€DØ	‡z‚z�d¤&Ñ(Ø×Ñ˜4 Ô&Ø€Køô ò Ø�w‰w�q‰zÕûðús   ¸A2 Á2	BÁ;BÂ	BÂBc                 ó  — ddl m} t        d| «      t        j                  ddt
        «      |dœ}t        | «      5 }|j                  || «      }d d d «       t        dd«      }t        |||«       |d	   S # 1 sw Y   Œ(xY w)
Nr   )Úptl_compiler*   r'   r(   )r+   r	   r   z<source>Úexecr	   )
Úquixoter5   r   r	   Ú_UnsafeErrorPageÚrpyNoResourceÚopenÚcompile_templateÚcompileÚeval)r   r   r5   r0   ÚfÚeÚcodes          r   ÚResourceTemplaterA   O   sŠ   € Ý#ô 0°°DÓ9Ü×-Ñ-ØÐ)¬=ó
ð ñ€Dô 
ˆd‹ð 2�qØ×(Ñ(¨¨DÓ1ˆ÷2ä�1�j &Ó)€DÜˆˆt�TÔØ�
ÑÐ÷	2ð 2ús   »A5Á5A>c                   ó    — e Zd Zdd„Zd„ Zd„ Zy)ÚResourceScriptWrapperNc                 óŠ   — t         j                  j                  | «       || _        |xs t	        j
                  «       | _        y r    ©r	   ÚResourcer   r   r   ÚRegistryr   r   s      r   r   zResourceScriptWrapper.__init__b   s0   € Ü×Ñ×"Ñ" 4Ô(ØˆŒ	Ø Ò5¤F§O¡OÓ$5ˆ�r   c                 ód   — t        | j                  | j                  «      }|j                  |«      S r    )r3   r   r   Úrender)r   ÚrequestÚress      r   rI   zResourceScriptWrapper.renderg   s%   € Ü˜TŸY™Y¨¯©Ó6ˆØ�z‰z˜'Ó"Ð"r   c                 óf   — t        | j                  | j                  «      }|j                  ||«      S r    )r3   r   r   ÚgetChildWithDefault)r   r   rJ   rK   s       r   rM   z)ResourceScriptWrapper.getChildWithDefaultk   s)   € Ü˜TŸY™Y¨¯©Ó6ˆØ×&Ñ& t¨WÓ5Ð5r   r    )r   r   r   r   rI   rM   r   r   r   rC   rC   a   s   „ ó6ò
#ó6r   rC   c                   ó$   — e Zd ZdZdd„Zd„ Zd„ Zy)Ú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.
    Nc                 óŠ   — t         j                  j                  | «       || _        |xs t	        j
                  «       | _        y r    rE   )r   Úpathnamer   s      r   r   z ResourceScriptDirectory.__init__~   s0   € Ü×Ñ×"Ñ" 4Ô(ØˆŒ	Ø Ò5¤F§O¡OÓ$5ˆ�r   c                 óR  — t         j                  j                  | j                  |«      }t         j                  j                  |«      rt	        || j
                  «      S t         j                  j                  |«      rt        || j
                  «      S t        j                  «       S r    )
Úosr   ÚjoinÚisdirrO   r   Úexistsr3   r	   Ú_UnsafeNoResource)r   r   rJ   Úfns       r   ÚgetChildz ResourceScriptDirectory.getChildƒ   sk   € Ü�W‰W�\‰\˜$Ÿ)™) TÓ*ˆä�7‰7�=‰=˜ÔÜ*¨2¨t¯}©}Ó=Ð=Ü�7‰7�>‰>˜"ÔÜ! " d§m¡mÓ4Ð4Ü×)Ñ)Ó+Ð+r   c                 óH   — t        j                  «       j                  |«      S r    )r	   rW   rI   )r   rJ   s     r   rI   zResourceScriptDirectory.renderŒ   s   € Ü×)Ñ)Ó+×2Ñ2°7Ó;Ð;r   r    )r   r   r   r   r   rY   rI   r   r   r   rO   rO   p   s   „ ñó6ò
,ó<r   rO   c                   ó    — e Zd ZdZdZd„ Zd„ Zy)Ú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.
    Tc                 ó    — || _         || _        y)z3
        Initialize me with a script name.
        N)Úfilenamer   )r   r^   r   s      r   r   zPythonScript.__init__š   s   € ð !ˆŒØ ˆ�r   c                 óà  — |j                  dt        dt        j                  z  «      «       |t	        d| j
                  «      | j                  dœ}	 t        | j
                  ||«       |j3                  «        t4        j6                  S # t        $ rk}|j                  dk(  rR|j                  t        j                  «       |j                  t        j                  d«      j!                  |«      «       Y d}~Œ�d}~wt"        $ ri t%        «       }t'        j(                  |¬«       t+        j,                  |j/                  «       «      }|j1                  d	«      }|j                  |«       Y �Œw xY w)
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*   )rJ   r+   r   é   zFile not found.N)ÚfileÚutf8)Ú	setHeaderr   r   Úversionr   r^   r   r   ÚOSErrorÚerrnoÚsetResponseCoder   Ú	NOT_FOUNDÚwriter	   rW   rI   ÚBaseExceptionr   Ú	tracebackÚ	print_excr   Ú_PREÚgetvalueÚencodeÚfinishr
   ÚNOT_DONE_YET)r   rJ   Ú	namespacer?   ÚioÚoutputs         r   rI   zPythonScript.render¡   s  € ð 	×ÑØœ]¨<¼)×:KÑ:KÑ+KÓLô	
ð Ü3°B¸¿¹ÓFØŸ™ñ
ˆ	ð
	"Ü�T—]‘] I¨yÔ9ð 	�‰ÔÜ×"Ñ"Ð"øô ò 	Ø�w‰w˜!Š|Ø×'Ñ'¬¯©Ô7Ø—‘Ü×.Ñ.Ð/@ÓA×HÑHÈÓQôÿøô ò 	"Ü“ˆBÜ×Ñ RÕ(Ü—Y‘Y˜rŸ{™{›}Ó-ˆFØ—]‘] 6Ó*ˆFØ�M‰M˜&×!ð	"ús    ÁB	 Â		E-ÂA!C8Ã8A1E-Å,E-N)r   r   r   r   ÚisLeafr   rI   r   r   r   r\   r\   �   s   „ ñð €Fò!ó #r   r\   )r   rS   rk   rs   r   Útwistedr   Útwisted.python.compatr   r   Útwisted.python.filepathr   Útwisted.webr   r	   r
   r   r   r9   Ú	Exceptionr   r   r8   r,   r3   rA   rF   rC   rO   r\   r   r   r   ú<module>r{      s›   ðñ
ó
 
Û Ý å ß 9Ý ?ß <Õ <ð€ô�Iô ÷ñ ð  
#ˆ×	"Ñ	" 3Ð(@À-Ó	P€òò0ô$6˜H×-Ñ-ô 6ô<˜h×/Ñ/ô <ô@1#�8×$Ñ$õ 1#r   