
    \d!                        d Z ddlZddlZddlZddlZddlmZmZmZm	Z	 ddl
mZmZ ddlmZ ddlmZ ddlmZ ddlmZ  G d	 d
e          Z G d d          Z G d d          Zd Z	 ej        Zn# e$ r ddZY nw xY wd Zdej        fdZ e	de          Z	 ddee         deej                 dee         fdZ e Z!d Z"ddgZ#dS )zL
Plugin system for Twisted.

@author: Jp Calderone
@author: Glyph Lefkowitz
    N)IterableOptionalTypeTypeVar)	Interface
providedBy)log)getAdapterFactory)	getModule)namedAnyc                       e Zd ZdZdS )IPluginz
    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____doc__     .lib/python3.11/site-packages/twisted/plugin.pyr   r      s           r   r   c                   2    e Zd Zd ZdefdZd ZddZeZdS )CachedPluginc                 |    || _         || _        || _        || _        | j         j                            |            d S N)dropinnamedescriptionprovidedpluginsappend)selfr   r   r   r   s        r   __init__zCachedPlugin.__init__'   s>    	& ""4(((((r   returnc                     d                     | j        | j        j        d                    d | j        D                                 S )Nz(<CachedPlugin {!r}/{!r} (provides {!r})>z, c                     g | ]	}|j         
S r   )r   ).0is     r   
<listcomp>z)CachedPlugin.__repr__.<locals>.<listcomp>2   s    999aqz999r   )formatr   r   
moduleNamejoinr   r    s    r   __repr__zCachedPlugin.__repr__.   sG    9@@IK"II994=999::
 
 	
r   c                 J    t          | j        j        dz   | j        z             S )N.)r   r   r)   r   r+   s    r   loadzCachedPlugin.load5   s!    .4ty@AAAr   Nc                     | j         D ]^}|                    |          r|                                 c S t          ||d             ||                                 |          c S _|S r   )r   isOrExtendsr/   r
   )r    	interfaceregistrydefaultprovidedInterfaces        r   __conform__zCachedPlugin.__conform__8   s|    !% 	7 	7 ,,Y77 #yy{{""" !2ItDDP yg66666 Qr   )NN)	r   r   r   r!   strr,   r/   r6   getComponentr   r   r   r   r   &   se        ) ) )
# 
 
 
 
B B B    LLLr   r   c                       e Zd ZdZd ZdS )CachedDropina  
    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                 0    || _         || _        g | _        d S r   )r)   r   r   )r    r)   r   s      r   r!   zCachedDropin.__init__V   s    $&r   N)r   r   r   r   r!   r   r   r   r:   r:   D   s-         "    r   r:   c                     t          | j        | j                  }| j                                        D ]H\  }}t          |d           }|1t          |||j        t          t          |                               I|S r   )	r:   r   r   __dict__itemsr   r   listr   )providerr   kvplugins        r   _generateCacheEntryrD   \   s|    (+X-=>>F!'')) I I1D!!AItJv4F4F/G/GHHHMr   c                     i }| D ]}|||<   |S r   r   )keysvaluedrA   s       r   fromkeysrI   j   s&     	 	AAaDDr   c                    i }t          | j                  }i }|                                D ]A}|j                                        }||vrg ||<   ||         }|                    |           B|                                D ]\  }}|                    d          }	 |                                }	|	                    d          5 }
t          j        |
          }ddd           n# 1 swxY w Y   n# t          $ r i }d}	Y nw xY wd}i }|D ]}|j                            d          d         }d||<   ||vs|j                                        |	k    rOd}	 |                                }t          |          }|||<   t# t          $ r t!          j                     Y w xY wt%          |                                          D ]}||vr||= d}|r	 |                    t          j        |                     nX# t,          $ r+}t!          j        d	|j        |j        
           Y d}~n(d}~wt          $ r t!          j        dd           Y nw xY w|                    |           |S )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   Fr.   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   r>   childgetModificationTimeopenpickler/   BaseExceptionr   splitrD   r	   errr?   rF   
setContentdumpsOSErrormsgrM   rN   update)moduleallCachesCombinedmodbucketsplugmodfppbucketpseudoPackagePath
dropinPath
lastCachedfdropinDotCache
needsWriteexistingKeyspluginModule	pluginKeyr@   entryes                      r   getCacherp   q   sL    
FO
$
$CG ??$$  %%''gGCLg%,]]__ .1 .1!6&,,^<<
	#7799J%% 0!'Q0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 	 	 	NJJJ	 
" 	6 	6L$)//44R8I&*L#//%99;;zII!
6+0022H
 099E05N9-- %   GIIIII J n113344 	" 	"I,,"9-!
 	KK%%fl>&B&BCCCC   + $'         ! K K KIJJJJJK  0000sf   )C5C)C5)C-	-C50C-	1C55DDFF#"F#'G??
I	!H//"IIr"   c                      dd l m}  | S )Nr   )twisted.pluginsr   )packages    r   _pluginsPackagert      s    %%%%%%Nr   _TInterface)boundr2   rs   c              #      K   |t                      }t          |          }|                                D ]E\  }}|j        D ]8}	  | |d          }||V  # t          $ r t          j                     Y 5w xY wFdS )ac  
    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)rt   rp   r>   r   rV   r	   rX   )r2   rs   
allDropinskeyr   rC   adapteds          r   
getPluginsr{      s       !##'""J!'')) " "Vn 	" 	"F"#)FD11 &!MMM	 !   						"" "s   AA87A8c                 ^    |                      d          fdt          j        D             S )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.
    r.   c           	          g | ]n}t           j                            t          j        j        |gd gz   R            :t           j                            t          j        j        |gR            oS )z__init__.py)osrM   existsr*   abspath)r%   xrs   s     r   r'   z&pluginPackagePaths.<locals>.<listcomp>   sz       w~~bgl1Iw-/HIIIJJ
Q111122  r   )rW   sysrM   )r   rs   s    @r   pluginPackagePathsr      sA     jjooG      r   r{   r   r   )$r   r~   rU   r   typestypingr   r   r   r   zope.interfacer   r   twisted.pythonr	   twisted.python.componentsr
   twisted.python.modulesr   twisted.python.reflectr   r   r   r:   rD   dictrI   AttributeErrorrp   
ModuleTypert   ru   r{   
getPlugInsr   __all__r   r   r   <module>r      sA    
			  



  4 4 4 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0 0 0       7 7 7 7 7 7 , , , , , , + + + + + +    i          <       0  }HH        I I IX)     gm9555 IM" "K "+3E4D+E"k" " " ": 
  < -
.s   +A3 3	A?>A?