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:
Call zope.interface.implements in your class definition.
Call zope.interfaces.directlyProvides on your object.
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.
__module__
(Attribute)
The name of the module defining the interface
__sro__
(Attribute)
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.)
__bases__
(Attribute)
Base specifications
A tuple if specifications from which this specification is directly derived.
__doc__
(Attribute)
The object doc string
__name__
(Attribute)
The object name
* = required
isOrExtends(other)
Test whether the specification is or extends another
implementedBy(class_)
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.
queryTaggedValue(tag, default=None)
Returns the value associated with tag.
Return the default value of the tag isn't set.
getTaggedValueTags()
Returns a list of all tags.
__getitem__(name)
Get the description for a name
If the named attribute is not defined, a KeyError is raised.
get(name, default=None)
Look up the description for a name
If the named attribute is not defined, the default is returned.
setTaggedValue(tag, value)
Associates value with key.
__contains__(name)
Test whether the name is defined by the interface
direct(name)
Get the description for the name if it was defined by the interface
If the interface doesn't define the name, returns None.
weakref(callback=None)
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.
__iter__()
Return 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.
extends(other, strict=True)
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.
names(all=False)
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.
providedBy(object)
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.
namesAndDescriptions(all=False)
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.
validateInvariants(obj, errors=None)
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.
getTaggedValue(tag)
Returns the value associated with tag.
Raise a KeyError of the tag isn't set.
There are no specific adapters registered for this interface.
There are no extended adapters registered for this interface.
zope.app.tree.interfaces.INode
zope.app.publisher.interfaces.http.ILogout
z3checkins.interfaces.IMessage
zope.schema.interfaces.IBytes
zope.app.onlinehelp.interfaces.IOnlineHelp
zope.securitypolicy.interfaces.IRole
zope.app.folder.interfaces.IFolder
zope.session.interfaces.ISession
zope.component.interfaces.IUnregistered
buddydemo.interfaces.IBuddyFolder
zope.tales.interfaces.ITALESIterator
zope.i18n.interfaces.locales.ILocaleCurrency
zope.schema.interfaces.IDate
zope.app.dav.interfaces.IDAVSchema
zope.index.text.interfaces.ISearchableText
zope.app.broken.interfaces.IBroken
zope.app.file.interfaces.IImage
zope.app.container.interfaces.INameChooser
zope.app.dependable.interfaces.IDependable
zope.app.undo.interfaces.IUndo
zope.app.menus.add_registration
zope.schema.interfaces.IInt
zope.i18n.interfaces.IDateTimeFormat
zope.app.sqlscript.interfaces.ISQLScript
zope.app.i18nfile.interfaces.II18nFile
zope.app.catalog.interfaces.ICatalogEdit
zope.app.tree.interfaces.IUniqueId
zope.schema.interfaces.IField
zope.app.security.interfaces.ILoginPassword
zope.component.interfaces.IRegistered
zope.app.renderer.stx.IStructuredTextSource
zope.app.css.layer
zope.schema.interfaces.IVocabularyTokenized
zope.schema.interfaces.IMinMax
zope.app.intid.interfaces.IIntIdRemovedEvent
zope.schema.interfaces.IChoice
zope.app.basicskin.IBasicSkin
zope.app.i18nfile.interfaces.II18nImage
zope.app.tree.interfaces.ITreeStateEncoder
zope.size.interfaces.ISized
zope.app.form.browser.interfaces.ITerms
zope.app.form.interfaces.IWidgetInputError
z3checkins.interfaces.ICheckinFolderSchema
zope.app.menus.add_stateful_states
zope.schema.interfaces.IBool
zope.app.tree.interfaces.IChildObjects
zope.app.apidoc.browser.skin.apidoc
zope.app.menus.zmi_views
zope.formlib.interfaces.ISubPageForm
zope.app.intid.interfaces.IIntIdsManage
zope.i18n.interfaces.locales.ILocaleFormat
zope.schema.interfaces.IList
zope.app.container.interfaces.IContainer
zope.app.intid.interfaces.IIntIdAddedEvent
zope.app.boston.IJavaScript
zope.app.boston.ICSS
zope.app.intid.interfaces.IIntIds
zope.formlib.interfaces.IAction
zope.app.cache.interfaces.ICacheable
zope.publisher.interfaces.IPublishTraverse
zope.location.interfaces.ISublocations
zope.security.interfaces.IPrincipal
zope.index.interfaces.IStatistics
zope.publisher.interfaces.ftp.IFTPRequest
zope.app.renderer.plaintext.IPlainTextSource
zope.app.menus.add_registration
zope.interface.Interface
zope.app.dav.interfaces.IXMLText
zope.schema.interfaces.IFrozenSet
zope.schema.interfaces.IBytesLine
zope.schema.interfaces.ISource
zope.schema.interfaces.IVocabularyFactory
zope.i18n.interfaces.IMessageCatalog
zope.exceptions.interfaces.IUserError
zope.app.menus.add_stateful_transitions
zope.app.apidoc.browser.skin.APIDOC
zope.app.boston.boston
zope.app.form.interfaces.IInputWidget
zope.app.cache.interfaces.ram.IRAMCache
zope.app.tree.browser.IStaticTreeSkin
zope.location.interfaces.IPossibleSite
zope.schema.interfaces.IASCIILine
zope.interface.interfaces.IInterface
zope.i18n.interfaces.IMessageExportFilter
zope.app.dtmlpage.interfaces.IDTMLPage
zope.app.menus.zmi_actions
zope.app.boston.ILeft
zope.app.menus.add_stateful_states
zope.copypastemove.interfaces.IObjectCopier
zope.publisher.interfaces.IRequest
zope.app.tree.browser.IStaticTreeLayer
zope.publisher.interfaces.ftp.IFTPPublisher
zope.app.http.interfaces.INullResource
zope.app.apidoc.browser.skin.apidoc
zope.app.menus.help_actions
zope.session.interfaces.IClientId
zope.app.menus.add_stateful_transitions
zope.app.publisher.xmlrpc.IMethodPublisher
zope.securitypolicy.interfaces.IGrantInfo
zope.formlib.interfaces.IActions
zope.publisher.interfaces.http.IHTTPRequest
zope.app.publication.interfaces.IFileContent
zope.app.dav.interfaces.IDAVNamespace
z3checkins.interfaces.ICheckinFolder
zope.app.menus.add_component
zope.session.interfaces.ISessionData
zope.app.file.interfaces.IFile
zope.app.twisted.interfaces.IServerType
zope.schema.interfaces.IText
zope.app.catalog.text.ITextIndex
zope.app.file.interfaces.IImage
zope.traversing.interfaces.IPathAdapter
zope.app.container.interfaces.IItemContainer
zope.app.undo.interfaces.IPrincipalUndo
zope.session.interfaces.ISessionPkgData
zope.app.menus.help_actions
buddydemo.interfaces.IPostalLookup
zope.app.sqlscript.interfaces.ISQLScript
zope.schema.interfaces.IObject
zope.component.interfaces.IObjectEvent
zope.app.pythonpage.IPythonPage
zope.i18n.interfaces.locales.ILocaleTimeZone
zope.app.zptpage.interfaces.IRenderZPTPage
persistent.interfaces.IPersistent
z3checkins.interfaces.IMessageParser
zope.app.catalog.interfaces.ICatalog
zope.traversing.interfaces.ITraverser
zope.schema.interfaces.ISourceText
zope.app.tree.browser.IStaticTreeLayer
zope.app.catalog.interfaces.ICatalogQuery
zope.copypastemove.interfaces.IObjectMover
zope.app.boston.Boston
zope.app.i18nfile.interfaces.II18nImage
zope.formlib.interfaces.IPageForm
zope.schema.interfaces.ISet
zope.schema.interfaces.IPassword
zope.formlib.namedtemplate.INamedTemplate
zope.app.intid.interfaces.IIntIdsSet
zope.schema.interfaces.IASCII
zope.app.workflow.stateful.interfaces.IState
zope.schema.interfaces.ITokenizedTerm
zope.schema.interfaces.IDatetime
zope.traversing.interfaces.ITraversable
zope.app.catalog.interfaces.IAttributeIndex
zope.publisher.interfaces.http.IHTTPResponse
zope.annotation.interfaces.IAnnotations
zope.schema.interfaces.IBaseVocabulary
zope.app.publication.http.IMethodNotAllowed
zope.app.container.interfaces.IContained
zope.sendmail.interfaces.IMailDelivery
zope.schema.interfaces.IAbstractSet
zope.schema.interfaces.IDecimal
zope.app.zptpage.interfaces.IZPTPage
zope.rdb.interfaces.IZopeConnection
zope.app.rotterdam.Rotterdam
zope.schema.interfaces.ICollection
zope.app.container.interfaces.IFind
zope.schema.interfaces.ITitledTokenizedTerm
zope.app.menus.zmi_views
zope.app.menus.zmi_actions
zope.i18n.interfaces.INegotiator
zope.i18n.interfaces.IUserPreferredCharsets
zope.app.container.interfaces.IReadContainer
zope.filerepresentation.interfaces.IReadFile
zope.i18n.interfaces.locales.ILocale
zope.app.menus.add_component
zope.i18n.interfaces.IMessageImportFilter
zope.component.interfaces.IComponentLookup
zope.app.catalog.field.IFieldIndex
zope.app.folder.interfaces.IFolder
zope.i18n.interfaces.locales.ILocaleDates
zope.app.security.interfaces.IEveryoneGroup
zope.interface.common.mapping.IItemMapping
zope.app.rotterdam.rotterdam
zope.app.zopetop.ZopeTop
zope.component.interfaces.IFactory
zope.traversing.interfaces.IContainmentRoot
zope.dublincore.interfaces.IZopeDublinCore
zope.app.i18nfile.interfaces.II18nFile
zope.i18n.interfaces.INumberFormat
zope.security.interfaces.IUnauthorized
zope.i18n.interfaces.locales.ILocaleNumbers
zope.schema.interfaces.ISequence
zope.app.dtmlpage.interfaces.IRenderDTMLPage
zope.rdb.interfaces.IZopeDatabaseAdapter
zope.app.boston.IHead
zope.component.interfaces.IRegistrationEvent
zope.session.http.ICookieClientIdManager
zope.app.boston.IToolBar
zope.app.intid.interfaces.IIntIdsQuery
zope.i18n.interfaces.locales.ILocaleVersion
zope.publisher.interfaces.INotFound
zope.app.apidoc.bookmodule.book.IBookModule
zope.app.css.layer
zope.error.interfaces.IErrorReportingUtility
zope.app.security.interfaces.ILogout
zope.security.interfaces.IPermission
zope.app.file.interfaces.IFile
zope.schema.interfaces.ITuple
zope.publisher.interfaces.http.IResult
zope.location.interfaces.ILocation
buddydemo.interfaces.IBuddy
zope.app.rotterdam.rotterdam
zope.app.pythonpage.IPythonPage
zope.annotation.interfaces.IAnnotatable
zope.schema.interfaces.ITextLine
zope.schema.interfaces.IIterableSource
zope.interface.common.interfaces.IException
zope.app.security.interfaces.IAuthentication
zope.app.css.CSS
z3checkins.interfaces.ICheckinMessage
zope.schema.interfaces.IURI
zope.app.dav.interfaces.IDAVWidget
zope.app.interpreter.interfaces.IInterpreter
zope.app.boston.boston
zope.i18n.interfaces.ITranslationDomain
zope.app.cache.interfaces.ICache
zope.formlib.interfaces.IWidgets
ZODB.interfaces.IConnection
zope.app.publisher.interfaces.http.ILogin
zope.app.catalog.interfaces.ICatalogIndex
zope.i18n.interfaces.locales.ILocaleIdentity
zope.schema.interfaces.IMinMaxLen
zope.app.content.interfaces.IContentType
zope.app.form.interfaces.IDisplayWidget
buddydemo.interfaces.IPostalInfo
zope.app.zapi.interfaces.IZAPI
zope.i18n.interfaces.locales.ILocaleCalendar
zope.interface.interfaces.IAttribute
zope.location.interfaces.ISite
zope.app.dtmlpage.interfaces.IDTMLPage
zope.rdb.interfaces.IZopeCursor
z3checkins.interfaces.IBookmark
zope.app.container.interfaces.IAdding
zope.schema.interfaces.IFloat
zope.app.homefolder.interfaces.IHomeFolder
zope.app.zptpage.interfaces.IZPTPage