Commit 2e43df17 authored by Michel Pelletier's avatar Michel Pelletier

removed interfaces

parent 482bdda9
from Zope.Interfaces.Interface import Interface
class RoleManager:
"""
Description of the RoleManager interface
"""
def ac_inherited_permissions(self, all=0):
"""
Get all permissions not defined in ourself that are inherited.
Returns a sequence of tuples with a name as the first item an
an empty tuple as the second.
"""
def permission_settings(self):
"""
Return user-role permission settings.
"""
def permissionsOfRole(self, role):
"""
Return the permissions that this Role maps to.
"""
def rolesOfPermission(self, permission):
"""
Returns roles that have 'permission'.
"""
def acquiredRolesAreUsedBy(self, permission):
"""
I have no idea.
"""
def has_local_roles(self):
"""
Returns the number of local roles for 'self', otherwiser
returns a false value.
"""
def get_local_roles(self):
"""
Returns a sequence of local roles for 'self'.
"""
def get_valid_userids(self):
"""
who knows.
"""
def get_local_roles_for_userid(self, userid):
"""
who knows.
"""
def valid_roles(self):
"""
Returns a list of valid roles.
"""
def validate_roles(self, roles):
"""
Returns a true value if all given roles are valid.
"""
def userdefined_roles(self):
"""
Returns a list of user defined roles.
"""
RoleManagerInterface=Interface(RoleManager) # create the interface object
from Zope.Interfaces.Interface import Interface
class Node:
"""
A node.
"""
NodeInterface=Interface(Node) # create the interface object
class Document:
"""A document.
"""
__extends__ = (NodeInterface,)
DocumentInterface=Interface(Document) # create the interface object
class Element:
"""An element.
"""
__extends__ = (NodeInterface,)
ElementInterface=Interface(Element) # create the interface object
from Zope.Interfaces.Interface import Interface
from OFS.ItemInterface import ItemInterface
class Vocabulary:
"""
Vocabulary objects encapsulate language dependent features for
text indexing. This is mostly used by the ZCatalog, but other
objects that require language dependent features may use
Vocabulary objects.
The main task of a Vocabulary object is to maintain a mapping from
integers (called 'word ids') to 'words'. In this sense, 'words'
can be any string of characters in any language. To understand
why this is useful, a little background on text indexing will be given.
In general, text indexes maintain a mapping from words to a list
of 'objects' that contain that word. This is just like the index
in the back of a book, which maintains a mapping from a word to a
list of pages in the book where that word occurs. In the case of
a book, the 'objects' are pages in the book. An index typically
looks like this::
foo -> (1, 5, 13, 66)
bar -> (5, 42)
Here, 'foo' and 'bar' are mapped to lists of 'objects' (or pages,
or whatever), that contain them.
The ZCatalog's text indexes in Zope work almost identically, but
instead of mapping a *word* to a list of objects, it maps a *word
id*. This word id is an integer.
Vocabulary objects maintain this mapping from word to word id.
Because they are seperated out into a different object, ZCatalogs
can work with a variety of Vocabulary objects that implement this
interface. This means that the ZCatalog is entirely language
neutral, and supporting other languages, and their possibly wildly
different concept of 'word', is mearly an excercise in creating a
new kind of Vocabulary object; there is no need to rewrite
something as complex as the ZCatalog to support new languages.
"""
__extends__ = (ItemInterface,)
def query(self, pattern):
"""
Returns a sequence of integer word ids for words that match
'pattern'. Vocabulary objects many interpret this pattern in
any way. For example, the current implementation of Zope's
vocabulary object's can be either globbing or non-globbing.
Non-globbing vocabularies do not interpret 'pattern' in any
special way and will allways return a sequence of 1 or less
integers. Globbing Vocabulary objects understand a minimal
set of 'globbing' wildcard characters that are be default '*'
and '?'. Globbing lexicons will return a sequence of zero or
more word ids for words that match the globbing 'pattern'.
"""
def insert(self, word=''):
"""
Inserts 'word' into the Vocabulary mapping and assigns it a
new word id. This method returns nothing.
"""
def words(self):
"""
Returns a sequence of all words in the Vocabulary.
"""
VocabularyInterface=Interface(Vocabulary) # create the interface object
from Zope.Interfaces.Interface import Interface
from OFS.FolderInterface import FolderInterface
class ZCatalog:
"""
ZCatalog's support indexing and searching for Zope objects. A
ZCatalog is basically a collection of indexes. The ZCatalog
object is a web managble interface to add and delete indexes and
to find objects to catalog.
"""
__extends__ = (FolderInterface,)
def catalog_object(self, obj, uid):
"""
This method will catalog the object 'obj' with the unique id
'uid'. By convention, the 'uid' is the object's path in Zope,
but this is not set in stone. This method returns nothing.
"""
def uncatalog_object(self, uid):
"""
This method will uncatalog any reference to 'uid'. If the
catalog has no reference to 'uid', an error will NOT be
raised. This method returns nothing.
"""
def uniqueValuesFor(self, name):
"""
Return a sequece of all uniquely indexed values in the index
'name'. 'name' is a string that identifies the index you want
unique values for. Note that some indexes do not support this
notion, and will raise an error if you call this method on
them. Currently, only FieldIndexes and KeywordIndexes support
the notion of uniqueValuesFor.
"""
def getpath(self, rid):
"""
Record objects returned by catalog queries have a special
integer id called a 'record id' (rid). It is often useful to
ask the catalog what unique id (uid) this rid maps to. Since
the convention is for uids to be paths, this method is called
getpath, although it is probably better named getuid. This
method returns the uid that maps to rid.
"""
def getobject(self, rid, REQUEST=None):
"""
This method works like getpath, except that it goes one step
further and tries to resolve the path into the actual object
that uid uniquely defines. This method depends on uid being a
path to the object, so don't use this if you use your own
uids. This method returns an object or raises an
NotFoundError if the object is not found.
"""
def schema(self):
"""
This method returns a sequence of meta-data table names. This
sequence of names is often refered to as the 'schema' for
record objects.
"""
def indexes(self):
"""
This method returns a sequece of index names.
"""
def index_objects(self):
"""
This method returns a sequence of actual index objects.
"""
def searchResults(self, REQUEST=None, **kw):
"""
This is the main query method for a ZCatalog. It is named
'searchResults' for historical reasons. This is usually
because this method is used from DTML with the in tag, and it
reads well::
<dtml-in searchResults>
<dtml-var id>
</dtml-in>
This is one way to call this method. In this case, you are
passing no argument explicitly, and the DTML engine will pass
the 'REQUEST' object in as the first argument to this method.
The REQUEST argument must be a mapping from index name to
search term. Like this:
Catalog.searchResults({'id' : 'Foo'})
This will search the 'id' index for objects that have the id
'Foo'. More than one index query can be passed at one time.
The various queries are implicitly intersected, also know as
'ANDed'. So:
Catalog.searchResults({'id' : 'Foo',
'title' : 'Bar'})
will search for objects that have the id 'Foo' AND the title
'Bar'. Currently unions ('ORing') is not supported, but is
planned.
searchResults returns a sequence of 'Record Objects'. Record
objects are descriptions of cataloged objects that match the
query terms. Record objects are NOT the objects themselves,
but the objects themselvles can be found with the 'getobject'
method.
Record Objects have attributes that corespond to entries in
the meta-data table. When an object is cataloged, the value
of any attributes it has that have the same name as a
meta-data table entry will get recorded by the meta-data
table. This information is then stuffed into the record
that is returned by the ZCatalog.
"""
def getVocabulary(self):
"""
This method returns the Vocabulary object being used by this
ZCatalog.
"""
ZCatalogInterface=Interface(ZCatalog) # create the interface object
import types
class Interface:
"""
Describes an interface.
"""
__extends__=()
def __init__(self, klass, name=None):
# Creates an interface instance given a python class.
# the class describes the inteface; it contains
# methods, arguments and doc strings.
#
# The name of the interface is deduced from the __name__
# attribute.
#
# The base interfaces are deduced from the __extends__
# attribute.
if name is not None:
self.name = name
else:
self.name=klass.__name__
self.doc=klass.__doc__
if hasattr(klass,'__extends__'):
self.extends=klass.__extends__
# Get info on attributes, ignore
# attributes that start with underscore.
self.attributes=[]
for k,v in klass.__dict__.items():
if k[0] != '_':
if type(v)==types.FunctionType:
self.attributes.append(Method(v))
else:
self.attributes.append(Attribute(k))
def getAttributes(self):
"""
Returns the interfaces attributes.
"""
return self.attributes
class Attribute:
"""
Describes an attribute of an interface.
"""
permission="" # how to indicate permissions, in docstrings?
def __init__(self, name):
self.name=name
self.doc="" # how to get doc strings from attributes?
class Method(Attribute):
"""
Describes a Method attribute of an interface.
required - a sequence of required arguments
optional - a sequence of tuples (name, default value)
varargs - the name of the variable argument or None
kwargs - the name of the kw argument or None
"""
varargs=None
kwargs=None
def __init__(self, func):
self.name=func.__name__
self.doc=func.__doc__
# figure out the method arguments
# mostly stolen from pythondoc
CO_VARARGS = 4
CO_VARKEYWORDS = 8
names = func.func_code.co_varnames
nrargs = func.func_code.co_argcount
if func.func_defaults:
nrdefaults = len(func.func_defaults)
else:
nrdefaults = 0
self.required = names[:nrargs-nrdefaults]
if func.func_defaults:
self.optional = tuple(map(None, names[nrargs-nrdefaults:nrargs],
func.func_defaults))
else:
self.optional = ()
varargs = []
ix = nrargs
if func.func_code.co_flags & CO_VARARGS:
self.varargs=names[ix]
ix = ix+1
if func.func_code.co_flags & CO_VARKEYWORDS:
self.kwargs=names[ix]
if __name__=='__main__':
class T:
"test interface description"
__name__="org.zope.test"
a=None
def foo(self, a, b=None, *c, **d):
"foo description"
i=Interface(T)
print i.name
print i.doc
for a in i.getAttributes():
print a.__dict__
##############################################################################
#
# Zope Public License (ZPL) Version 1.0
# -------------------------------------
#
# Copyright (c) Digital Creations. All rights reserved.
#
# This license has been certified as Open Source(tm).
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions in source code must retain the above copyright
# notice, this list of conditions, and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions, and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# 3. Digital Creations requests that attribution be given to Zope
# in any manner possible. Zope includes a "Powered by Zope"
# button that is installed by default. While it is not a license
# violation to remove this button, it is requested that the
# attribution remain. A significant investment has been put
# into Zope, and this effort will continue if the Zope community
# continues to grow. This is one way to assure that growth.
#
# 4. All advertising materials and documentation mentioning
# features derived from or use of this software must display
# the following acknowledgement:
#
# "This product includes software developed by Digital Creations
# for use in the Z Object Publishing Environment
# (http://www.zope.org/)."
#
# In the event that the product being advertised includes an
# intact Zope distribution (with copyright and license included)
# then this clause is waived.
#
# 5. Names associated with Zope or Digital Creations must not be used to
# endorse or promote products derived from this software without
# prior written permission from Digital Creations.
#
# 6. Modified redistributions of any form whatsoever must retain
# the following acknowledgment:
#
# "This product includes software developed by Digital Creations
# for use in the Z Object Publishing Environment
# (http://www.zope.org/)."
#
# Intact (re-)distributions of any official Zope release do not
# require an external acknowledgement.
#
# 7. Modifications are encouraged but must be packaged separately as
# patches to official Zope releases. Distributions that do not
# clearly separate the patches from the original work must be clearly
# labeled as unofficial distributions. Modifications which do not
# carry the name Zope may be packaged in any form, as long as they
# conform to all of the clauses above.
#
#
# Disclaimer
#
# THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
# EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
#
# This software consists of contributions made by Digital Creations and
# many individuals on behalf of Digital Creations. Specific
# attributions are listed in the accompanying credits file.
#
##############################################################################
"""
InterfaceImplementer -- Mixin class for objects that support interfaces
"""
class InterfaceImplementer:
"""
Mix-in class to support interfaces.
Interface implementation is indicated
with the __implements__ class attribute
that should be a tuple of Interface objects.
"""
def implementedInterfaces(self):
"""
Returns a sequence of Interface objects
that the object implements.
"""
return self.__implements__
##############################################################################
#
# Zope Public License (ZPL) Version 1.0
# -------------------------------------
#
# Copyright (c) Digital Creations. All rights reserved.
#
# This license has been certified as Open Source(tm).
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions in source code must retain the above copyright
# notice, this list of conditions, and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions, and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# 3. Digital Creations requests that attribution be given to Zope
# in any manner possible. Zope includes a "Powered by Zope"
# button that is installed by default. While it is not a license
# violation to remove this button, it is requested that the
# attribution remain. A significant investment has been put
# into Zope, and this effort will continue if the Zope community
# continues to grow. This is one way to assure that growth.
#
# 4. All advertising materials and documentation mentioning
# features derived from or use of this software must display
# the following acknowledgement:
#
# "This product includes software developed by Digital Creations
# for use in the Z Object Publishing Environment
# (http://www.zope.org/)."
#
# In the event that the product being advertised includes an
# intact Zope distribution (with copyright and license included)
# then this clause is waived.
#
# 5. Names associated with Zope or Digital Creations must not be used to
# endorse or promote products derived from this software without
# prior written permission from Digital Creations.
#
# 6. Modified redistributions of any form whatsoever must retain
# the following acknowledgment:
#
# "This product includes software developed by Digital Creations
# for use in the Z Object Publishing Environment
# (http://www.zope.org/)."
#
# Intact (re-)distributions of any official Zope release do not
# require an external acknowledgement.
#
# 7. Modifications are encouraged but must be packaged separately as
# patches to official Zope releases. Distributions that do not
# clearly separate the patches from the original work must be clearly
# labeled as unofficial distributions. Modifications which do not
# carry the name Zope may be packaged in any form, as long as they
# conform to all of the clauses above.
#
#
# Disclaimer
#
# THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
# EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
#
# This software consists of contributions made by Digital Creations and
# many individuals on behalf of Digital Creations. Specific
# attributions are listed in the accompanying credits file.
#
##############################################################################
from Interface import Interface
class _Interface:
""" This is the Interface for Interface objects """
def defered(self):
"""
Returns a defered class corresponding to the interface
"""
def extends(self, other):
"""
Does this Interface extend 'other'?
"""
def implementedBy(self, object):
"""
Does 'object' implement this Interface?
"""
def implementedByInstancesOf(self, klass):
"""
Do instances of the given class implement the interface?
"""
def implements(self):
"""
Returns a sequence of base interfaces
"""
def names(self):
"""
Returns the attribute names defined by the interface
"""
def namesAndDescriptions(self):
"""
Return the attribute names and descriptions defined by the interface
"""
def getDescriptionFor(self, name, default=None):
"""
Return the attribute description for the given name
"""
InterfaceInterface = Interface(_Interface, 'InterfaceInterface')
##############################################################################
#
# Zope Public License (ZPL) Version 1.0
# -------------------------------------
#
# Copyright (c) Digital Creations. All rights reserved.
#
# This license has been certified as Open Source(tm).
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions in source code must retain the above copyright
# notice, this list of conditions, and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions, and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# 3. Digital Creations requests that attribution be given to Zope
# in any manner possible. Zope includes a "Powered by Zope"
# button that is installed by default. While it is not a license
# violation to remove this button, it is requested that the
# attribution remain. A significant investment has been put
# into Zope, and this effort will continue if the Zope community
# continues to grow. This is one way to assure that growth.
#
# 4. All advertising materials and documentation mentioning
# features derived from or use of this software must display
# the following acknowledgement:
#
# "This product includes software developed by Digital Creations
# for use in the Z Object Publishing Environment
# (http://www.zope.org/)."
#
# In the event that the product being advertised includes an
# intact Zope distribution (with copyright and license included)
# then this clause is waived.
#
# 5. Names associated with Zope or Digital Creations must not be used to
# endorse or promote products derived from this software without
# prior written permission from Digital Creations.
#
# 6. Modified redistributions of any form whatsoever must retain
# the following acknowledgment:
#
# "This product includes software developed by Digital Creations
# for use in the Z Object Publishing Environment
# (http://www.zope.org/)."
#
# Intact (re-)distributions of any official Zope release do not
# require an external acknowledgement.
#
# 7. Modifications are encouraged but must be packaged separately as
# patches to official Zope releases. Distributions that do not
# clearly separate the patches from the original work must be clearly
# labeled as unofficial distributions. Modifications which do not
# carry the name Zope may be packaged in any form, as long as they
# conform to all of the clauses above.
#
#
# Disclaimer
#
# THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
# EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
#
# This software consists of contributions made by Digital Creations and
# many individuals on behalf of Digital Creations. Specific
# attributions are listed in the accompanying credits file.
#
##############################################################################
import InterfaceInterface
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment