Ë
    oj!  ã                   ó†  — 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j4                  Z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#y# e$ r dd„ZY ŒQw xY w)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y)Ú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.pyr   r      s   „ òr   r   c                   ó0   — e Zd Zd„ Zdefd„Zd„ Zdd„ZeZy)ÚCachedPluginc                 ó†   — || _         || _        || _        || _        | j                   j                  j                  | «       y ©N)ÚdropinÚnameÚdescriptionÚprovidedÚpluginsÚappend)Úselfr   r   r   r   s        r   Ú__init__zCachedPlugin.__init__'   s7   € ØˆŒØˆŒ	Ø&ˆÔØ ˆŒØ�‰×Ñ×"Ñ" 4Õ(r   Úreturnc           
      óÐ   — dj                  | j                  | j                  j                  dj	                  | j
                  D �cg c]  }|j                  ‘Œ c}«      «      S c c}w )Nz(<CachedPlugin {!r}/{!r} (provides {!r})>z, )Úformatr   r   Ú
moduleNameÚjoinr   r   )r    Úis     r   Ú__repr__zCachedPlugin.__repr__.   sM   € Ø9×@Ñ@Ø�I‰IØ�K‰K×"Ñ"Ø�I‰I¨4¯=©=Ö9 a�q—z“zÒ9Ó:ó
ð 	
ùò :s   ÁA#c                 ó`   — t        | j                  j                  dz   | j                  z   «      S )Nú.)r   r   r%   r   )r    s    r   ÚloadzCachedPlugin.load5   s%   € Ü˜Ÿ™×.Ñ.°Ñ4°t·y±yÑ@ÓAÐAr   Nc                 óº   — | j                   D ]K  }|j                  |«      r| j                  «       c S t        ||d «      €Œ4 || j                  «       |«      c S  |S r   )r   ÚisOrExtendsr+   r
   )r    Ú	interfaceÚregistryÚdefaultÚprovidedInterfaces        r   Ú__conform__zCachedPlugin.__conform__8   sZ   € Ø!%§¡ò 	7ÐØ ×,Ñ,¨YÔ7Ø—y‘y“{Ò"Ü Ð!2°I¸tÓDÑPÙ  §¡£¨gÓ6Ò6ð		7ð
 ˆr   )NN)	r   r   r   r!   Ústrr(   r+   r2   ÚgetComponentr   r   r   r   r   &   s%   „ ò)ð
˜#ó 
òBóð �Lr   r   c                   ó   — e Zd ZdZd„ Zy)Ú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 | _        y 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   r6   r6   D   s   „ ñó"r   r6   c                 óü   — t        | j                  | j                  «      }| j                  j	                  «       D ]>  \  }}t        |d «      }|€Œt        |||j                  t        t        |«      «      «       Œ@ |S r   )	r6   r   r   Ú__dict__Úitemsr   r   Úlistr   )Úproviderr   ÚkÚvÚplugins        r   Ú_generateCacheEntryr@   \   ss   € Ü˜(×+Ñ+¨X×-=Ñ-=Ó>€FØ×!Ñ!×'Ñ'Ó)ò I‰ˆˆ1Ü˜˜DÓ!ˆØÑä˜  A§I¡I¬t´J¸vÓ4FÓ/GÕHð	Ið
 €Mr   c                 ó"   — i }| D ]  }|||<   Œ	 |S r   r   )ÚkeysÚvalueÚdr=   s       r   ÚfromkeysrE   j   s$   € ØˆØò 	ˆAØˆAˆaŠDð	àˆr   c                 óš  — i }t        | j                  «      }i }|j                  «       D ];  }|j                  j	                  «       }||vrg ||<   ||   }|j                  |«       Œ= |j                  «       D �]*  \  }}|j                  d«      }	 |j                  «       }	|j                  d«      5 }
