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

View file

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

View file

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

View file

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