(Name: "zope.session.http.ICookieClientIdManager")

Component: zope.session.http.ICookieClientIdManager

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.


* = required