ó
—‰]c           @   s  d  d l  Z  d  d l Z d d l m Z d d l m Z d d l m Z m Z m	 Z	 m
 Z
 d  d l Z e j d d f k rŽ d  d l m Z n d  d l Z d	 „  Z d
 e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ e e  d ƒ r d „  Z n	 d „  Z d S(   iÿÿÿÿNi   (   t   _tracing(   t   _Result(   t   HookImplt
   _HookRelayt   _HookCallert   normalize_hookimpl_optsi   i   (   t   metadatac         C   s2   t  j |  t |  ƒ d | j j d | j j ƒd  S(   Nt   linenot   filename(   t   warningst   warn_explicitt   typet   __code__t   co_firstlinenot   co_filename(   t   warningt   function(    (    s-   lib/python2.7/site-packages/pluggy/manager.pyt   _warn_for_function   s
    t   PluginValidationErrorc           B   s   e  Z d  Z d „  Z RS(   sŽ    plugin failed validation.

    :param object plugin: the plugin which failed validation,
        may be a module or an arbitrary object.
    c         C   s#   | |  _  t t |  ƒ j | ƒ d  S(   N(   t   plugint   supert	   Exceptiont   __init__(   t   selfR   t   message(    (    s-   lib/python2.7/site-packages/pluggy/manager.pyR      s    	(   t   __name__t
   __module__t   __doc__R   (    (    (    s-   lib/python2.7/site-packages/pluggy/manager.pyR      s   t
   DistFacadec           B   s;   e  Z d  Z d „  Z e d „  ƒ Z d d „ Z d „  Z RS(   s$   Emulate a pkg_resources Distributionc         C   s   | |  _  d  S(   N(   t   _dist(   R   t   dist(    (    s-   lib/python2.7/site-packages/pluggy/manager.pyR   &   s    c         C   s   |  j  d S(   Nt   name(   R   (   R   (    (    s-   lib/python2.7/site-packages/pluggy/manager.pyt   project_name)   s    c         C   s   t  |  j | | ƒ S(   N(   t   getattrR   (   R   t   attrt   default(    (    s-   lib/python2.7/site-packages/pluggy/manager.pyt   __getattr__-   s    c         C   s   t  t |  j ƒ d d g ƒ S(   NR   R    (   t   sortedt   dirR   (   R   (    (    s-   lib/python2.7/site-packages/pluggy/manager.pyt   __dir__0   s    N(	   R   R   R   R   t   propertyR    t   NoneR$   R'   (    (    (    s-   lib/python2.7/site-packages/pluggy/manager.pyR   #   s
   	t   PluginManagerc           B   sõ   e  Z d  Z d d „ Z d „  Z d d „ Z d „  Z d d d „ Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s   Core Pluginmanager class which manages registration
    of plugin objects and 1:N hook calling.

    You can register new hooks by calling ``add_hookspecs(module_or_class)``.
    You can register plugin objects (which contain hooks) by calling
    ``register(plugin)``.  The Pluginmanager is initialized with a
    prefix that is searched for in the names of the dict of registered
    plugin objects.

    For debugging purposes you can call ``enable_tracing()``
    which will subsequently send debug information to the trace helper.
    c         C   s†   | |  _  i  |  _ i  |  _ g  |  _ t j ƒ  j d ƒ |  _ t ƒ  |  _	 | d k	 rm t j d t d d ƒn  | |  _ d „  |  _ d S(   su   If ``implprefix`` is given implementation functions
        will be recognized if their name matches the implprefix. t   pluginmanagesy   Support for the `implprefix` arg is now deprecated and will be removed in an upcoming release. Please use HookimplMarker.t
   stackleveli   c         S   s4   |  j  | | d |  j r- |  j j j d ƒ n t ƒS(   Nt   firstresult(   t	   multicallt   spect   optst   gett   False(   t   hookt   methodst   kwargs(    (    s-   lib/python2.7/site-packages/pluggy/manager.pyt   <lambda>S   s   N(   R    t   _name2plugint   _plugin2hookcallerst   _plugin_distinfoR    t	   TagTracerR1   t   traceR   R3   R)   R	   t   warnt   DeprecationWarningt   _implprefixt   _inner_hookexec(   R   R    t
   implprefix(    (    s-   lib/python2.7/site-packages/pluggy/manager.pyR   B   s    				
	c         C   s   |  j  | | | ƒ S(   N(   R?   (   R   R3   R4   R5   (    (    s-   lib/python2.7/site-packages/pluggy/manager.pyt	   _hookexecY   s    c   	      C   sˆ  | p |  j  | ƒ } | |  j k s3 | |  j k rq |  j j | d ƒ d k rR d St d | | |  j f ƒ ‚ n  | |  j | <g  |  j | <} xò t | ƒ D]ä } |  j | | ƒ } | d k	 rœ t | ƒ t	 | | ƒ } t
 | | | | ƒ } t	 |  j | d ƒ } | d k r7t | |  j ƒ } t |  j | | ƒ n, | j ƒ  rc|  j | | ƒ | j | ƒ n  | j | ƒ | j | ƒ qœ qœ W| S(   s«    Register a plugin and return its canonical name or None if the name
        is blocked from registering.  Raise a ValueError if the plugin is already
        registered. iÿÿÿÿNs#   Plugin already registered: %s=%s
%s(   t   get_canonical_nameR7   R8   R1   R)   t
   ValueErrorR&   t   parse_hookimpl_optsR   R!   R   R3   R   RA   t   setattrt   has_spect   _verify_hookt   _maybe_apply_historyt   _add_hookimplt   append(	   R   R   R   t   plugin_namet   hookcallerst   hookimpl_optst   methodt   hookimplR3   (    (    s-   lib/python2.7/site-packages/pluggy/manager.pyt   register^   s2    
c         C   sÅ   t  | | ƒ } t j | ƒ s" d  Sy t  | |  j d d  ƒ } Wn t k
 rX i  } n X| d  k	 r~ t | t ƒ r~ d  } nC | d  k rÁ |  j rÁ | j	 |  j ƒ rÁ t
 t d ƒ | ƒ i  } n  | S(   Nt   _implsh   The `implprefix` system is deprecated please decorate this function using an instance of HookimplMarker.(   R!   t   inspectt	   isroutineR    R)   R   t
   isinstancet   dictR>   t
   startswithR   R=   (   R   R   R   RN   t   res(    (    s-   lib/python2.7/site-packages/pluggy/manager.pyRD   ƒ   s     
	'	c         C   s¤   | d k r6 | d k	 s$ t d ƒ ‚ |  j | ƒ } n  | d k rT |  j | ƒ } n  |  j j | ƒ rs |  j | =n  x* |  j j | g  ƒ D] } | j | ƒ q‰ W| S(   sn    unregister a plugin object and all its contained hook implementations
        from internal data structures. s+   one of name or plugin needs to be specifiedN(	   R)   t   AssertionErrort   get_namet
   get_pluginR7   R1   R8   t   popt   _remove_plugin(   R   R   R   t
   hookcaller(    (    s-   lib/python2.7/site-packages/pluggy/manager.pyt
   unregisterš   s    c         C   s!   |  j  d | ƒ d |  j | <d S(   sJ    block registrations of the given name, unregister if already registered. R   N(   R^   R)   R7   (   R   R   (    (    s-   lib/python2.7/site-packages/pluggy/manager.pyt   set_blocked­   s    c         C   s    | |  j  k o |  j  | d k S(   s2    return True if the given plugin name is blocked. N(   R7   R)   (   R   R   (    (    s-   lib/python2.7/site-packages/pluggy/manager.pyt
   is_blocked²   s    c         C   s÷   g  } xÈ t  | ƒ D]º } |  j | | ƒ } | d k	 r t |  j | d ƒ } | d k r† t | |  j | | ƒ } t |  j | | ƒ n7 | j | | ƒ x$ | j	 ƒ  D] } |  j
 | | ƒ q£ W| j | ƒ q q W| só t d |  j | f ƒ ‚ n  d S(   s    add new hook specifications defined in the given module_or_class.
        Functions are recognized if they have been decorated accordingly. s   did not find any %r hooks in %rN(   R&   t   parse_hookspec_optsR)   R!   R3   R   RA   RE   t   set_specificationt   get_hookimplsRG   RJ   RC   R    (   R   t   module_or_classt   namesR   t	   spec_optst   hct   hookfunction(    (    s-   lib/python2.7/site-packages/pluggy/manager.pyt   add_hookspecs¶   s    c         C   s&   t  | | ƒ } t  | |  j d d  ƒ S(   Nt   _spec(   R!   R    R)   (   R   Rd   R   RN   (    (    s-   lib/python2.7/site-packages/pluggy/manager.pyRa   Í   s    c         C   s   t  |  j ƒ S(   s'    return the set of registered plugins. (   t   setR8   (   R   (    (    s-   lib/python2.7/site-packages/pluggy/manager.pyt   get_pluginsÑ   s    c         C   s   | |  j  k S(   s2    Return True if the plugin is already registered. (   R8   (   R   R   (    (    s-   lib/python2.7/site-packages/pluggy/manager.pyt   is_registeredÕ   s    c         C   s"   t  | d d ƒ p! t t | ƒ ƒ S(   s	   Return canonical name for a plugin object. Note that a plugin
        may be registered under a different name which was specified
        by the caller of register(plugin, name). To obtain the name
        of an registered plugin use ``get_name(plugin)`` instead.R   N(   R!   R)   t   strt   id(   R   R   (    (    s-   lib/python2.7/site-packages/pluggy/manager.pyRB   Ù   s    c         C   s   |  j  j | ƒ S(   s-    Return a plugin or None for the given name. (   R7   R1   (   R   R   (    (    s-   lib/python2.7/site-packages/pluggy/manager.pyRZ   à   s    c         C   s   |  j  | ƒ d k	 S(   s<    Return True if a plugin with the given name is registered. N(   RZ   R)   (   R   R   (    (    s-   lib/python2.7/site-packages/pluggy/manager.pyt
   has_pluginä   s    c         C   s4   x- |  j  j ƒ  D] \ } } | | k r | Sq Wd S(   s>    Return name for registered plugin or None if not registered. N(   R7   t   items(   R   R   R   t   val(    (    s-   lib/python2.7/site-packages/pluggy/manager.pyRY   è   s    c         C   s¼   | j  ƒ  r: | j r: t | j d | j | j f ƒ ‚ n  | j j r_ t | j j | j	 ƒ n  t
 | j ƒ t
 | j j ƒ } | r¸ t | j d | j | j t | j	 ƒ | f ƒ ‚ n  d  S(   Ns6   Plugin %r
hook %r
historic incompatible to hookwrappers~   Plugin %r for hook %r
hookimpl definition: %s
Argument(s) %s are declared in the hookimpl but can not be found in the hookspec(   t   is_historict   hookwrapperR   R   RK   R   R/   t   warn_on_implR   R   Rk   t   argnamest
   _formatdef(   R   R3   RO   t	   notinspec(    (    s-   lib/python2.7/site-packages/pluggy/manager.pyRG   î   s     c         C   s‘   xŠ |  j  j D]| } | d d k r t |  j  | ƒ } | j ƒ  s‰ xB | j ƒ  D]1 } | j sN t | j d | | j f ƒ ‚ qN qN Wq‰ q q Wd S(   sŒ    Verify that all hooks which have not been verified against
        a hook specification are optional, otherwise raise PluginValidationErrori    t   _s   unknown hook %r in plugin %rN(   R3   t   __dict__R!   RF   Rc   t   optionalhookR   R   (   R   R   R3   RO   (    (    s-   lib/python2.7/site-packages/pluggy/manager.pyt   check_pending  s    	c         C   sÑ   d } xÄ t  j ƒ  D]¶ } x­ | j D]¢ } | j | k s# | d k	 rS | j | k s# |  j | j ƒ s# |  j | j ƒ r} q# n  | j ƒ  } |  j	 | d | j ƒ|  j
 j | t | ƒ f ƒ | d 7} q# Wq W| S(   s+   Load modules from querying the specified setuptools ``group``.

        :param str group: entry point group to load plugins
        :param str name: if given, loads only plugins with the given ``name``.
        :rtype: int
        :return: return the number of loaded plugins by this call.
        i    R   i   N(   t   importlib_metadatat   distributionst   entry_pointst   groupR)   R   RZ   R`   t   loadRP   R9   RJ   R   (   R   R€   R   t   countR   t   epR   (    (    s-   lib/python2.7/site-packages/pluggy/manager.pyt   load_setuptools_entrypoints  s    c         C   s   t  |  j ƒ S(   sV    return list of distinfo/plugin tuples for all setuptools registered
        plugins. (   t   listR9   (   R   (    (    s-   lib/python2.7/site-packages/pluggy/manager.pyt   list_plugin_distinfo/  s    c         C   s   t  |  j j ƒ  ƒ S(   s#    return list of name/plugin pairs. (   R…   R7   Rq   (   R   (    (    s-   lib/python2.7/site-packages/pluggy/manager.pyt   list_name_plugin4  s    c         C   s   |  j  j | ƒ S(   s0    get all hook callers for the specified plugin. (   R8   R1   (   R   R   (    (    s-   lib/python2.7/site-packages/pluggy/manager.pyt   get_hookcallers8  s    c            s=   ˆ j  ‰ ‡  ‡ ‡ f d †  } | ˆ _  ‡ ‡ f d †  } | S(   sB   add before/after tracing functions for all hooks
        and return an undo function which, when called,
        will remove the added tracers.

        ``before(hook_name, hook_impls, kwargs)`` will be called ahead
        of all hook calls and receive a hookcaller instance, a list
        of HookImpl instances and the keyword arguments for the hook call.

        ``after(outcome, hook_name, hook_impls, kwargs)`` receives the
        same arguments as ``before`` but also a :py:class:`_Result`` object
        which represents the result of the overall hook call.
        c            sT   ˆ ˆ  j  ˆ ˆ ƒ t j ‡  ‡ ‡ ‡ f d †  ƒ } ˆ | ˆ  j  ˆ ˆ ƒ | j ƒ  S(   Nc              s   ˆ ˆ  ˆ ˆ ƒ S(   N(    (    (   R3   t
   hook_implsR5   t   oldcall(    s-   lib/python2.7/site-packages/pluggy/manager.pyR6   M  t    (   R   R   t	   from_callt
   get_result(   R3   R‰   R5   t   outcome(   t   aftert   beforeRŠ   (   R3   R‰   R5   s-   lib/python2.7/site-packages/pluggy/manager.pyt   traced_hookexecK  s    !c              s   ˆ  ˆ _  d  S(   N(   R?   (    (   RŠ   R   (    s-   lib/python2.7/site-packages/pluggy/manager.pyt   undoS  s    (   R?   (   R   R   R   R‘   R’   (    (   R   R   RŠ   R   s-   lib/python2.7/site-packages/pluggy/manager.pyt   add_hookcall_monitoring<  s
    		c            sC   |  j  j j d ƒ ‰  ‡  f d †  } ‡  f d †  } |  j | | ƒ S(   s;    enable tracing of hook calls and return an undo function. R3   c            s#   ˆ  j  j d 7_ ˆ  |  | ƒ d  S(   Ni   (   t   roott   indent(   t	   hook_nameR4   R5   (   t	   hooktrace(    s-   lib/python2.7/site-packages/pluggy/manager.pyR   \  s    c            sA   |  j  d  k r+ ˆ  d | d |  j ƒ  ƒ n  ˆ  j j d 8_ d  S(   Nt   finishs   -->i   (   t   excinfoR)   R   R”   R•   (   RŽ   R–   R4   R5   (   R—   (    s-   lib/python2.7/site-packages/pluggy/manager.pyR   `  s    (   R;   R”   R1   R“   (   R   R   R   (    (   R—   s-   lib/python2.7/site-packages/pluggy/manager.pyt   enable_tracingX  s    c   	      C   sÇ   t  |  j | ƒ } g  | D] } t | | ƒ r | ^ q } | rÃ t | j | j | j j | j j ƒ } xU | j	 ƒ  D]G } | j
 } | | k rt | j | ƒ |  j j | g  ƒ j | ƒ qt qt W| S| S(   s›    Return a new _HookCaller instance for the named method
        which manages calls to all registered plugins except the
        ones from remove_plugins. (   R!   R3   t   hasattrR   R   RA   R/   t	   namespaceR0   Rc   R   RI   R8   t
   setdefaultRJ   (	   R   R   t   remove_pluginst   origt   plugt   plugins_to_removeRg   RO   R   (    (    s-   lib/python2.7/site-packages/pluggy/manager.pyt   subset_hook_callerg  s    ($	#N(   R   R   R   R)   R   RA   RP   RD   R^   R_   R`   Ri   Ra   Rl   Rm   RB   RZ   Rp   RY   RG   R|   R„   R†   R‡   Rˆ   R“   Rš   R¢   (    (    (    s-   lib/python2.7/site-packages/pluggy/manager.pyR*   4   s2   	%																		t	   signaturec         C   s    d |  j  t t j |  ƒ ƒ f S(   Ns   %s%s(   R   Rn   RR   R£   (   t   func(    (    s-   lib/python2.7/site-packages/pluggy/manager.pyRw   ~  s    c         C   s#   d |  j  t j t j |  ƒ Œ  f S(   Ns   %s%s(   R   RR   t   formatargspect
   getargspec(   R¤   (    (    s-   lib/python2.7/site-packages/pluggy/manager.pyRw   „  s    (   RR   t   sysR‹   R    t   callersR   t   hooksR   R   R   R   R	   t   version_infot	   importlibR   R}   R   R   R   t   objectR   R*   R›   Rw   (    (    (    s-   lib/python2.7/site-packages/pluggy/manager.pyt   <module>   s    "		ÿ I