TJJc @ s d Z d Z d d k l Z d d k l Z d e f d YZ d e f d YZ d e f d YZ d e f d YZ d e e f d YZ d e f d YZ d e f d YZ d e f d YZ d S( sU Interface Package Interfaces $Id: interfaces.py 92521 2008-10-24 05:44:37Z baijum $ t restructuredtexti( t Interface( t Attributet IElementc B sS e Z d Z e d d Z e d d Z d Z d d Z d Z d Z RS( s= Objects that have basic documentation and tagged values. t __name__s The object namet __doc__s The object doc stringc C s d S( sc Returns the value associated with `tag`. Raise a `KeyError` of the tag isn't set. N( ( t tag( ( s? /usr/lib64/python2.6/site-packages/zope/interface/interfaces.pyt getTaggedValue s c C s d S( si Returns the value associated with `tag`. Return the default value of the tag isn't set. N( ( R t default( ( s? /usr/lib64/python2.6/site-packages/zope/interface/interfaces.pyt queryTaggedValue% s c C s d S( s Returns a list of all tags.N( ( ( ( s? /usr/lib64/python2.6/site-packages/zope/interface/interfaces.pyt getTaggedValueTags+ s c C s d S( s Associates `value` with `key`.N( ( R t value( ( s? /usr/lib64/python2.6/site-packages/zope/interface/interfaces.pyt setTaggedValue. s N( R t __module__R R R t NoneR R R ( ( ( s? /usr/lib64/python2.6/site-packages/zope/interface/interfaces.pyR s t IAttributec B s e Z d Z e d d Z RS( s Attribute descriptorst interfaces@ Stores the interface instance in which the attribute is located.( R R R R R ( ( ( s? /usr/lib64/python2.6/site-packages/zope/interface/interfaces.pyR 2 s t IMethodc B s e Z d Z d Z d Z RS( s Method attributesc C s d S( s Returns 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. N( ( ( ( s? /usr/lib64/python2.6/site-packages/zope/interface/interfaces.pyt getSignatureInfo= s c C s d S( s Return 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')`. N( ( ( ( s? /usr/lib64/python2.6/site-packages/zope/interface/interfaces.pyt getSignatureStringM s ( R R R R R ( ( ( s? /usr/lib64/python2.6/site-packages/zope/interface/interfaces.pyR : s t ISpecificationc B s_ e Z d Z e d Z d Z d d Z e d Z e d Z e d Z d d Z RS( s Object Behavioral specificationsc C s d S( s Test 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. N( ( t othert strict( ( s? /usr/lib64/python2.6/site-packages/zope/interface/interfaces.pyt extendsX s c C s d S( s= Test whether the specification is or extends another N( ( R ( ( s? /usr/lib64/python2.6/site-packages/zope/interface/interfaces.pyt isOrExtendsa s c C s d S( s/ 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. N( ( t callback( ( s? /usr/lib64/python2.6/site-packages/zope/interface/interfaces.pyt weakrefe s so Base specifications A tuple if specifications from which this specification is directly derived. s Specification-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.) s Interface-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.) c C s d S( s| Look up the description for a name If the named attribute is not defined, the default is returned. N( ( t nameR ( ( s? /usr/lib64/python2.6/site-packages/zope/interface/interfaces.pyt get s N( R R R t TrueR R R R R t __bases__t __sro__t __iro__R ( ( ( s? /usr/lib64/python2.6/site-packages/zope/interface/interfaces.pyR U s t IInterfacec B st e Z d Z d Z d Z e d Z e d Z d Z d Z d d Z d Z d Z e d Z RS( sE Interface objects Interface objects describe the behavior of an object by containing useful information about the object. This information includes: o 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. o Descriptions of attributes. Attribute descriptions include the name of the attribute and prose documentation describing the attributes usage. o 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. o 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 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: o 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. o You query interface meta-data. See the IInterface methods and attributes for details. c C s d S( s Test 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. N( ( t object( ( s? /usr/lib64/python2.6/site-packages/zope/interface/interfaces.pyt providedBy s c C s d S( s Test 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. N( ( t class_( ( s? /usr/lib64/python2.6/site-packages/zope/interface/interfaces.pyt implementedBy s c C s d S( se Get 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. N( ( t all( ( s? /usr/lib64/python2.6/site-packages/zope/interface/interfaces.pyt names s c C s d S( s Get 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. N( ( R&