3 [s@sdZdZddlmZddlmZddlmZdZGdddeZGd d d eZ Gd d d e Z Gd ddeZ Gddde eZ Gddde Z GdddeZGdddeZGdddeZGdddeZGdddeZeeGdddeZGdd d eZGd!d"d"eZGd#d$d$eZGd%d&d&eZGd'd(d(eZGd)d*d*eZGd+d,d,eZGd-d.d.eZeeGd/d0d0eZGd1d2d2eZ ee Gd3d4d4eZ!Gd5d6d6eZ"ee"Gd7d8d8eZ#Gd9d:d:eZ$Gd;d<dzInterface Package Interfaces Zrestructuredtext) Attribute) Interface) implementerc@sFeZdZdZeddZeddZddZdd d Zd d Zd dZdS)IElementz=Objects that have basic documentation and tagged values. __name__zThe object name__doc__zThe object doc stringcCsdS)zcReturns the value associated with `tag`. Raise a `KeyError` of the tag isn't set. N)tagr r "/usr/lib64/python3.6/interfaces.pygetTaggedValue szIElement.getTaggedValueNcCsdS)ziReturns the value associated with `tag`. Return the default value of the tag isn't set. Nr )r defaultr r r queryTaggedValue&szIElement.queryTaggedValuecCsdS)zReturns a list of all tags.Nr r r r r getTaggedValueTags,szIElement.getTaggedValueTagscCsdS)zAssociates `value` with `key`.Nr )r valuer r r setTaggedValue/szIElement.setTaggedValue)N) r __module__ __qualname__rrr rrrr r r r rs   rc@seZdZdZeddZdS) IAttributezAttribute descriptors interfacez@Stores the interface instance in which the attribute is located.N)rrrrrrr r r r r3src@s eZdZdZddZddZdS)IMethodzMethod attributescCsdS)aReturns the signature information. This method returns a dictionary with the following keys: o `positional` - All positional arguments. o `required` - A list of all required arguments. o `optional` - A list of all optional arguments. o `varargs` - The name of the varargs argument. o `kwargs` - The name of the kwargs argument. Nr r r r r getSignatureInfo>szIMethod.getSignatureInfocCsdS)zReturn a signature string suitable for inclusion in documentation. This method returns the function signature string. For example, if you have `func(a, b, c=1, d='f')`, then the signature string is `(a, b, c=1, d='f')`. Nr r r r r getSignatureStringNszIMethod.getSignatureStringN)rrrrrrr r r r r;src@s^eZdZdZddZddZddZdd d Zdd d Ze dZ e dZ e dZ dddZ d S)ISpecificationz Object Behavioral specificationscCsdS)zTest whether the interface is implemented by the object Return true of the object asserts that it implements the interface, including asserting that it implements an extended interface. Nr )objectr r r providedByYszISpecification.providedBycCsdS)zTest whether the interface is implemented by instances of the class Return true of the class asserts that its instances implement the interface, including asserting that they implement an extended interface. Nr )class_r r r implementedByaszISpecification.implementedBycCsdS)z=Test whether the specification is or extends another Nr )otherr r r isOrExtendsiszISpecification.isOrExtendsTcCsdS)zTest whether a specification extends another The specification extends other if it has other as a base interface or if one of it's bases extends other. If strict is false, then the specification extends itself. Nr )rstrictr r r extendsmszISpecification.extendsNcCsdS)a/Return a weakref to the specification This method is, regrettably, needed to allow weakrefs to be computed to security-proxied specifications. While the zope.interface package does not require zope.security or zope.proxy, it has to be able to coexist with it. Nr )callbackr r r weakrefvszISpecification.weakrefzoBase specifications A tuple if specifications from which this specification is directly derived. zSpecification-resolution order A tuple of the specification and all of it's ancestor specifications from most specific to least specific. (This is similar to the method-resolution order for new-style classes.) aInterface-resolution order A tuple of the of the specification's ancestor interfaces from most specific to least specific. The specification itself is included if it is an interface. (This is similar to the method-resolution order for new-style classes.) cCsdS)z|Look up the description for a name If the named attribute is not defined, the default is returned. Nr )namer r r r getszISpecification.get)T)N)N)rrrrrrrr!r#r __bases__Z__sro__Z__iro__r%r r r r rVs rc@sVeZdZdZdddZdddZddZd d Zdd d ZddZ ddZ e dZd S) IInterfacea4 Interface objects Interface objects describe the behavior of an object by containing useful information about the object. This information includes: - Prose documentation about the object. In Python terms, this is called the "doc string" of the interface. In this element, you describe how the object works in prose language and any other useful information about the object. - Descriptions of attributes. Attribute descriptions include the name of the attribute and prose documentation describing the attributes usage. - Descriptions of methods. Method descriptions can include: - Prose "doc string" documentation about the method and its usage. - A description of the methods arguments; how many arguments are expected, optional arguments and their default values, the position or arguments in the signature, whether the method accepts arbitrary arguments and whether the method accepts arbitrary keyword arguments. - Optional tagged data. Interface objects (and their attributes and methods) can have optional, application specific tagged data associated with them. Examples uses for this are examples, security assertions, pre/post conditions, and other possible information you may want to associate with an Interface or its attributes. Not all of this information is mandatory. For example, you may only want the methods of your interface to have prose documentation and not describe the arguments of the method in exact detail. Interface objects are flexible and let you give or take any of these components. Interfaces are created with the Python class statement using either `zope.interface.Interface` or another interface, as in:: from zope.interface import Interface class IMyInterface(Interface): '''Interface documentation''' def meth(arg1, arg2): '''Documentation for meth''' # Note that there is no self argument class IMySubInterface(IMyInterface): '''Interface documentation''' def meth2(): '''Documentation for meth2''' You use interfaces in two ways: - You assert that your object implement the interfaces. There are several ways that you can assert that an object implements an interface: 1. Call `zope.interface.implements` in your class definition. 2. Call `zope.interfaces.directlyProvides` on your object. 3. Call `zope.interface.classImplements` to assert that instances of a class implement an interface. For example:: from zope.interface import classImplements classImplements(some_class, some_interface) This approach is useful when it is not an option to modify the class source. Note that this doesn't affect what the class itself implements, but only what its instances implement. - You query interface meta-data. See the IInterface methods and attributes for details. FcCsdS)aeGet the interface attribute names Return a sequence of the names of the attributes, including methods, included in the interface definition. Normally, only directly defined attributes are included. If a true positional or keyword argument is given, then attributes defined by base classes will be included. Nr )allr r r namesszIInterface.namescCsdS)aGet the interface attribute names and descriptions Return a sequence of the names and descriptions of the attributes, including methods, as name-value pairs, included in the interface definition. Normally, only directly defined attributes are included. If a true positional or keyword argument is given, then attributes defined by base classes will be included. Nr )r(r r r namesAndDescriptionsszIInterface.namesAndDescriptionscCsdS)zoGet the description for a name If the named attribute is not defined, a `KeyError` is raised. Nr )r$r r r __getitem__szIInterface.__getitem__cCsdS)zGet the description for the name if it was defined by the interface If the interface doesn't define the name, returns None. Nr )r$r r r directszIInterface.directNcCsdS)a Validate invariants Validate object to defined invariants. If errors is None, raises first Invalid error; if errors is a list, appends all errors to list, then raises Invalid with the errors as the first element of the "args" tuple.Nr )objerrorsr r r validateInvariantsszIInterface.validateInvariantscCsdS)z1Test whether the name is defined by the interfaceNr )r$r r r __contains__#szIInterface.__contains__cCsdS)zReturn an iterator over the names defined by the interface The names iterated include all of the names defined by the interface directly and indirectly by base interfaces. Nr r r r r __iter__&szIInterface.__iter__z-The name of the module defining the interface)F)F)N) rrrrr)r*r+r,r/r0r1rr r r r r'sV  r'c@s@eZdZdZddZddZddZdd Zd d Zd d Z dS) IDeclarationzInterface declaration Declarations are used to express the interfaces implemented by classes or provided by objects. cCsdS)zTest whether an interface is in the specification Return true if the given interface is one of the interfaces in the specification and false otherwise. Nr )rr r r r06szIDeclaration.__contains__cCsdS)zCReturn an iterator for the interfaces in the specification Nr r r r r r1=szIDeclaration.__iter__cCsdS)aReturn an iterator of all included and extended interfaces An iterator is returned for all interfaces either included in or extended by interfaces included in the specifications without duplicates. The interfaces are in "interface resolution order". The interface resolution order is such that base interfaces are listed after interfaces that extend them and, otherwise, interfaces are included in the order that they were defined in the specification. Nr r r r r flattenedAszIDeclaration.flattenedcCsdS)aCreate an interface specification with some interfaces excluded The argument can be an interface or an interface specifications. The interface or interfaces given in a specification are subtracted from the interface specification. Removing an interface that is not in the specification does not raise an error. Doing so has no effect. Removing an interface also removes sub-interfaces of the interface. Nr ) interfacesr r r __sub__MszIDeclaration.__sub__cCsdS)azCreate an interface specification with some interfaces added The argument can be an interface or an interface specifications. The interface or interfaces given in a specification are added to the interface specification. Adding an interface that is already in the specification does not raise an error. Doing so has no effect. Nr )r4r r r __add__[szIDeclaration.__add__cCsdS)zHReturn a true value of the interface specification is non-empty Nr r r r r __nonzero__fszIDeclaration.__nonzero__N) rrrrr0r1r3r5r6r7r r r r r2/s  r2c@seZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZddZddZddZddZd d!Zd"S)#IInterfaceDeclarationadDeclare and check the interfaces of objects The functions defined in this interface are used to declare the interfaces that objects provide and to query the interfaces that have been declared. Interfaces can be declared for objects in two ways: - Interfaces are declared for instances of the object's class - Interfaces are declared for the object directly. The interfaces declared for an object are, therefore, the union of interfaces declared for the object directly and the interfaces declared for instances of the object's class. Note that we say that a class implements the interfaces provided by it's instances. An instance can also provide interfaces directly. The interfaces provided by an object are the union of the interfaces provided directly and the interfaces implemented by the class. cCsdS)zReturn the interfaces provided by an object This is the union of the interfaces directly provided by an object and interfaces implemented by it's class. The value returned is an `IDeclaration`. Nr )obr r r rsz IInterfaceDeclaration.providedBycCsdS)zsReturn the interfaces implemented for a class' instances The value returned is an `IDeclaration`. Nr )rr r r rsz#IInterfaceDeclaration.implementedBycGsdS)aQDeclare 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. Consider the following example:: class C(A, B): ... classImplements(C, I1, I2) Instances of ``C`` provide ``I1``, ``I2``, and whatever interfaces instances of ``A`` and ``B`` provide. Nr )rr4r r r classImplementssz%IInterfaceDeclaration.classImplementscGsdS)zCreate a decorator for declaring interfaces implemented by a factory. A callable is returned that makes an implements declaration on objects passed to it. Nr )r4r r r rsz!IInterfaceDeclaration.implementercGsdS)ayDeclare 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. Consider the following example:: class C(A, B): ... classImplements(C, IA, IB. IC) classImplementsOnly(C. I1, I2) Instances of ``C`` provide only ``I1``, ``I2``, and regardless of whatever interfaces instances of ``A`` and ``B`` implement. Nr )rr4r r r classImplementsOnlysz)IInterfaceDeclaration.classImplementsOnlycGsdS)zCreate a decorator for declaring the only interfaces implemented A callable is returned that makes an implements declaration on objects passed to it. Nr )r4r r r implementer_onlysz&IInterfaceDeclaration.implementer_onlycCsdS)zvReturn the interfaces directly provided by the given object The value returned is an `IDeclaration`. Nr )rr r r directlyProvidedBysz(IInterfaceDeclaration.directlyProvidedBycGsdS)aDeclare 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. Consider the following example:: class C(A, B): ... ob = C() directlyProvides(ob, I1, I2) The object, ``ob`` provides ``I1``, ``I2``, and whatever interfaces instances have been declared for instances of ``C``. To remove directly provided interfaces, use `directlyProvidedBy` and subtract the unwanted interfaces. For example:: directlyProvides(ob, directlyProvidedBy(ob)-I2) removes I2 from the interfaces directly provided by ``ob``. The object, ``ob`` no longer directly provides ``I2``, although it might still provide ``I2`` if it's class implements ``I2``. To add directly provided interfaces, use `directlyProvidedBy` and include additional interfaces. For example:: directlyProvides(ob, directlyProvidedBy(ob), I2) adds I2 to the interfaces directly provided by ob. Nr )rr4r r r directlyProvidessz&IInterfaceDeclaration.directlyProvidescGsdS)zDeclare additional interfaces directly for an object:: alsoProvides(ob, I1) is equivalent to:: directlyProvides(ob, directlyProvidedBy(ob), I1) Nr )rr4r r r alsoProvidessz"IInterfaceDeclaration.alsoProvidescCsdS)aRemove an interface from the list of an object's directly provided interfaces:: noLongerProvides(ob, I1) is equivalent to:: directlyProvides(ob, directlyProvidedBy(ob) - I1) with the exception that if ``I1`` is an interface that is provided by ``ob`` through the class's implementation, `ValueError` is raised. Nr )rrr r r noLongerProvidessz&IInterfaceDeclaration.noLongerProvidescGsdS)aDeclare interfaces implemented by instances of a class This function is called in a class definition (Python 2.x only). 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. Consider the following example (Python 2.x only):: class C(A, B): implements(I1, I2) Instances of ``C`` implement ``I1``, ``I2``, and whatever interfaces instances of ``A`` and ``B`` implement. Nr )r4r r r implementssz IInterfaceDeclaration.implementscGsdS)aoDeclare the only interfaces implemented by instances of a class This function is called in a class definition (Python 2.x only). 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. Consider the following example (Python 2.x only):: class C(A, B): implementsOnly(I1, I2) Instances of ``C`` implement ``I1``, ``I2``, regardless of what instances of ``A`` and ``B`` implement. Nr )r4r r r implementsOnly4sz$IInterfaceDeclaration.implementsOnlycGsdS)aDeclare 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. Nr )r4r r r classProvidesTsz#IInterfaceDeclaration.classProvidescGsdS)z,A class decorator version of `classProvides`Nr )r4r r r providerqszIInterfaceDeclaration.providercGsdS)aIDeclare 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 a module. For example:: moduleImplements(I1) is equivalent to:: directlyProvides(sys.modules[__name__], I1) Nr )r4r r r moduleProvidestsz$IInterfaceDeclaration.moduleProvidescGsdS)aCreate an interface specification The arguments are one or more interfaces or interface specifications (`IDeclaration` objects). A new interface specification (`IDeclaration`) with the given interfaces is returned. Nr )r4r r r Declarationsz!IInterfaceDeclaration.DeclarationN)rrrrrrr:rr;r<r=r>r?r@rArBrCrDrErFr r r r r8js" ' $ r8c@seZdZdZddZefddZddd Zedfd d Zedfd d Z edfddZ edfddZ ddZ ddZ efddZefddZefddZdS)IAdapterRegistryaProvide an interface-based registry for adapters This registry registers objects that are in some sense "from" a sequence of specification to an interface and a name. No specific semantics are assumed for the registered objects, however, the most common application will be to register factories that adapt objects providing required specifications to a provided interface. cCsdS)zRegister a value A value is registered for a *sequence* of required specifications, a provided interface, and a name, which must be text. Nr )requiredprovidedr$rr r r registerszIAdapterRegistry.registercCsdS)aReturn the component registered for the given interfaces and name name must be text. Unlike the lookup method, this methods won't retrieve components registered for more specific required interfaces or less specific provided interfaces. If no component was registered exactly for the given interfaces and name, then None is returned. Nr )rHrIr$r r r registeredszIAdapterRegistry.registeredrNcCsdS)zLookup a value A value is looked up based on a *sequence* of required specifications, a provided interface, and a name, which must be text. Nr )rHrIr$r r r r lookupszIAdapterRegistry.lookupcCsdS)zDAdapt a sequence of objects to a named, provided, interface Nr )objectsrIr$r r r r queryMultiAdaptersz"IAdapterRegistry.queryMultiAdaptercCsdS)zLookup a value using a single required interface A value is looked up based on a single required specifications, a provided interface, and a name, which must be text. Nr )rHrIr$r r r r lookup1szIAdapterRegistry.lookup1cCsdS)zsR   J;/` Q H