
    h                     H   S r SSKrSSKrSSKJr  SSKJr  SSKJrJ	r	  SSK
Jr  SSKJrJrJrJrJr  Sr " S	 S
\5      r " S S5      r\R,                  " SS\5      rS rS r " S S\R4                  5      r " S S\R4                  5      r " S S\R4                  5      rg)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                       \ rS rSrSrSrg)AlreadyCached   z?
This exception is raised when a path has already been cached.
 N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       Y/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/web/script.pyr   r      s    r   r   c                   &    \ rS rSrS rS rS rSrg)CacheScanner$   c                 *    Xl         X l        SU l        g )Nr   )pathregistrydoCacheselfr   r   s      r   __init__CacheScanner.__init__%   s    	 r   c                     U R                   R                  U R                  5      nUb  [        U5      eU R	                  5         g N)r   getCachedPathr   r   recache)r!   cs     r   cacheCacheScanner.cache*   s3    MM''		2=""r   c                     SU l         g )N   )r   )r!   s    r   r'   CacheScanner.recache0   s	    r   )r   r   r   N)r   r   r   r   r"   r)   r'   r   r   r   r   r   r   $   s    
r   r     Whoops! Internal Errorc                 6   [        X5      n[        SU 5      [        UUR                  UR                  S.n [        XU5        US   nUR                  (       a  U[        La  UR                  X5        U$ ! [         a  nUR                  S   s SnA$ SnAff = f)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   ResourceScriptr:   7   s     
d	%B/D9::DT" 
D	zzd&(4&K  wwqzs   A5 5
B?BBBc                 
   SSK Jn  [        SU 5      [        R                  " SS[
        5      US.n[        U 5       nUR                  X@5      nS S S 5        [        WSS5      n[        XcU5        US	   $ ! , (       d  f       N,= f)
Nr   )ptl_compiler1   r.   r/   )r2   r	   r   z<source>execr	   )
quixoter<   r   r	   _UnsafeErrorPagerpyNoResourceopencompile_templatecompileeval)r   r   r<   r7   fecodes          r   ResourceTemplaterH   O   s~    # 0D9--)=
 D 
dq((1 
1j&)DT
	 
s   A44
Bc                   *    \ rS rSrSS jrS rS rSrg)ResourceScriptWrappera   Nc                     [         R                  R                  U 5        Xl        U=(       d    [        R
                  " 5       U l        g r%   r	   Resourcer"   r   r   Registryr   r    s      r   r"   ResourceScriptWrapper.__init__b   s.    ""4(	 5FOO$5r   c                 d    [        U R                  U R                  5      nUR                  U5      $ r%   )r:   r   r   render)r!   requestress      r   rR   ResourceScriptWrapper.renderg   s%    TYY6zz'""r   c                 d    [        U R                  U R                  5      nUR                  X5      $ r%   )r:   r   r   getChildWithDefault)r!   r   rS   rT   s       r   rW   )ResourceScriptWrapper.getChildWithDefaultk   s'    TYY6&&t55r   r   r   r%   )r   r   r   r   r"   rR   rW   r   r   r   r   rJ   rJ   a   s    6
#6r   rJ   c                   .    \ rS rSrSrSS jrS rS rSrg)	ResourceScriptDirectoryp   a  
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                     [         R                  R                  U 5        Xl        U=(       d    [        R
                  " 5       U l        g r%   rM   )r!   pathnamer   s      r   r"    ResourceScriptDirectory.__init__~   s.    ""4(	 5FOO$5r   c                 d   [         R                  R                  U R                  U5      n[         R                  R                  U5      (       a  [	        X0R
                  5      $ [         R                  R                  U5      (       a  [        X0R
                  5      $ [        R                  " 5       $ r%   )
osr   joinisdirr[   r   existsr:   r	   _UnsafeNoResource)r!   r   rS   fns       r   getChild ResourceScriptDirectory.getChild   sm    WW\\$))T*77==*2}}==77>>"!"mm44))++r   c                 J    [         R                  " 5       R                  U5      $ r%   )r	   re   rR   )r!   rS   s     r   rR   ResourceScriptDirectory.render   s    ))+227;;r   rY   r%   )	r   r   r   r   r   r"   rg   rR   r   r   r   r   r[   r[   p   s    6
,<r   r[   c                   (    \ rS rSrSrSrS rS rSrg)PythonScript   z
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                     Xl         X l        g)z#
Initialize me with a script name.
Nfilenamer   )r!   rp   r   s      r   r"   PythonScript.__init__   s     ! r   c                    UR                  S[        S[        R                  -  5      5        U[	        SU R
                  5      U R                  S.n [        U R
                  X"5        UR3                  5         [4        R6                  $ ! [         am  nUR                  S:X  aS  UR                  [        R                  5        UR                  [        R                  " S5      R!                  U5      5         SnANSnAf["         ah    [%        5       n[&        R(                  " US9  [*        R,                  " UR/                  5       5      nUR1                  S	5      nUR                  U5         GNf = f)
a  
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/%sr1   )rS   r2   r      zFile not found.N)fileutf8)	setHeaderr   r   versionr   rp   r   r   OSErrorerrnosetResponseCoder   	NOT_FOUNDwriter	   re   rR   BaseExceptionr   	traceback	print_excr   _PREgetvalueencodefinishr
   NOT_DONE_YET)r!   rS   	namespacerF   iooutputs         r   rR   PythonScript.render   s    	]<):K:K+KL	
 3BF
	
	"T]]I9 	"""  	ww!|''7../@AHHQ  	"BR(YYr{{}-F]]6*FMM&!	"s    B 
E/A#C::A1E/.E/ro   N)	r   r   r   r   r   isLeafr"   rR   r   r   r   r   rl   rl      s     F! #r   rl   )r   ra   r~   r   r   twistedr   twisted.python.compatr   r   twisted.python.filepathr   twisted.webr   r	   r
   r   r   r@   	Exceptionr   r   r?   r3   r:   rH   rN   rJ   r[   rl   r   r   r   <module>r      s   

 
    9 ? < <I    
	"	"3(@-	P0$6H-- 6<h// <@1#8$$ 1#r   