typology: Python3 fixes; + update of example data

This commit is contained in:
Helmut Merz 2024-09-23 15:05:10 +02:00
parent 61c78fe3e7
commit b8eba239ed
4 changed files with 18 additions and 61 deletions

View file

@ -1,8 +1,6 @@
A Basic API for Dynamic Typing
==============================
($Id$)
The typology package offers a basic standard API for associating
arbitrary objects with types that may then be used for controlling
execution of code, helping with search interfaces or editing of
@ -20,9 +18,9 @@ we will then apply dynamic typing to Person objects:
>>> from cybertools.organize.party import Person
>>> from datetime import date
>>> pdata = ((u'John', u'Smith', '1956-08-01'),
... (u'David', u'Waters', '1972-12-24'),
... (u'Carla', u'Myers', '1999-10-11'))
>>> pdata = (('John', 'Smith', '1956-08-01'),
... ('David', 'Waters', '1972-12-24'),
... ('Carla', 'Myers', '2015-10-11'))
>>> persons = [Person(f, s, date(*[int(d) for d in b.split('-')]))
... for f, s, b in pdata]
@ -51,7 +49,7 @@ a global utility that does the real work.
We can now look what the type is telling us about the persons:
>>> john_type.title
u'Adult'
'Adult'
>>> john_type.token
'organize.person.agegroup.adult'
>>> david_type.token
@ -90,7 +88,7 @@ another (possibly persistent) object knowing about the available types.
>>> typeManager = component.getUtility(IAgeGroupManager)
>>> types = typeManager.types
>>> [t.title for t in types]
[u'Child', u'Adult']
['Child', 'Adult']
>>> types[0] == carla_type
True
>>> types[1] == john_type == david_type
@ -98,4 +96,4 @@ another (possibly persistent) object knowing about the available types.
>>> t = typeManager.getType(carla_type.token)
>>> t.title
u'Child'
'Child'

View file

@ -1,30 +1,12 @@
#
# Copyright (c) 2006 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
#
# cybertools.typology.example.person
"""
Example classes for the cybertools.reporter package. These use the
cybertools.organize package
""" Example classes for the cybertools.typology package.
$Id$
These use the cybertools.organize package
"""
from zope.component import adapts
from zope.interface import implements
from zope.interface import implementer
from cybertools.organize.interfaces import IPerson
from cybertools.typology.interfaces import IType, ITypeManager
from cybertools.typology.type import BaseType, TypeManager
@ -44,9 +26,9 @@ class IAgeGroupManager(ITypeManager):
# implementations
@implementer(IAgeGroup)
class AgeGroup(BaseType):
implements(IAgeGroup)
adapts(IPerson)
# IType attributes
@ -75,10 +57,9 @@ class AgeGroupTypeInfo(AgeGroup):
self.isChild = isChild
@implementer(IAgeGroupManager)
class AgeGroupManager(TypeManager):
implements(IAgeGroupManager)
@property
def types(self):
return tuple([AgeGroupTypeInfo(flag) for flag in (True, False)])

View file

@ -1,9 +1,8 @@
# $Id$
# cybertools.typology.tests
import unittest, doctest
from zope.app.testing import ztapi
from zope.interface.verify import verifyClass
from zope.interface import implements
from cybertools.typology.interfaces import IType, ITypeManager

View file

@ -1,35 +1,15 @@
#
# Copyright (c) 2006 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
#
# cybertools.typology.type
"""
Abstract base classes for type management.
$Id$
""" Abstract base classes for type management.
"""
from zope.interface import implements
from zope.interface import implementer
from cybertools.typology.interfaces import IType, ITypeManager
@implementer(IType)
class BaseType(object):
implements(IType)
def __init__(self, context):
self.context = context
@ -57,10 +37,9 @@ class BaseType(object):
return []
@implementer(ITypeManager)
class TypeManager(object):
implements(ITypeManager)
@property
def types(self):
return (BaseType(None),)