ó
—‰]c           @   s  d  Z  d d l Z d d l Z d d l Z d d l m Z m Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ	 d	 „  Z
 e e d
 ƒ r d „  Z n	 d „  Z e e d ƒ o· e j j d k Z d „  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   sA   
Internal hook annotation, representation and calling machinery.
iÿÿÿÿNi   (   t   _legacymulticallt
   _multicallt   HookspecMarkerc           B   s,   e  Z d  Z d „  Z d e e d d „ Z RS(   s   Decorator helper class for marking functions as hook specifications.

    You can instantiate it with a project_name to get a decorator.
    Calling PluginManager.add_hookspecs later will discover all marked functions
    if the PluginManager uses the same project_name.
    c         C   s   | |  _  d  S(   N(   t   project_name(   t   selfR   (    (    s+   lib/python2.7/site-packages/pluggy/hooks.pyt   __init__   s    c            s6   ‡  ‡ ‡ ‡ f d †  } | d k	 r. | | ƒ S| Sd S(   sA   if passed a function, directly sets attributes on the function
        which will make it discoverable to add_hookspecs().  If passed no
        function, returns a decorator which can be applied to a function
        later using the attributes supplied.

        If firstresult is True the 1:N hook call (N being the number of registered
        hook implementation functions) will stop at I<=N when the I'th function
        returns a non-None result.

        If historic is True calls to a hook will be memorized and replayed
        on later registered plugins.

        c      
      sK   ˆ r ˆ  r t  d ƒ ‚ n  t |  ˆ j d t d ˆ  d ˆ d ˆ ƒ ƒ |  S(   Ns'   cannot have a historic firstresult hookt   _spect   firstresultt   historict   warn_on_impl(   t
   ValueErrort   setattrR   t   dict(   t   func(   R   R   R   R	   (    s+   lib/python2.7/site-packages/pluggy/hooks.pyt   setattr_hookspec_opts&   s    

N(   t   None(   R   t   functionR   R   R	   R   (    (   R   R   R   R	   s+   lib/python2.7/site-packages/pluggy/hooks.pyt   __call__   s    
N(   t   __name__t
   __module__t   __doc__R   R   t   FalseR   (    (    (    s+   lib/python2.7/site-packages/pluggy/hooks.pyR   
   s   	t   HookimplMarkerc           B   s/   e  Z d  Z d „  Z d e e e e d „ Z RS(   s   Decorator helper class for marking functions as hook implementations.

    You can instantiate with a project_name to get a decorator.
    Calling PluginManager.register later will discover all marked functions
    if the PluginManager uses the same project_name.
    c         C   s   | |  _  d  S(   N(   R   (   R   R   (    (    s+   lib/python2.7/site-packages/pluggy/hooks.pyR   B   s    c            s9   ‡  ‡ ‡ ‡ ‡ f d †  } | d k r+ | S| | ƒ Sd S(   sz   if passed a function, directly sets attributes on the function
        which will make it discoverable to register().  If passed no function,
        returns a decorator which can be applied to a function later using
        the attributes supplied.

        If optionalhook is True a missing matching hook specification will not result
        in an error (by default it is an error if no matching spec is found).

        If tryfirst is True this hook implementation will run as early as possible
        in the chain of N hook implementations for a specification.

        If trylast is True this hook implementation will run as late as possible
        in the chain of N hook implementations.

        If hookwrapper is True the hook implementations needs to execute exactly
        one "yield".  The code before the yield is run early before any non-hookwrapper
        function is run.  The code after the yield is run after all non-hookwrapper
        function have run.  The yield receives a ``_Result`` object representing
        the exception or result outcome of the inner calls (including other hookwrapper
        calls).

        c            s6   t  |  ˆ j d t d ˆ  d ˆ d ˆ d ˆ ƒ ƒ |  S(   Nt   _implt   hookwrappert   optionalhookt   tryfirstt   trylast(   R   R   R   (   R   (   R   R   R   R   R   (    s+   lib/python2.7/site-packages/pluggy/hooks.pyt   setattr_hookimpl_optse   s    

N(   R   (   R   R   R   R   R   R   R   (    (   R   R   R   R   R   s+   lib/python2.7/site-packages/pluggy/hooks.pyR   E   s     N(   R   R   R   R   R   R   R   (    (    (    s+   lib/python2.7/site-packages/pluggy/hooks.pyR   :   s   	c         C   sD   |  j  d t ƒ |  j  d t ƒ |  j  d t ƒ |  j  d t ƒ d  S(   NR   R   R   R   (   t
   setdefaultR   (   t   opts(    (    s+   lib/python2.7/site-packages/pluggy/hooks.pyt   normalize_hookimpl_optsx   s    t   getfullargspecc         C   s   t  j |  ƒ S(   N(   t   inspectR    (   R   (    (    s+   lib/python2.7/site-packages/pluggy/hooks.pyt   _getargspec   s    c         C   s   t  j |  ƒ S(   N(   R!   t
   getargspec(   R   (    (    s+   lib/python2.7/site-packages/pluggy/hooks.pyR"   ‡   s    t   pypy_version_infoi   c         C   s»  t  |  d i  ƒ } y | d SWn t k
 r1 n Xt j |  ƒ rl y |  j }  Wq¯ t k
 rh d
 d f SXnC t j |  ƒ s¯ y t  |  d |  ƒ }  Wq¯ t k
 r« d d f SXn  y t |  ƒ } Wn t	 k
 rÙ d d f SXt
 | j ƒ | j } } | r$t | ƒ } | |  t
 | | ƒ } } n d } t s6d n d } | r‰t j |  ƒ syd t  |  d d ƒ k r‰| d | k r‰| d	 } q‰n  y | | f | d <Wn t	 k
 r°n X| | f S(   sâ   Return tuple of positional and keywrord argument names for a function,
    method, class or callable.

    In case of a class, its ``__init__`` method is considered.
    For methods the ``self`` parameter is not included.
    t   __dict__t	   _varnamesR   R   t   objt   .t   __qualname__i    i   (    (    (    (    (    (    (    (   R   (   R   R'   (    (   t   getattrt   KeyErrorR!   t   isclassR   t   AttributeErrort	   isroutinet	   ExceptionR"   t	   TypeErrort   tuplet   argst   defaultst   lent   _PYPY3t   ismethod(   R   t   cachet   specR2   R3   t   indext   kwargst   implicit_names(    (    s+   lib/python2.7/site-packages/pluggy/hooks.pyt   varnamesŽ   sD    (t
   _HookRelayc           B   s   e  Z d  Z RS(   sh    hook holder object for performing 1:N hook calls where N is the number
    of registered plugins.

    (   R   R   R   (    (    (    s+   lib/python2.7/site-packages/pluggy/hooks.pyR=   Â   s   t   _HookCallerc           B   sƒ   e  Z d d d  „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d d d d	 „ Z d
 „  Z d „  Z RS(   c         C   s}   | |  _  g  |  _ g  |  _ | |  _ d  |  _ d  |  _ t |  _ d  |  _	 | d  k	 ry | d  k	 sf t
 ‚ |  j | | ƒ n  d  S(   N(   t   namet	   _wrapperst   _nonwrapperst	   _hookexecR   t   argnamest
   kwargnamesR   t	   multicallR8   t   AssertionErrort   set_specification(   R   R?   t   hook_executet   specmodule_or_classt	   spec_opts(    (    s+   lib/python2.7/site-packages/pluggy/hooks.pyR   Ê   s    								c         C   s   |  j  d  k	 S(   N(   R8   R   (   R   (    (    s+   lib/python2.7/site-packages/pluggy/hooks.pyt   has_spec×   s    c         C   sJ   |  j  ƒ  s t ‚ t | |  j | ƒ |  _ | j d ƒ rF g  |  _ n  d  S(   NR   (   RK   RF   t   HookSpecR?   R8   t   gett   _call_history(   R   RI   RJ   (    (    s+   lib/python2.7/site-packages/pluggy/hooks.pyRG   Ú   s    c         C   s   t  |  d ƒ S(   NRN   (   t   hasattr(   R   (    (    s+   lib/python2.7/site-packages/pluggy/hooks.pyt   is_historicà   s    c            sV   ‡  f d †  } | |  j  ƒ d  k rR | |  j ƒ d  k rR t d ˆ  f ƒ ‚ qR n  d  S(   Nc            s;   x4 t  |  ƒ D]& \ } } | j ˆ  k r |  | =t Sq Wd  S(   N(   t	   enumeratet   plugint   True(   t   wrapperst   it   method(   RR   (    s+   lib/python2.7/site-packages/pluggy/hooks.pyt   removeä   s    s   plugin %r not found(   R@   R   RA   R
   (   R   RR   RW   (    (   RR   s+   lib/python2.7/site-packages/pluggy/hooks.pyt   _remove_pluginã   s    c         C   s   |  j  |  j S(   N(   RA   R@   (   R   (    (    s+   lib/python2.7/site-packages/pluggy/hooks.pyt   get_hookimplsî   s    c         C   sÐ   | j  r |  j } n	 |  j } | j r: | j d | ƒ ng | j rS | j | ƒ nN t | ƒ d } x' | d k rŒ | | j rŒ | d 8} qf W| j | d | ƒ d | j k rÌ t	 j
 d t ƒ t |  _ n  d S(   s5   Add an implementation to the callback chain.
        i    i   t   __multicall__sV   Support for __multicall__ is now deprecated and will beremoved in an upcoming release.N(   R   R@   RA   R   t   insertR   t   appendR4   RC   t   warningst   warnt   DeprecationWarningR    RE   (   R   t   hookimplt   methodsRU   (    (    s+   lib/python2.7/site-packages/pluggy/hooks.pyt   _add_hookimplò   s     				c         C   s   d |  j  f S(   Ns   <_HookCaller %r>(   R?   (   R   (    (    s+   lib/python2.7/site-packages/pluggy/hooks.pyt   __repr__  s    c         O   s³   | r t  d ƒ ‚ n  |  j ƒ  s( t ‚ |  j rš |  j j rš t |  j j ƒ t d g ƒ t | j ƒ  ƒ } | rš t j d j	 t
 | ƒ ƒ d d ƒqš n  |  j |  |  j ƒ  | ƒ S(   Ns,   hook calling supports only keyword argumentsRZ   sT   Argument(s) {} which are declared in the hookspec can not be found in this hook callt
   stackleveli   (   R0   RP   RF   R8   RC   t   sett   keysR]   R^   t   formatR1   RB   RY   (   R   R2   R:   t	   notincall(    (    s+   lib/python2.7/site-packages/pluggy/hooks.pyR     s    /c         C   s‘   | d k	 r% t j d t ƒ | } n  |  j j | p7 i  | f ƒ |  j |  |  j ƒ  | ƒ } | d k rl d Sx | px g  D] } | | ƒ qy Wd S(   s\  Call the hook with given ``kwargs`` for all registered plugins and
        for all plugins which will be registered afterwards.

        If ``result_callback`` is not ``None`` it will be called for for each
        non-None result obtained from a hook implementation.

        .. note::
            The ``proc`` argument is now deprecated.
        sX   Support for `proc` argument is now deprecated and will beremoved in an upcoming release.N(   R   R]   R^   R_   RN   R\   RB   RY   (   R   t   result_callbackR:   t   proct   rest   x(    (    s+   lib/python2.7/site-packages/pluggy/hooks.pyt   call_historic   s    
	c         C   s”   t  |  j ƒ t  |  j ƒ f } xK | D]C } t d t d t d t ƒ } t d d | | ƒ } |  j | ƒ q% Wz |  |   SWd | \ |  _ |  _ Xd S(   s}    Call the hook with some additional temporarily participating
        methods using the specified kwargs as call parameters. R   R   R   s   <temp>N(   t   listRA   R@   R   R   t   HookImplR   Rb   (   R   Ra   R:   t   oldRV   R   R`   (    (    s+   lib/python2.7/site-packages/pluggy/hooks.pyt
   call_extra;  s    c         C   sh   |  j  ƒ  rd xU |  j D]G \ } } |  j |  | g | ƒ } | r | d k	 r | | d ƒ q q Wn  d S(   sJ   Apply call history to a new hookimpl if it is marked as historic.
        i    N(   RP   RN   RB   R   (   R   RV   R:   Ri   Rk   (    (    s+   lib/python2.7/site-packages/pluggy/hooks.pyt   _maybe_apply_historyH  s
    N(   R   R   R   R   RK   RG   RP   RX   RY   Rb   Rc   R   Rm   Rq   Rr   (    (    (    s+   lib/python2.7/site-packages/pluggy/hooks.pyR>   É   s   									Ro   c           B   s   e  Z d  „  Z d „  Z RS(   c         C   sS   | |  _  t |  j  ƒ \ |  _ |  _ | |  _ | |  _ | |  _ |  j j | ƒ d  S(   N(	   R   R<   RC   RD   RR   R   t   plugin_nameR%   t   update(   R   RR   Rs   R   t   hook_impl_opts(    (    s+   lib/python2.7/site-packages/pluggy/hooks.pyR   S  s    				c         C   s   d |  j  |  j f S(   Ns$   <HookImpl plugin_name=%r, plugin=%r>(   Rs   RR   (   R   (    (    s+   lib/python2.7/site-packages/pluggy/hooks.pyRc   [  s    (   R   R   R   Rc   (    (    (    s+   lib/python2.7/site-packages/pluggy/hooks.pyRo   R  s   	RL   c           B   s   e  Z d  „  Z RS(   c         C   sx   | |  _  t | | ƒ |  _ } | |  _ t | ƒ \ |  _ |  _ | |  _ d g t |  j ƒ |  _ | j	 d ƒ |  _
 d  S(   NRZ   R	   (   t	   namespaceR*   R   R?   R<   RC   RD   R   Rn   RM   R	   (   R   Rv   R?   R   R   (    (    s+   lib/python2.7/site-packages/pluggy/hooks.pyR   `  s    			(   R   R   R   (    (    (    s+   lib/python2.7/site-packages/pluggy/hooks.pyRL   _  s   (   R   R!   t   sysR]   t   callersR    R   t   objectR   R   R   RO   R"   t   version_infot   majorR5   R<   R=   R>   Ro   RL   (    (    (    s+   lib/python2.7/site-packages/pluggy/hooks.pyt   <module>   s    0>		!	4‰