Ϫf!dZddlZddlZddlZddlZddlmZmZmZm Z ddl m Z m Z ddl mZddlmZddlmZddlmZGd d e ZGd d ZGd dZdZ ej4ZdZdej:fdZe de Z ddeedeej:deefdZ e Z!dZ"ddgZ#y#e$rddZYQwxYw)zL Plugin system for Twisted. @author: Jp Calderone @author: Glyph Lefkowitz N)IterableOptionalTypeTypeVar) Interface providedBy)log)getAdapterFactory) getModule)namedAnyceZdZdZy)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__0/usr/lib/python3/dist-packages/twisted/plugin.pyrrsrrc0eZdZdZdefdZdZddZeZy) CachedPluginc||_||_||_||_|jjj |yN)dropinname descriptionprovidedpluginsappend)selfrrrrs r__init__zCachedPlugin.__init__'s7  &   ""4(rreturnc dj|j|jjdj |j Dcgc]}|j c}Scc}w)Nz(z, )formatrr moduleNamejoinrr)r is r__repr__zCachedPlugin.__repr__.sM9@@ II KK " " II4==9aqzz9 :  :sA#c`t|jjdz|jzS)N.)r rr%r)r s rloadzCachedPlugin.load5s% ..4tyy@AArNc|jD]K}|j|r|jcSt||d4||j|cS|Sr)r isOrExtendsr+r )r interfaceregistrydefaultprovidedInterfaces r __conform__zCachedPlugin.__conform__8sZ!% 7  ,,Y7yy{" !2ItDP g66  7 r)NN) rrrr!strr(r+r2 getComponentrrrrr&s%) # BLrrceZdZdZdZy) 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.||_||_g|_yr)r%rr)r r%rs rr!zCachedDropin.__init__Vs$& rN)rrrrr!rrrr6r6Ds "rr6c t|j|j}|jj D]>\}}t |d}|t |||jtt|@|Sr) r6rr__dict__itemsrrlistr)providerrkvplugins r_generateCacheEntryr@\ss (++X-=-= >F!!'')I1D!   AIItJv4F/G H I Mrc"i}|D]}|||< |Srr)keysvaluedr=s rfromkeysrEjs$  AAaD rci}t|j}i}|jD];}|jj }||vrg||<||}|j |=|j D]*\}}|jd} |j} |jd5} tj| } dddd} i} |D]j}|jjdd}d| |<| vs|jj| k\sHd} |j}t|}|| |<lt% j'D] }|| vs| |=d} | r% |j)tj*| |j5| -|S#1swYxYw#t$ri} d} YwxYw#t$rt!j"YwxYw#t,$r6}t!j.d |j0|j2 Yd}~d}~wt$rt!j"dd YwxYw) 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 iterModulesfilePathparentrr:childgetModificationTimeopenpickler+ BaseExceptionrsplitr@r errr;rB setContentdumpsOSErrormsgrIrJupdate)moduleallCachesCombinedmodbucketsplugmodfppbucketpseudoPackagePath dropinPath lastCachedfdropinDotCache needsWrite existingKeys pluginModule pluginKeyr<entryes rgetCacherlqs` FOO $CG??$%%' g GCL g  &-]]_.1!6&,,^<  #779J% 0!'Q 0   " 6L$))//4R8I&*L #/%%99;zI! 6+002H 09E05N9- 6 n1134 "I ,"9-!  "  K%%fll>&BC   0].1^ W 0 0 NJ %GGI +$'' ! KIJ KsZ!F42F(F4!G.$G+(F1 -F44 GGG('G(+ I 4,H%%"I  I r"cddlm}|S)Nr)twisted.pluginsr)packages r_pluginsPackagerps % Nr _TInterface)boundr.roc#K| t}t|}|jD]'\}}|jD]} ||d}||)y#t$rt j Y8wxYww)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)rprlr:rrRr rT)r.ro allDropinskeyrr?adapteds r getPluginsrws!#'"J!'')" Vnn "F "#FD1&!M ""!   s/=A8 A A8 A8A52A84A55A8c b|jd}tjDcgc]}tjj tjj |g|dgzs=tjj tjj |g|c}Scc}w)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*z __init__.py)rSsysrIosexistsr&abspath)rroxs rpluginPackagePathsr~sjjoG  ww~~bggll1Iw-/HIJ  Q112  sBB,rwr~r)$rrzrQrytypestypingrrrrzope.interfacerrtwisted.pythonr twisted.python.componentsr twisted.python.modulesr twisted.python.reflectr rrr6r@dictrEAttributeErrorrl ModuleTyperprqrw getPlugInsr~__all__rrrrs  4407,+i<0}}HIX)) m95 IM"K "+3E4D4D+E" k": < - .ys" B44 C?C