
    h!                        S r SSKrSSKrSSKrSSKrSSKJrJrJrJ	r	  SSK
JrJr  SSKJr  SSKJr  SSKJr  SSKJr   " S	 S
\5      r " S S5      r " S S5      rS r \R4                  rS rS\R:                  4S jr\	" S\S9r SS\\   S\\R:                     S\\   4S jjr \ r!S r"SS/r#g! \ a    SS jr NSf = f)zL
Plugin system for Twisted.

@author: Jp Calderone
@author: Glyph Lefkowitz
    N)IterableOptionalTypeTypeVar)	Interface
providedBy)log)getAdapterFactory)	getModule)namedAnyc                       \ rS rSrSrSrg)IPlugin   z
Interface that must be implemented by all plugins.

Only objects which implement this interface will be considered for return
by C{getPlugins}.  To be useful, plugins should also implement some other
application-specific interface.
 N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       U/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/plugin.pyr   r      s    r   r   c                   <    \ rS rSrS rS\4S jrS rS	S jr\r	Sr
g)
CachedPlugin&   c                 ~    Xl         X l        X0l        X@l        U R                   R                  R                  U 5        g N)dropinnamedescriptionprovidedpluginsappend)selfr   r   r    r!   s        r   __init__CachedPlugin.__init__'   s/    	& ""4(r   returnc           
          SR                  U R                  U R                  R                  SR	                  U R
                   Vs/ s H  oR                  PM     sn5      5      $ s  snf )Nz(<CachedPlugin {!r}/{!r} (provides {!r})>z, )formatr   r   
moduleNamejoinr!   r   )r$   is     r   __repr__CachedPlugin.__repr__.   sO    9@@IIKK""II4==9=azz=9:
 	
 :s   A%c                 `    [        U R                  R                  S-   U R                  -   5      $ )N.)r   r   r*   r   )r$   s    r   loadCachedPlugin.load5   s%    ..4tyy@AAr   Nc                     U R                    HQ  nUR                  U5      (       a  U R                  5       s  $ [        XAS 5      c  M:  U" U R                  5       U5      s  $    U$ r   )r!   isOrExtendsr1   r
   )r$   	interfaceregistrydefaultprovidedInterfaces        r   __conform__CachedPlugin.__conform__8   sV    !% ,,Y77yy{" !2tDP g66	 "/
 r   )r    r   r   r!   )NN)r   r   r   r   r%   strr-   r1   r9   getComponentr   r   r   r   r   r   &   s%    )
# 
B Lr   r   c                       \ rS rSrSrS rSrg)CachedDropinD   a  
A collection of L{CachedPlugin} instances from a particular module in a
plugin package.

@type moduleName: C{str}
@ivar moduleName: The fully qualified name of the plugin module this
    represents.

@type description: C{str} or L{None}
@ivar description: A brief explanation of this collection of plugins
    (probably the plugin module's docstring).

@type plugins: C{list}
@ivar plugins: The L{CachedPlugin} instances which were loaded from this
    dropin.
c                 *    Xl         X l        / U l        g r   )r*   r    r"   )r$   r*   r    s      r   r%   CachedDropin.__init__V   s    $&r   )r    r*   r"   N)r   r   r   r   r   r%   r   r   r   r   r>   r>   D   s    "r   r>   c                     [        U R                  U R                  5      nU R                  R	                  5        H?  u  p#[        US 5      nUc  M  [        XUR                  [        [        U5      5      5        MA     U$ r   )	r>   r   r   __dict__itemsr   r   listr   )providerr   kvplugins        r   _generateCacheEntryrJ   \   sh    (++X-=-=>F!!'')D!AIItJv4F/GH	 *
 Mr   c                 $    0 nU  H  nXU'   M	     U$ r   r   )keysvaluedrG   s       r   fromkeysrO   j   s    AaD r   c                    0 n[        U R                  5      n0 nUR                  5        H;  nUR                  R	                  5       nXS;  a  / X5'   X5   nUR                  U5        M=     UR                  5        GH8  u  pvUR                  S5      n UR                  5       n	UR                  S5       n
[        R                  " U
5      nSSS5        Sn0 nU Hm  nUR                  R                  S5      S   nSX'   UW;  d   UR                  R                  5       U	:  d  MK  Sn UR                  5       n[        U5      nUX'   Mo     [%        WR'                  5       5       H  nX;  d  M
  X	 SnM     U(       a&   UR)                  [        R*                  " U5      5        UR5                  U5        GM;     U$ ! , (       d  f       N= f! [         a    0 nSn	 GN	f = f! [         a    [         R"                  " 5          GM*  f = f! [,         a4  n[         R.                  " S	UR0                  UR2                  S
9   SnANSnAf[         a    [         R"                  " SS5         Nf = f)a#  
Compute all the possible loadable plugins, while loading as few as
possible and hitting the filesystem as little as possible.

@param module: a Python module object.  This represents a package to search
for plugins.

@return: a dictionary mapping module names to L{CachedDropin} instances.
zdropin.cacherNr   Fr0   Tz@Unable to write to plugin cache %(path)s: error number %(errno)d)r)   patherrnoz)Unexpected error while writing cache file)r   r   iterModulesfilePathparentr#   rD   childgetModificationTimeopenpickler1   BaseExceptionr   splitrJ   r	   errrE   rL   
setContentdumpsOSErrormsgrS   rT   update)moduleallCachesCombinedmodbucketsplugmodfppbucketpseudoPackagePath
dropinPath
lastCachedfdropinDotCache
needsWriteexistingKeyspluginModule	pluginKeyrF   entryes                      r   getCacherv   q   s2    
FOO
$CG ??$%%'GLg % &-]]_!&,,^<
	#779J%!'Q & 
"L$))//4R8I&*L#/%%99;zI!
6+002H
 09E05N- #  n1134I,"-!
 5 K%%fll>&BC 	  0] &5^ W &% 	NJ	 % GGII  + $'' ! KIJKs`   !G	2F8	G	%G;%H8
