
2(Vc           @   sC  d  Z  d Z d d l Z d d l m Z d d l m Z d d l m Z d d l Z d d l Z d d l	 m
 Z
 d d l m Z d d	 l m Z d d
 l m Z d d l m Z d d l m Z i  Z d Z d Z d e f d     YZ d e f d     YZ d e f d     YZ d   Z e Z d   Z d   Z d   Z d d; d     YZ d d< d     YZ  d   Z! d   Z" d   Z# d  e f d!     YZ$ e$ Z% e j&   Z' d"   Z$ e( e$ _) d#   Z* d$   Z+ d%   Z, d& e f d'     YZ- e- Z. e- Z/ y d d l0 Z0 Wn e1 k
 rn Xd d( l0 m/ Z/ d) e e/ f d*     YZ2 d+   Z3 d,   Z4 d-   Z5 d. d= d/     YZ6 d0   Z7 d1   Z8 d2   Z9 e9 Z: d3   Z; e; Z< d4 e f d5     YZ= e= Z> d d6  Z@ e   ZA y d d l0 Z0 Wn e1 k
 rnA Xd d7 l0 m Z d d8 l0 m< Z< d d9 l0 m: Z: d d: l0 m> Z> e>   ZB d S(>   s  Implementation of interface declarations

There are three flavors of declarations:

  - Declarations are used to simply name declared interfaces.

  - ImplementsDeclarations are used to express the interfaces that a
    class implements (that instances of the class provides).

    Implements specifications support inheriting interfaces.

  - ProvidesDeclarations are used to express interfaces directly
    provided by objects.

t   restructuredtextiN(   t   FunctionType(   t
   MethodType(   t
   ModuleType(   t   addClassAdvisor(   t   InterfaceClass(   t   SpecificationBase(   t   Specification(   t   CLASS_TYPES(   t   PYTHON3sI   Class advice impossible in Python3.  Use the @%s class decorator instead.s\   The %s API is deprecated, and will not work in Python3  Use the @%s class decorator instead.t   namedc           B   s   e  Z d    Z d   Z RS(   c         C   s   | |  _  d  S(   N(   t   name(   t   selfR   (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyt   __init__6   s    c         C   s   |  j  | _ | S(   N(   R   t   __component_name__(   R   t   ob(    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyt   __call__9   s    (   t   __name__t
   __module__R   R   (    (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyR
   4   s   	t   Declarationc           B   sS   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 e	 Z
 RS(   s   Interface declarationsc         G   s   t  j |  t |   d  S(   N(   R   R   t   _normalizeargs(   R   t
   interfaces(    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyR   @   s    c         C   s2   t  j |  |  y
 |  ` Wn t k
 r- n Xd  S(   N(   R   t   changedt   _v_attrst   AttributeError(   R   t   originally_changed(    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyR   C   s
    
c         C   s   |  j  |  o | |  j   k S(   s:   Test whether an interface is in the specification
        (   t   extendsR   (   R   t	   interface(    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyt   __contains__J   s    c         C   s
   |  j    S(   sC   Return an iterator for the interfaces in the specification
        (   R   (   R   (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyt   __iter__P   s    c         C   s   t  |  j  S(   sC   Return an iterator of all included and extended interfaces
        (   t   itert   __iro__(   R   (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyt	   flattenedU   s    c         C   sT   t  g  |  j   D]= } g  | j   D] } | j | d  r# | ^ q# s | ^ q   S(   s/   Remove interfaces from a specification
        i    (   R   R   R   (   R   t   othert   it   j(    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyt   __sub__Z   s    c         C   s   i  } g  } x+ |  j    D] } d | | <| j |  q Wx: | j    D], } | | k rG d | | <| j |  qG qG Wt |   S(   sC   Add two specifications or a specification and an interface
        i   (   R   t   appendR   (   R   R!   t   seent   resultR"   (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyt   __add__d   s    

(   R   R   t   __doc__R   R   R   R   R    R$   R(   t   __radd__(    (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyR   =   s   						
	t
   Implementsc           B   s,   e  Z d Z d Z d  Z  d   Z d   Z RS(   t   ?c         C   s   d |  j  S(   Ns   <implementedBy %s>(   R   (   R   (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyt   __repr__   s    c         C   s   t  |  j f f S(   N(   t   implementedByt   inherit(   R   (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyt
   __reduce__   s    N(    (   R   R   t   NoneR/   t   declaredR-   R0   (    (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyR+   |   s
   	c         C   s`  y |  j  j d  } Wnu t k
 r t |  d d  } | d k rg t j |   } | d k	 rc | St S| j t k rz | St	 t
 | f    SXt | t  r | S| d k r t j |   } | d k	 r | Sn  | d k	 r| f } t t
 |    } d | _ |  ` ns y |  j } Wn5 t k
 rLt |   sCt d |    n  d } n Xt g  | D] } t |  ^ qW  } |  | _ t |  d d  pd d t |  d d  pd | _ ym | |  _ t |  d  st |  _ n  t |  t  rd |  j  k rt |  t |  d	 t |     |  _ n  Wn< t k
 r[t |  t  sNt d
 |    n  | t |  <n X| S(   sk   Return the interfaces implemented for a class' instances

      The value returned is an IDeclaration.
    t   __implemented__s$   ImplementedBy called for non-factoryR   R,   t   .R   t   __providedBy__t   __provides__t	   __class__s!   ImplementedBy called for non-typeN(    (   t   __dict__t   getR   t   getattrR1   t#   BuiltinImplementationSpecificationst   _emptyR7   R+   R   R   t
   isinstanceR/   R3   t	   __bases__t   callablet	   TypeErrorR.   R   t   hasattrt   objectSpecificationDescriptorR5   t   DescriptorAwareMetaClassest   ClassProvidest   typeR6   (   t   clst   spect   basest   c(    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyt   implementedByFallback   s\    			
%	5	%c         G   s/   t  |   } d | _ d | _ t |  |  d S(   s8  Declare the only interfaces implemented by instances of a class

      The arguments after the class are one or more interfaces or interface
      specifications (``IDeclaration`` objects).

      The interfaces given (including the interfaces in the specifications)
      replace any previous declarations.
    N(    (   R.   R2   R1   R/   t   classImplements(   RF   R   RG   (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyt   classImplementsOnly   s    			c         G   s   t  |   } | j t t |   7_ g  } i  } x7 | j D], } | | k r= d | | <| j |  q= q= W| j d k	 r xI | j j D]8 } t  |  } | | k r d | | <| j |  q q Wn  t |  | _ d S(   sI  Declare additional interfaces implemented for instances of a class

      The arguments after the class are one or more interfaces or
      interface specifications (``IDeclaration`` objects).

      The interfaces given (including the interfaces in the specifications)
      are added to any interfaces previously declared.
    i   N(   R.   R2   t   tupleR   R%   R/   R1   R>   (   RF   R   RG   RH   R&   t   bRI   (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyRK      s    	

c         C   s*   |  j  d \ } } |  ` | |  |  |  S(   Nt   __implements_advice_data__(   R8   RO   (   RF   R   RK   (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyt   _implements_advice  s    t   implementerc           B   s    e  Z d  Z d   Z d   Z RS(   s  Declare the interfaces implemented by instances of a class.

      This function is called as a class decorator.

      The arguments are one or more interfaces or interface
      specifications (IDeclaration objects).

      The interfaces given (including the interfaces in the
      specifications) are added to any interfaces previously
      declared.

      Previous declarations include declarations for base classes
      unless implementsOnly was used.

      This function is provided for convenience. It provides a more
      convenient way to call classImplements. For example::

        @implementer(I1)
        class C(object):
            pass

      is equivalent to calling::

        classImplements(C, I1)

      after the class has been created.
      c         G   s   | |  _  d  S(   N(   R   (   R   R   (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyR   5  s    c         C   sf   t  | t  r# t | |  j  | St |  j   } y | | _ Wn  t k
 ra t d |   n X| S(   Ns   Can't declare implements(   R=   RC   RK   R   R+   R3   R   R@   (   R   R   RG   (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyR   8  s    (   R   R   R)   R   R   (    (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyRQ     s   	t   implementer_onlyc           B   s    e  Z d  Z d   Z d   Z RS(   sn  Declare the only interfaces implemented by instances of a class

      This function is called as a class decorator.

      The arguments are one or more interfaces or interface
      specifications (IDeclaration objects).

      Previous declarations including declarations for base classes
      are overridden.

      This function is provided for convenience. It provides a more
      convenient way to call classImplementsOnly. For example::

        @implementer_only(I1)
        class C(object): pass

      is equivalent to calling::

        classImplementsOnly(I1)

      after the class has been created.
      c         G   s   | |  _  d  S(   N(   R   (   R   R   (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyR   \  s    c         C   s<   t  | t t f  r$ t d   n t | |  j  | Sd  S(   NsI   The implementer_only decorator is not supported for methods or functions.(   R=   R   R   t
   ValueErrorRL   R   (   R   R   (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyR   _  s    (   R   R   R)   R   R   (    (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyRR   D  s   	c         C   s   t  r t d   n  t j d  } | j } | | j k sH d | k r[ t |  d   n  d | k rz t |  d   n  | | f | d <t t d d d  S(	   Ns"   Class advice impossible in Python3i   R   s*    can be used only from a class definition.RO   s-    can be used only once in a class definition.t   depthi   (   R	   R@   t   syst	   _getframet   f_localst	   f_globalsR   RP   (   R   R   RK   t   framet   locals(    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyt   _implementsk  s    	c          G   s-   t  r t t d   n  t d |  t  d S(   s  Declare interfaces implemented by instances of a class

      This function is called in a class definition.

      The arguments are one or more interfaces or interface
      specifications (IDeclaration objects).

      The interfaces given (including the interfaces in the
      specifications) are added to any interfaces previously
      declared.

      Previous declarations include declarations for base classes
      unless implementsOnly was used.

      This function is provided for convenience. It provides a more
      convenient way to call classImplements. For example::

        implements(I1)

      is equivalent to calling::

        classImplements(C, I1)

      after the class has been created.
    RQ   t
   implementsN(   R	   R@   t   _ADVICE_ERRORR[   RK   (   R   (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyR\     s    c          G   s-   t  r t t d   n  t d |  t  d S(   sL  Declare the only interfaces implemented by instances of a class

      This function is called in a class definition.

      The arguments are one or more interfaces or interface
      specifications (IDeclaration objects).

      Previous declarations including declarations for base classes
      are overridden.

      This function is provided for convenience. It provides a more
      convenient way to call classImplementsOnly. For example::

        implementsOnly(I1)

      is equivalent to calling::

        classImplementsOnly(I1)

      after the class has been created.
    RR   t   implementsOnlyN(   R	   R@   R]   R[   RL   (   R   (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyR^     s    t   Providesc           B   s/   e  Z d  Z d   Z d   Z d Z d   Z RS(   s   Implement __provides__, the instance-specific specification

    When an object is pickled, we pickle the interfaces that it implements.
    c         G   s:   | f | |  _  | |  _ t j |  | t |  f  d  S(   N(   t   _Provides__argst   _clsR   R   R.   (   R   RF   R   (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyR     s    	c         C   s   t  |  j f S(   N(   R_   R`   (   R   (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyR0     s    s   zope.interfacec         C   s/   | d k r | |  j k r |  St d   d S(   sH   Make sure that a class __provides__ doesn't leak to an instance
        R6   N(   R1   Ra   R   (   R   t   instRF   (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyt   __get__  s    (   R   R   R)   R   R0   Rc   (    (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyR_     s
   		c          G   s8   t  j |   } | d k r4 t |    } | t  |  <n  | S(   s   Cache instance declarations

      Instance declarations are shared among instances that have the same
      declaration. The declarations are cached in a weak value dictionary.
    N(   t   InstanceDeclarationsR9   R1   t   ProvidesClass(   R   RG   (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyR_     s
    c         G   s   t  |  d d  } | d k	 rW t  | d d  | k rW t |  t  sW t d   qW n  t |  } | d k r~ t |   } n  t } x' t D] } t | |  r t	 } Pq q W| r t
 |  | |  |  _ n t | |  |  _ d S(   s@  Declare interfaces declared directly for an object

      The arguments after the object are one or more interfaces or interface
      specifications (``IDeclaration`` objects).

      The interfaces given (including the interfaces in the specifications)
      replace interfaces previously declared for the object.
    R7   sH   Attempt to make an interface declaration on a non-descriptor-aware classN(   R:   R1   R=   RC   R@   R   RE   t   Falset
   issubclasst   TrueRD   R6   R_   (   t   objectR   RF   t   issubt   damc(    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyt   directlyProvides  s     	$	c         G   s   t  |  t |   |  d S(   sA  Declare interfaces declared directly for an object

    The arguments after the object are one or more interfaces or interface
    specifications (``IDeclaration`` objects).

    The interfaces given (including the interfaces in the specifications) are
    added to the interfaces previously declared for the object.
    N(   Rl   t   directlyProvidedBy(   Ri   R   (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyt   alsoProvides  s    	c         C   s9   t  |  t |   |  | j |   r5 t d   n  d S(   s;    Removes a directly provided interface from an object.
    s-   Can only remove directly provided interfaces.N(   Rl   Rm   t
   providedByRS   (   Ri   R   (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyt   noLongerProvides  s    t   ClassProvidesBaseFallbackc           B   s   e  Z d    Z RS(   c         C   s6   | |  j  k r& | d  k r |  S|  j St d   d  S(   NR6   (   Ra   R1   R[   R   (   R   Rb   RF   (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyRc   (  s
    (   R   R   Rc   (    (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyRq   &  s   (   t   ClassProvidesBaseRD   c           B   s)   e  Z d  Z d   Z d   Z e j Z RS(   s   Special descriptor for class __provides__

    The descriptor caches the implementedBy info, so that
    we can get declarations for objects without instance-specific
    interfaces a bit quicker.
    c         G   sL   | |  _  t |  |  _ | | f | |  _ t j |  | t |  f  d  S(   N(   Ra   R.   R[   t   _ClassProvides__argsR   R   (   R   RF   t   metaclsR   (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyR   H  s    	c         C   s   |  j  |  j f S(   N(   R7   Rs   (   R   (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyR0   N  s    (   R   R   R)   R   R0   Rr   Rc   (    (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyRD   A  s   		c         C   sB   t  |  d d  } | d k s- t | t  r1 t St | j d   S(   sp   Return the interfaces directly provided by the given object

    The value returned is an ``IDeclaration``.
    R6   iN(   R:   R1   R=   R+   R<   R   R>   (   Ri   t   provides(    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyRm   T  s
    c          G   s   t  r t t d   n  t j d  } | j } | | j k sL d | k r[ t d   n  d | k rv t d   n  t |   | d <t t	 d d d	 S(
   s  Declare interfaces provided directly by a class

      This function is called in a class definition.

      The arguments are one or more interfaces or interface specifications
      (``IDeclaration`` objects).

      The given interfaces (including the interfaces in the specifications)
      are used to create the class's direct-object interface specification.
      An error will be raised if the module class has an direct interface
      specification. In other words, it is an error to call this function more
      than once in a class definition.

      Note that the given interfaces have nothing to do with the interfaces
      implemented by instances of the class.

      This function is provided for convenience. It provides a more convenient
      way to call directlyProvides for a class. For example::

        classProvides(I1)

      is equivalent to calling::

        directlyProvides(theclass, I1)

      after the class has been created.
    t   provideri   R   s7   classProvides can be used only from a class definition.R6   s:   classProvides can only be used once in a class definition.RT   i   N(
   R	   R@   R]   RU   RV   RW   RX   R   R   t   _classProvides_advice(   R   RY   RZ   (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyt   classProvidesf  s    	c         C   s$   |  j  d } |  ` t |  |  |  S(   NR6   (   R8   R6   Rl   (   RF   R   (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyRw     s    Rv   c           B   s    e  Z d  Z d   Z d   Z RS(   s(   Class decorator version of classProvidesc         G   s   | |  _  d  S(   N(   R   (   R   R   (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyR     s    c         C   s   t  | |  j  | S(   N(   Rl   R   (   R   R   (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyR     s    (   R   R   R)   R   R   (    (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyRv     s   	c          G   sz   t  j d  } | j } | | j k	 s3 d | k rB t d   n  d | k r] t d   n  t t t |    | d <d S(   s  Declare interfaces provided by a module

    This function is used in a module definition.

    The arguments are one or more interfaces or interface specifications
    (``IDeclaration`` objects).

    The given interfaces (including the interfaces in the specifications) are
    used to create the module's direct-object interface specification.  An
    error will be raised if the module already has an interface specification.
    In other words, it is an error to call this function more than once in a
    module definition.

    This function is provided for convenience. It provides a more convenient
    way to call directlyProvides. For example::

      moduleImplements(I1)

    is equivalent to::

      directlyProvides(sys.modules[__name__], I1)
    i   R   s9   moduleProvides can only be used from a module definition.R6   s<   moduleProvides can only be used once in a module definition.N(   RU   RV   RW   RX   R@   R_   R   R   (   R   RY   RZ   (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyt   moduleProvides  s    	c         C   s   t  | |   S(   sf   Provide object specifications

    These combine information for the object and for it's classes.
    (   R_   (   t   directRF   (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyt   ObjectSpecification  s    c         C   s`   t  |  d d   } | d  k	 r4 t | t  r4 | Sn  y |  j } Wn t k
 rU t SXt |  S(   NR6   (   R:   R1   R=   R   R7   R   R<   R.   (   R   Ru   RF   (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyt   getObjectSpecificationFallback  s    c         C   s   y |  j  } Wn t k
 r' t |   SXy | j Wnz t k
 r y |  j } Wn t k
 rm t |  j  SXy |  j j } Wn t k
 r | SX| | k r t |  j  Sn X| S(   N(   R5   R   t   getObjectSpecificationR   R6   R.   R7   (   R   t   rt   cp(    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyt   providedByFallback  s$    t%   ObjectSpecificationDescriptorFallbackc           B   s   e  Z d  Z d   Z RS(   s   Implement the `__providedBy__` attribute

    The `__providedBy__` attribute computes the interfaces peovided by
    an object.
    c         C   sB   | d k r t |  St | d d  } | d k	 r8 | St |  S(   s2   Get an object specification for an object
        R6   N(   R1   R}   R:   R.   (   R   Rb   RF   Ru   (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyRc   (  s    
(   R   R   R)   Rc   (    (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyR   !  s   c         C   sn   | d k r g  } n  |  j } t | j k s< t | j k rL | j |   n x |  D] } t | |  qS W| S(   s   Normalize declaration arguments

    Normalization arguments might contain Declarions, tuples, or single
    interfaces.

    Anything but individial interfaces or implements specs will be expanded.
    N(   R1   R7   R   t   __mro__R+   R%   R   (   t   sequencet   outputRF   t   v(    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyR   8  s    		(   R.   (   Ro   (   R}   (   t   ObjectSpecificationDescriptor(    (    (    (C   R)   t   __docformat__RU   t   typesR   R   R   t   warningst   weakreft   zope.interface.adviceR   t   zope.interface.interfaceR   R   R   t   zope.interface._compatR   RC   R	   R;   R]   t   _ADVICE_WARNINGRi   R
   R   R+   RJ   R.   RL   RK   RP   RQ   RR   R[   R\   R^   R_   Re   t   WeakValueDictionaryRd   Rh   t   __safe_for_unpickling__Rl   Rn   Rp   Rq   t   ClassProvidesBasePyRr   t   _zope_interface_coptimizationst   ImportErrorRD   Rm   Rx   Rw   Rv   Ry   R{   R|   R}   R   Ro   R   R   R1   R   R<   RB   (    (    (    s?   /usr/lib/python2.7/dist-packages/zope/interface/declarations.pyt   <module>   s   	?	W			,'		 	 			$				2	
	,			1	