o b!@s<dZddlZddlZddlZddlZddlmZmZmZm Z ddl m Z m Z ddl mZddlmZddlmZddlmZGd d d e ZGd d d ZGd ddZddZzejZWneykd ddZYnwddZdejfddZe de dZ d deedeejdeefddZ e Z!ddZ"ddgZ#dS)!zL Plugin system for Twisted. @author: Jp Calderone @author: Glyph Lefkowitz N)IterableOptionalTypeTypeVar) Interface providedBy)log)getAdapterFactory) getModule)namedAnyc@seZdZdZdS)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__rr0/usr/lib/python3/dist-packages/twisted/plugin.pyr sr c@s8eZdZddZdefddZddZd d d ZeZdS) CachedPlugincCs*||_||_||_||_|jj|dSN)dropinname descriptionprovidedpluginsappend)selfrrrrrrr__init__'s zCachedPlugin.__init__returncCs&d|j|jjddd|jDS)Nz(z, cSsg|]}|jqSr)r ).0irrr 2sz)CachedPlugin.__repr__..)formatrr moduleNamejoinrrrrr__repr__.s zCachedPlugin.__repr__cCst|jjd|jS)N.)r rr"rr$rrrload5szCachedPlugin.loadNcCsH|jD]}||r|St||ddur!|||Sq|Sr)r isOrExtendsr'r )r interfaceregistrydefaultprovidedInterfacerrr __conform__8s   zCachedPlugin.__conform__)NN) r rrrstrr%r'r- getComponentrrrrr&s   rc@seZdZdZddZdS) 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. cCs||_||_g|_dSr)r"rr)rr"rrrrrVs zCachedDropin.__init__N)r rrrrrrrrr0Ds r0cCsPt|j|j}|jD]\}}t|d}|dur%t|||jtt|q |Sr) r0r r__dict__itemsr rlistr)providerrkvpluginrrr_generateCacheEntry\s r8cCsi}|D]}|||<q|Srr)keysvaluedr5rrrfromkeysjs r<c Csi}t|j}i}|D]}|j}||vrg||<||}||q |D]\}}|d}z |} | d } t | } Wdn1sMwYWn t y`i} d} Ynwd} i} |D]7}|j dd}d| |<|| vs|j| krd} z| }Wn t ytYqgwt|}|| |<qgt| D] }|| vr| |=d} q| rz |t | Wn*ty}ztjd |j|jd WYd}~nd}~wt ytdd Ynw|| q*|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.cacherNrFr&Tz@Unable to write to plugin cache %(path)s: error number %(errno)d)r!patherrnoz)Unexpected error while writing cache file)r r iterModulesfilePathparentrr2childgetModificationTimeopenpickler' BaseExceptionrsplitrerrr8r3r9 setContentdumpsOSErrormsgr?r@update)moduleallCachesCombinedmodbucketsplugmodfppbucketpseudoPackagePath dropinPath lastCachedfdropinDotCache needsWrite existingKeys pluginModule pluginKeyr4entryerrrgetCacheqsr             rbrcCsddlm}|S)Nr)twisted.pluginsrpackagerrr_pluginsPackages rf _TInterface)boundr)rec csr|durt}t|}|D]&\}}|jD]}z||d}Wn ty-tYqw|dur5|VqqdS)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)rfrbr2rrHrrJ)r)re allDropinskeyrr7adaptedrrr getPluginss    rlcs|dfddtjDS)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&csJg|]!}tjtjj|gdgRstjtjj|gRqS)z __init__.py)osr?existsr#abspath)rxrdrrr s  z&pluginPackagePaths..)rIsysr?)rrrdrpluginPackagePathss rrr)$rrmrGrqtypestypingrrrrzope.interfacerrtwisted.pythonrtwisted.python.componentsr twisted.python.modulesr twisted.python.reflectr r rr0r8dictr<AttributeErrorrb ModuleTyperfrgrl getPlugInsrr__all__rrrrsD        L