G	G	G		GGHH
I%*H>>$I%$I%r'   c                      SS K Jn   U $ )Nr   )twisted.pluginsr"   )packages    r   _pluginsPackagerz      s
    %Nr   _TInterface)boundr5   ry   c              #     #    Uc
  [        5       n[        U5      nUR                  5        H+  u  p4UR                   H  n U " US5      nUb  Uv   M  M     M-     g! [         a    [
        R                  " 5          MA  f = f7f)aG  
Retrieve all plugins implementing the given interface beneath the given module.

@param interface: An interface class.  Only plugins which implement this
interface will be returned.

@param package: A package beneath which plugins are installed.  For
most uses, the default value is correct.

@return: An iterator of plugins.
N)rz   rv   rD   r"   r\   r	   r^   )r5   ry   
allDropinskeyr   rI   adapteds          r   
getPluginsr      s}      !#'"J!'')nnF"#FD1 &!M ' % * ! 	s)   =B 	A	BA>:B=A>>Bc           
      z   U R                  S5      n[        R                   Vs/ s H  n[        R                  R	                  [        R                  R
                  " U/US/-   Q76 5      (       a  ML  [        R                  R                  [        R                  R
                  " U/UQ76 5      PM     sn$ s  snf )a  
Return a list of additional directories which should be searched for
modules to be included as part of the named plugin package.

@type name: C{str}
@param name: The fully-qualified Python name of a plugin package, eg
    C{'twisted.plugins'}.

@rtype: C{list} of C{str}
@return: The absolute paths to other directories which may contain plugin
    modules for the named plugin package.
r0   z__init__.py)r]   sysrS   osexistsr+   abspath)r   ry   xs      r   pluginPackagePathsr      s     jjoG Aww~~bggll1Iw-/HIJ 	3Q112  s   AB83AB8r   r   r   )$r   r   r[   r   typestypingr   r   r   r   zope.interfacer   r   twisted.pythonr	   twisted.python.componentsr
   twisted.python.modulesr   twisted.python.reflectr   r   r   r>   rJ   dictrO   AttributeErrorrv   
ModuleTyperz   r{   r   
getPlugInsr   __all__r   r   r   <module>r      s    
  
  4 4 0  7 , +i  < 0}}HIX))  m95 IM"K "+3E4D4D+E"k": 
< -
.y  s   "B4 4CC