t        j                  |
«      }ddd«       d}i }|D ]j  }|j                  j                  d«      d   }d||<   |vs|j                  j                  «       |	k\  sŒHd}	 |j                  «       }t        |«      }|||<   Œl t%        j'                  «       «      D ]  }||vsŒ||= d}Œ |r%	 |j)                  t        j*                  |«      «       |j5                  |«       �Œ- |S # 1 sw Y   ŒáxY w# t        $ r i }d}	Y Œów xY w# t        $ r t!        j"                  «        Y �Œw xY w# t,        $ r6}t!        j.                  d	|j0                  |j2                  ¬
«       Y d}~Œ“d}~wt        $ r t!        j"                  dd«       Y Œ·w xY w)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   Úsplitr@   r	   Úerrr;   rB   Ú
setContentÚdumpsÚOSErrorÚmsgrI   rJ   Úupdate)ÚmoduleÚallCachesCombinedÚmodÚbucketsÚplugmodÚfppÚbucketÚpseudoPackagePathÚ
dropinPathÚ
lastCachedÚfÚdropinDotCacheÚ
needsWriteÚexistingKeysÚpluginModuleÚ	pluginKeyr<   ÚentryÚes                      r   ÚgetCacherl   q   s`  € ð ÐÜ
�F—O‘OÓ
$€Cà€Gð —?‘?Ó$ò ˆØ×Ñ×%Ñ%Ó'ˆØ�gÑØˆG�C‰LØ˜‘ˆØ�‰�gÕðð &-§]¡]£_ó .1Ñ!Ð˜6Ø&×,Ñ,¨^Ó<ˆ
ð	Ø#×7Ñ7Ó9ˆJØ—‘ Ó%ð 0¨Ü!'§¡¨Q£�÷0ð ˆ
ØˆØ"ò 	6ˆLØ$×)Ñ)×/Ñ/°Ó4°RÑ8ˆIØ&*ˆL˜Ñ#Ø Ñ/Ø×%Ñ%×9Ñ9Ó;¸zÓIà!�
ð6Ø+×0Ñ0Ó2�Hô
 0°Ó9�EØ05�N 9Ò-ð	6ô  ˜n×1Ñ1Ó3Ó4ò 	"ˆIØ Ò,Ø" 9Ð-Ø!‘
ð	"ñ ðKØ×%Ñ%¤f§l¡l°>Ó&BÔCð 	× Ñ  Ö0ð].1ð^ Ð÷W0ð 0ûäò 	ØˆNØŠJð	ûô %ò ä—G‘G—Iðûô ò Ü—‘ð+ð $Ÿ™ØŸ'™'÷ò ûô !ò KÜ—‘˜ÐIÖJðKúsZ   Â!F4Â2F(ÃF4Ä!GÅ.$G+Æ(F1	Æ-F4Æ4GÇGÇG(Ç'G(Ç+	I
Ç4,H%È%"I
É	I
r"   c                  ó   — dd l m}  | S )Nr   )Útwisted.pluginsr   )Úpackages    r   Ú_pluginsPackagerp   ½   s
   € Ý%à€Nr   Ú_TInterface)Úboundr.   ro   c              #   óô   K  — |€
t        «       }t        |«      }|j                  «       D ]'  \  }}|j                  D ]  }	  | |d«      }|€Œ|–— Œ Œ) y# t        $ r t        j                  «        Y Œ8w xY w­w)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)rp   rl   r:   r   rR   r	   rT   )r.   ro   Ú
allDropinsÚkeyr   r?   Úadapteds          r   Ú
getPluginsrw   Æ   s…   è ø€ ð €Ü!Ó#ˆÜ˜'Ó"€JØ!×'Ñ'Ó)ò "‰ˆˆVØ—n‘nò 	"ˆFð"Ù# F¨DÓ1�ð Ñ&Ø!“Mñ	"ñ"øô !ò Ü—‘–	ðüs/   ‚=A8Á 	AÁ	A8Á	A8ÁA5Á2A8Á4A5Á5A8c           
      ób  — | j                  d«      }t        j                  D �cg c]€  }t        j                  j	                  t        j                  j
                  |g|dgz   ¢­Ž «      s=t        j                  j                  t        j                  j
                  |g|¢­Ž «      ‘Œ‚ c}S c c}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)rS   ÚsysrI   ÚosÚexistsr&   Úabspath)r   ro   Úxs      r   ÚpluginPackagePathsr~   æ   s   € ð �j‰j˜‹o€Gô —‘öàÜ�w‰w�~‰~œbŸg™gŸl™l¨1ÐI¨w¸-¸Ñ/HÒIÔJô 	�‰�‰œŸ™Ÿ™ QÐ1¨Ò1Õ2òð ùò s   ¤BB,rw   r~   r   )$r   rz   rQ   ry   ÚtypesÚtypingr   r   r   r   Úzope.interfacer   r   Útwisted.pythonr	   Útwisted.python.componentsr
   Útwisted.python.modulesr   Útwisted.python.reflectr   r   r   r6   r@   ÚdictrE   ÚAttributeErrorrl   Ú
ModuleTyperp   rq   rw   Ú
getPlugInsr~   Ú__all__r   r   r   ú<module>r‹      sð   ðñó 
Û Û 
Û ß 4Ó 4ç 0å Ý 7Ý ,Ý +ôˆiô ÷ñ ÷<ñ ò0ðØ�}‰}€HòIðX˜×)Ñ)ó ñ �m¨9Ô5€ð IMñ"Ø�KÑ ð"Ø+3°E×4DÑ4DÑ+Eð"àˆkÑó"ð: €
òð< Ð-Ð
.�øðy ò õðús   Á"B4 Â4	C Â?C 