relation: Python3 fixes
This commit is contained in:
parent
f9a3326ec7
commit
3ec90f4b66
3 changed files with 20 additions and 39 deletions
|
@ -1,8 +1,6 @@
|
||||||
Quickstart Instructions
|
Quickstart Instructions
|
||||||
=======================
|
=======================
|
||||||
|
|
||||||
($Id$)
|
|
||||||
|
|
||||||
In the ++etc++/default folder of your Zope 3 site create a Unique Id Utility
|
In the ++etc++/default folder of your Zope 3 site create a Unique Id Utility
|
||||||
and a relation registry.
|
and a relation registry.
|
||||||
|
|
||||||
|
@ -87,15 +85,16 @@ reference these objects via IntIds later; the __parent__ and __name__
|
||||||
attributes are also needed later when we send an IObjectRemovedEvent event):
|
attributes are also needed later when we send an IObjectRemovedEvent event):
|
||||||
|
|
||||||
>>> from persistent import Persistent
|
>>> from persistent import Persistent
|
||||||
>>> from zope.interface import implements
|
>>> from zope.interface import implementer
|
||||||
>>> from cybertools.relation.interfaces import IRelatable
|
>>> from cybertools.relation.interfaces import IRelatable
|
||||||
|
|
||||||
>>> class Person(Persistent):
|
>>> class Person(Persistent):
|
||||||
... __name__ = __parent__ = None
|
... __name__ = __parent__ = None
|
||||||
... implements(IRelatable)
|
>>> Person = implementer(IRelatable)(Person)
|
||||||
|
|
||||||
>>> class City(Persistent):
|
>>> class City(Persistent):
|
||||||
... implements(IRelatable)
|
... pass
|
||||||
|
>>> City = implementer(IRelatable)(City)
|
||||||
|
|
||||||
>>> clark = Person()
|
>>> clark = Person()
|
||||||
>>> kirk = Person()
|
>>> kirk = Person()
|
||||||
|
@ -396,10 +395,8 @@ We also need a class for the predicate objects that will be used for
|
||||||
the constructor of the NamedPredicateRelation class:
|
the constructor of the NamedPredicateRelation class:
|
||||||
|
|
||||||
>>> from cybertools.relation.interfaces import IPredicate
|
>>> from cybertools.relation.interfaces import IPredicate
|
||||||
>>> from zope.interface import implements
|
|
||||||
|
|
||||||
>>> class Predicate(object):
|
>>> class Predicate(object):
|
||||||
... implements(IPredicate)
|
|
||||||
... def __init__(self, name):
|
... def __init__(self, name):
|
||||||
... self.name = name
|
... self.name = name
|
||||||
... self.forClass = None
|
... self.forClass = None
|
||||||
|
@ -407,6 +404,7 @@ the constructor of the NamedPredicateRelation class:
|
||||||
... if self.forClass is not None:
|
... if self.forClass is not None:
|
||||||
... return self.forClass(self, None, None).getPredicateName()
|
... return self.forClass(self, None, None).getPredicateName()
|
||||||
... return self.name
|
... return self.name
|
||||||
|
>>> Predicate = implementer(IPredicate)(Predicate)
|
||||||
|
|
||||||
We can now create a predicate with the name '_lives in_' (that may replace
|
We can now create a predicate with the name '_lives in_' (that may replace
|
||||||
our LivesIn relation class from above) and use for registration:
|
our LivesIn relation class from above) and use for registration:
|
||||||
|
|
|
@ -1,23 +1,6 @@
|
||||||
#
|
# cybertools.relation.registry
|
||||||
# Copyright (c) 2013 Helmut Merz helmutm@cy55.de
|
|
||||||
#
|
|
||||||
# This program is free software; you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation; either version 2 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program; if not, write to the Free Software
|
|
||||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
#
|
|
||||||
|
|
||||||
"""
|
""" Implementation of the utilities needed for the relations package.
|
||||||
Implementation of the utilities needed for the relations package.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
@ -26,9 +9,9 @@ from persistent import Persistent
|
||||||
from persistent.interfaces import IPersistent
|
from persistent.interfaces import IPersistent
|
||||||
from zope import component
|
from zope import component
|
||||||
from zope.component import adapts
|
from zope.component import adapts
|
||||||
from zope.interface import Interface, Attribute, implements
|
from zope.interface import Interface, Attribute, implementer
|
||||||
from zope.app.catalog.catalog import Catalog, ResultSet
|
from zope.catalog.catalog import Catalog, ResultSet
|
||||||
from zope.app.catalog.field import FieldIndex
|
from zope.catalog.field import FieldIndex
|
||||||
from zope.intid.interfaces import IIntIds
|
from zope.intid.interfaces import IIntIds
|
||||||
from zope.location.interfaces import ILocation
|
from zope.location.interfaces import ILocation
|
||||||
from zope.event import notify
|
from zope.event import notify
|
||||||
|
@ -36,18 +19,18 @@ from zope.interface.interfaces import ObjectEvent
|
||||||
from zope.security.proxy import removeSecurityProxy
|
from zope.security.proxy import removeSecurityProxy
|
||||||
from zope.traversing.api import getName, getParent
|
from zope.traversing.api import getName, getParent
|
||||||
|
|
||||||
from interfaces import IRelationRegistry, IRelationInvalidatedEvent, IRelation
|
from cybertools.relation.interfaces import IRelationRegistry
|
||||||
|
from cybertools.relation.interfaces import IRelationInvalidatedEvent, IRelation
|
||||||
|
|
||||||
|
|
||||||
logger = getLogger('cybertools.relation.registry')
|
logger = getLogger('cybertools.relation.registry')
|
||||||
|
|
||||||
|
|
||||||
|
@implementer(IRelationRegistry)
|
||||||
class DummyRelationRegistry(object):
|
class DummyRelationRegistry(object):
|
||||||
""" Dummy implementation for demonstration and test purposes.
|
""" Dummy implementation for demonstration and test purposes.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
implements(IRelationRegistry)
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.relations = []
|
self.relations = []
|
||||||
self.objects = []
|
self.objects = []
|
||||||
|
@ -112,12 +95,11 @@ class DummyRelationRegistry(object):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
@implementer(IRelationRegistry)
|
||||||
class RelationRegistry(Catalog):
|
class RelationRegistry(Catalog):
|
||||||
""" Local utility for registering (cataloguing) and searching relations.
|
""" Local utility for registering (cataloguing) and searching relations.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
implements(IRelationRegistry)
|
|
||||||
|
|
||||||
relations = None
|
relations = None
|
||||||
|
|
||||||
def __init__(self, *args, **kw):
|
def __init__(self, *args, **kw):
|
||||||
|
@ -202,12 +184,12 @@ class IIndexableRelation(Interface):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
@implementer(IIndexableRelation)
|
||||||
class IndexableRelationAdapter(object):
|
class IndexableRelationAdapter(object):
|
||||||
""" Adapter for providing the attributes needed for indexing
|
""" Adapter for providing the attributes needed for indexing
|
||||||
relation objects.
|
relation objects.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
implements(IIndexableRelation)
|
|
||||||
adapts(IRelation)
|
adapts(IRelation)
|
||||||
|
|
||||||
def __init__(self, context):
|
def __init__(self, context):
|
||||||
|
@ -296,8 +278,9 @@ def setRelationSingle(relation, forSecond=True):
|
||||||
|
|
||||||
# events and handlers
|
# events and handlers
|
||||||
|
|
||||||
|
@implementer(IRelationInvalidatedEvent)
|
||||||
class RelationInvalidatedEvent(ObjectEvent):
|
class RelationInvalidatedEvent(ObjectEvent):
|
||||||
implements(IRelationInvalidatedEvent)
|
pass
|
||||||
|
|
||||||
|
|
||||||
def invalidateRelations(context, event):
|
def invalidateRelations(context, event):
|
||||||
|
|
|
@ -44,15 +44,15 @@ class TestRelation(unittest.TestCase):
|
||||||
def testInterfaces(self):
|
def testInterfaces(self):
|
||||||
verifyClass(IPredicate, Relation)
|
verifyClass(IPredicate, Relation)
|
||||||
verifyClass(IRelation, Relation)
|
verifyClass(IRelation, Relation)
|
||||||
self.assert_(IDyadicRelation.providedBy(DyadicRelation(None, None)),
|
self.assertTrue(IDyadicRelation.providedBy(DyadicRelation(None, None)),
|
||||||
'Interface IDyadicRelation is not implemented by class DyadicRelation.')
|
'Interface IDyadicRelation is not implemented by class DyadicRelation.')
|
||||||
verifyClass(IDyadicRelation, DyadicRelation)
|
verifyClass(IDyadicRelation, DyadicRelation)
|
||||||
self.assert_(ITriadicRelation.providedBy(TriadicRelation(None, None, None)),
|
self.assertTrue(ITriadicRelation.providedBy(TriadicRelation(None, None, None)),
|
||||||
'Interface ITriadicRelation is not implemented by class TriadicRelation.')
|
'Interface ITriadicRelation is not implemented by class TriadicRelation.')
|
||||||
verifyClass(ITriadicRelation, TriadicRelation)
|
verifyClass(ITriadicRelation, TriadicRelation)
|
||||||
# avoid dependency on import:
|
# avoid dependency on import:
|
||||||
from cybertools.relation.registry import RelationRegistry
|
from cybertools.relation.registry import RelationRegistry
|
||||||
self.assert_(IRelationRegistry.providedBy(RelationRegistry()),
|
self.assertTrue(IRelationRegistry.providedBy(RelationRegistry()),
|
||||||
'Interface IRelationRegistry is not implemented by class RelationRegistry.')
|
'Interface IRelationRegistry is not implemented by class RelationRegistry.')
|
||||||
verifyClass(IRelationRegistry, RelationRegistry)
|
verifyClass(IRelationRegistry, RelationRegistry)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue