From 52990d1df693f06bc810b737a799b4c7e099e94c Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Sun, 22 Sep 2024 18:10:02 +0200 Subject: [PATCH] work in progress: organize: Python3 fixes --- cybertools/composer/message/base.py | 31 +++----------- cybertools/composer/rule/base.py | 41 ++++-------------- cybertools/composer/rule/instance.py | 27 ++---------- cybertools/composer/rule/tests.py | 15 +++---- cybertools/composer/rule/web.py | 24 +---------- cybertools/composer/schema/browser/common.py | 27 ++---------- cybertools/composer/schema/client.py | 33 +++----------- cybertools/composer/schema/field.py | 12 +++--- cybertools/composer/schema/instance.py | 29 +++---------- cybertools/organize/browser/report.py | 29 +++---------- cybertools/organize/party.py | 31 +++----------- cybertools/organize/service.py | 45 +++++--------------- cybertools/organize/servicemanager.txt | 31 +++++++------- cybertools/organize/task.py | 28 +++--------- cybertools/organize/work.py | 28 +++--------- cybertools/stateful/base.py | 34 +++------------ cybertools/stateful/definition.py | 35 +++------------ cybertools/util/format.py | 4 +- pyproject.toml | 2 + 19 files changed, 112 insertions(+), 394 deletions(-) diff --git a/cybertools/composer/message/base.py b/cybertools/composer/message/base.py index d9a6bd7..051c283 100644 --- a/cybertools/composer/message/base.py +++ b/cybertools/composer/message/base.py @@ -1,28 +1,9 @@ -# -# Copyright (c) 2007 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.composer.message.base -""" -Basic classes for message management. - -$Id$ +""" Basic classes for message management. """ -from zope.interface import implements +from zope.interface import implementer from cybertools.composer.base import Component, Element, Compound from cybertools.composer.base import Template @@ -30,10 +11,9 @@ from cybertools.composer.message.interfaces import IMessageManager, IMessage from cybertools.util.jeep import Jeep +@implementer(IMessageManager) class MessageManager(object): - implements(IMessageManager) - messagesFactory = Jeep messages = None @@ -50,10 +30,9 @@ class MessageManager(object): self.messages.append(message) +@implementer(IMessage) class Message(Template): - implements(IMessage) - name = u'' manager = None diff --git a/cybertools/composer/rule/base.py b/cybertools/composer/rule/base.py index a24f7dd..bbe9e45 100644 --- a/cybertools/composer/rule/base.py +++ b/cybertools/composer/rule/base.py @@ -1,30 +1,11 @@ -# -# Copyright (c) 2007 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.composer.rule.base -""" -Basic classes for rules and actions. - -$Id$ +""" Basic classes for rules and actions. """ from zope import component from zope.component import adapts -from zope.interface import implements +from zope.interface import implementer from cybertools.composer.base import Component, Element, Compound from cybertools.composer.base import Template @@ -38,10 +19,9 @@ from cybertools.util.jeep import Jeep # rules +@implementer(IRuleManager) class RuleManager(object): - implements(IRuleManager) - rulesFactory = Jeep rules = None @@ -67,10 +47,9 @@ class RuleManager(object): return result +@implementer(IRule) class Rule(Template): - implements(IRule) - name = title = description = u'' manager = None actions = None @@ -95,10 +74,9 @@ class EventType(object): self.title = title or name +@implementer(IEvent) class Event(object): - implements(IEvent) - def __init__(self, eventType, context=None, request=None): self.eventType = eventType self.name = eventType.name @@ -109,9 +87,9 @@ class Event(object): # conditions +@implementer(ICondition) class Condition(object): - implements(ICondition) adapts(IRuleInstance) def __init__(self, context): @@ -123,10 +101,9 @@ class Condition(object): # actions +@implementer(IAction) class Action(Component): - implements(IAction) - name = u'' handlerName = u'' parameters = None @@ -142,9 +119,9 @@ class Action(Component): self.handlerName = name +@implementer(IActionHandler) class ActionHandler(object): - implements(IActionHandler) adapts(IRuleInstance) def __init__(self, context): diff --git a/cybertools/composer/rule/instance.py b/cybertools/composer/rule/instance.py index e28fc20..0d9b736 100644 --- a/cybertools/composer/rule/instance.py +++ b/cybertools/composer/rule/instance.py @@ -1,38 +1,19 @@ -# -# Copyright (c) 2007 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.rule.instance -""" -Rule instance and related classes. - -$Id$ +""" Rule instance and related classes. """ from zope import component from zope.component import adapts -from zope.interface import Interface, implements +from zope.interface import Interface, implementer from cybertools.composer.instance import Instance from cybertools.composer.rule.interfaces import IRuleInstance, IActionHandler +@implementer(IRuleInstance) class RuleInstance(Instance): - implements(IRuleInstance) adapts(Interface) template = None diff --git a/cybertools/composer/rule/tests.py b/cybertools/composer/rule/tests.py index 9f3069e..280e09e 100755 --- a/cybertools/composer/rule/tests.py +++ b/cybertools/composer/rule/tests.py @@ -1,21 +1,20 @@ import unittest, doctest from email import message_from_string -from zope.interface import implements +from zope.interface import implementer from zope.sendmail.interfaces import IMailDelivery +@implementer(IMailDelivery) class TestMailer(object): - implements(IMailDelivery) - def send(self, sender, recipients, message): - print 'sender:', sender - print 'recipients:', recipients + print('sender:', sender) + print('recipients:', recipients) msg = message_from_string(message) - print 'subject:', msg['Subject'] - print 'message:' - print msg.get_payload(decode=True) + print('subject:', msg['Subject']) + print('message:') + print(msg.get_payload(decode=True)) class Test(unittest.TestCase): diff --git a/cybertools/composer/rule/web.py b/cybertools/composer/rule/web.py index 3a5a7ca..c89dfa7 100644 --- a/cybertools/composer/rule/web.py +++ b/cybertools/composer/rule/web.py @@ -1,29 +1,9 @@ -# -# Copyright (c) 2009 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.composer.rule.web -""" -Action handler for sending emails. - -$Id$ +""" Action handler for sending emails. """ from zope import component -from zope.interface import implements from cybertools.composer.rule.interfaces import IRuleManager, IRuleInstance from cybertools.composer.rule.interfaces import IActionHandler diff --git a/cybertools/composer/schema/browser/common.py b/cybertools/composer/schema/browser/common.py index b953388..de39351 100644 --- a/cybertools/composer/schema/browser/common.py +++ b/cybertools/composer/schema/browser/common.py @@ -1,32 +1,13 @@ -# -# Copyright (c) 2010 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.composer.schema.browser.common -""" -Common base class(es) for schema and other template views. - -$Id$ +""" Common base class(es) for schema and other template views. """ from datetime import datetime import time from zope import component -from zope.app.pagetemplate import ViewPageTemplateFile -from zope.app.session.interfaces import ISession +from zope.browserpage import ViewPageTemplateFile +from zope.session.interfaces import ISession from zope.cachedescriptors.property import Lazy from zope.traversing.browser.absoluteurl import absoluteURL diff --git a/cybertools/composer/schema/client.py b/cybertools/composer/schema/client.py index 9aa84e9..eb3a67a 100644 --- a/cybertools/composer/schema/client.py +++ b/cybertools/composer/schema/client.py @@ -1,25 +1,6 @@ -# -# Copyright (c) 2010 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.composer.schema.client -""" -Client implementations. - -$Id$ +""" Client implementations. """ from BTrees.OOBTree import OOBTree @@ -27,7 +8,7 @@ from persistent import Persistent from time import time from zope.cachedescriptors.property import Lazy from zope.component import adapts -from zope.interface import implements +from zope.interface import implementer from cybertools.composer.message.base import MessageManager from cybertools.composer.rule.base import RuleManager, EventType @@ -42,10 +23,9 @@ from cybertools.util.jeep import Jeep from cybertools.util.randomname import generateName +@implementer(IClientManager) class ClientManager(object): - implements(IClientManager) - clientSchemasFactory = Jeep clientsFactory = OOBTree @@ -85,10 +65,9 @@ class ClientManager(object): return name not in self.getClients() +@implementer(IClient) class Client(Persistent): - implements(IClient) - timeStamp = None def __init__(self, manager=None): @@ -96,9 +75,9 @@ class Client(Persistent): self.timeStamp = int(time()) +@implementer(IClientFactory) class ClientFactory(object): - implements(IClientFactory) adapts(IClientManager) def __init__(self, context): diff --git a/cybertools/composer/schema/field.py b/cybertools/composer/schema/field.py index de1c135..6321503 100644 --- a/cybertools/composer/schema/field.py +++ b/cybertools/composer/schema/field.py @@ -127,7 +127,7 @@ class Field(Component): if instance is not None: context = instance.context voc = (self.vocabulary or '') - if isinstance(voc, basestring): + if isinstance(voc, str): terms = self.getVocabularyTerms(voc, context, request) if terms is not None: return terms @@ -268,7 +268,7 @@ class DecimalFieldInstance(NumberFieldInstance): def display(self, value, pattern=u'#,##0.00;-#,##0.00'): if value is None: return '' - if isinstance(value, basestring): + if isinstance(value, str): if not value.isdigit(): return value value = float(value) @@ -293,7 +293,7 @@ class DateFieldInstance(NumberFieldInstance): def marshall(self, value): if not value: return '' - if isinstance(value, basestring): + if isinstance(value, str): return value try: return strftime('%Y-%m-%dT%H:%M', value.timetuple()) @@ -402,7 +402,7 @@ class ListFieldInstance(FieldInstance): return component.getAdapter(self.valueType, IFieldInstance, name=instanceName) def marshall(self, value): - if isinstance(value, basestring): + if isinstance(value, str): return value if value is None: return u'' @@ -412,12 +412,12 @@ class ListFieldInstance(FieldInstance): def display(self, value): if not value: return u'' - if isinstance(value, basestring): + if isinstance(value, str): return value return u' | '.join(unicode(self.valueFieldInstance.display(v)) for v in value) def unmarshall(self, value): - if isinstance(value, basestring): + if isinstance(value, str): value = value.split('\n') return [self.valueFieldInstance.unmarshall(v.strip()) for v in value if v.strip()] diff --git a/cybertools/composer/schema/instance.py b/cybertools/composer/schema/instance.py index 5a4236d..5283a90 100644 --- a/cybertools/composer/schema/instance.py +++ b/cybertools/composer/schema/instance.py @@ -1,29 +1,12 @@ -# -# 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 -# +# cybertools.composer.schema.instance -""" -Instance adapter classes for schemas. +""" Instance adapter classes for schemas. """ from BTrees.OOBTree import OOBTree from zope.cachedescriptors.property import Lazy from zope.component import adapts -from zope.interface import implements, Interface +from zope.interface import implementer, Interface from cybertools.composer.instance import Instance as BaseInstance from cybertools.composer.interfaces import IInstance @@ -32,9 +15,9 @@ from cybertools.composer.schema.schema import FormState from cybertools.util.jeep import Jeep +@implementer(IInstance) class Instance(BaseInstance): - implements(IInstance) adapts(Interface) aspect = 'schema.editor.default' @@ -77,9 +60,9 @@ class Instance(BaseInstance): return self.getFieldInstances() +@implementer(IInstance) class Editor(BaseInstance): - implements(IInstance) adapts(Interface) aspect = 'schema.editor.default' @@ -134,9 +117,9 @@ class Editor(BaseInstance): return formState +@implementer(IInstance) class ClientInstance(object): - implements(IInstance) adapts(IClient) attrsName = '__schema_attributes__' diff --git a/cybertools/organize/browser/report.py b/cybertools/organize/browser/report.py index e108e48..128f1fa 100644 --- a/cybertools/organize/browser/report.py +++ b/cybertools/organize/browser/report.py @@ -1,29 +1,10 @@ -# -# Copyright (c) 2010 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.organize.browser.report -""" -View classes for CSV export. - -$Id$ +""" View classes for CSV export. """ import csv -from cStringIO import StringIO +from io import StringIO import itertools from zope import component from zope.cachedescriptors.property import Lazy @@ -172,7 +153,7 @@ class RegistrationsExportCsv(BaseView): return result def encode(self, text): - if type(text) is unicode: + if isinstance(text, str): result = [] for c in text: try: @@ -180,5 +161,5 @@ class RegistrationsExportCsv(BaseView): except UnicodeEncodeError: c = '?' result.append(c) - text = ''.join(result) + text = b''.join(result) return text diff --git a/cybertools/organize/party.py b/cybertools/organize/party.py index cb0cb96..a98ea1d 100644 --- a/cybertools/organize/party.py +++ b/cybertools/organize/party.py @@ -1,38 +1,18 @@ -# -# 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.organize.party -""" -A set of simple application classes for contact management; this may be used +""" A set of simple application classes for contact management; this may be used as an example for some of the cybertools packages, but may also be the base for some real life stuff. - -$Id$ """ -from zope.interface import implements +from zope.interface import implementer from datetime import date from cybertools.organize.interfaces import IPerson, IAddress +@implementer(IPerson) class Person(object): - implements(IPerson) - def __init__(self, lastName, firstName=u'', birthDate=None): self.lastName = lastName self.firstName = firstName @@ -55,10 +35,9 @@ class Person(object): return int((dt - date(bd.year, bd.month, bd.day)).days/365.25) +@implementer(IAddress) class Address(object): - implements(IAddress) - def __init__(self, city, street=u'', lines=[], zipcode=None, country=None): self.lines = lines # a sequence of additional address lines diff --git a/cybertools/organize/service.py b/cybertools/organize/service.py index b2851f4..ad5d39b 100644 --- a/cybertools/organize/service.py +++ b/cybertools/organize/service.py @@ -1,25 +1,6 @@ -# -# Copyright (c) 2011 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.organize.service -""" -Service management classes. - -$Id$ +""" Service management classes. """ from time import time @@ -28,7 +9,7 @@ from BTrees.OOBTree import OOBTree from zope.cachedescriptors.property import Lazy from zope.component import adapts from zope import component -from zope.interface import implements, Interface +from zope.interface import implementer, Interface from cybertools.composer.interfaces import IInstance from cybertools.composer.message.base import MessageManager @@ -50,10 +31,9 @@ from cybertools.organize.interfaces import IRegistration, IRegistrationTemplate from cybertools.organize.interfaces import IClientRegistrations +@implementer(IServiceManager) class ServiceManager(ClientManager): - implements(IServiceManager) - servicesFactory = Jeep services = None @@ -69,10 +49,9 @@ class ServiceManager(ClientManager): return self.services +@implementer(IRegistration) class Registration(object): - implements(IRegistration) - number = 1 numberWaiting = 0 @@ -89,10 +68,9 @@ class PersistentRegistration(Registration, Persistent): pass +@implementer(IService) class Service(object): - implements(IService) - registrationsFactory = OOBTree registrationFactory = PersistentRegistration subservicesFactory = Jeep @@ -234,10 +212,9 @@ class Service(object): return getattr(self.getManager(), 'allowDirectRegistration', None) +@implementer(IScheduledService) class ScheduledService(Service): - implements(IScheduledService) - start = end = None # default methods @@ -247,10 +224,9 @@ class ScheduledService(Service): return getattr(self.getManager(), 'end', None) +@implementer(IServiceCollection) class ServiceCollection(ScheduledService): - implements(IServiceCollection) - assignmentsFactory = set assignments = None @@ -273,10 +249,9 @@ class ServiceCollection(ScheduledService): # registration stuff +@implementer(IRegistrationTemplate) class RegistrationTemplate(object): - implements(IRegistrationTemplate) - def __init__(self, name=None, manager=None): self.name = self.__name__ = name self.manager = self.__parent__ = manager @@ -298,9 +273,9 @@ class RegistrationTemplate(object): return self.manager +@implementer(IClientRegistrations) class ClientRegistrations(object): - implements(IClientRegistrations) adapts(IClient) template = None diff --git a/cybertools/organize/servicemanager.txt b/cybertools/organize/servicemanager.txt index ca04fe5..b538c5b 100644 --- a/cybertools/organize/servicemanager.txt +++ b/cybertools/organize/servicemanager.txt @@ -2,8 +2,6 @@ Service Manager ================ - ($Id$) - This package does not provide functionality on its own but shows only how to integrate other packages into an application package. @@ -111,15 +109,16 @@ Using schema views for displaying and editing data We need some additional setup for working with schema views - so we have to supply some session handling stuff in order to work with client names. - >>> from zope.interface import implements - >>> from zope.app.session.interfaces import IClientIdManager, ISessionDataContainer - >>> from zope.app.session import session + >>> from zope.interface import implementer + >>> from zope.session.interfaces import IClientIdManager, ISessionDataContainer + >>> from zope.session import session >>> component.provideAdapter(session.ClientId) >>> component.provideAdapter(session.Session) >>> component.provideUtility(session.RAMSessionDataContainer(), ISessionDataContainer) >>> class ClientIdManager(object): ... implements(IClientIdManager) ... def getClientId(self, request): return 'dummy' + >>> ClientIdManager = implementer(IClientIdManager)(ClientIdManager) >>> component.provideUtility(ClientIdManager()) >>> from zope.publisher.browser import TestRequest @@ -329,7 +328,7 @@ registered for them. >>> for svc in workshop.getServices(): ... for cn, reg in sorted(svc.registrations.items()): - ... print 'client-%i: ' % (clientNames.index(cn)+1), reg.service.name + ... print('client-%i: ' % (clientNames.index(cn)+1), reg.service.name) client-1: event1 client-3: event2 @@ -492,7 +491,7 @@ allows a hierarchical presentation. >>> overview = wsView.overview() >>> for line in overview: - ... print line['title'], line['isHeadline'], line['level'] + ... print(line['title'], line['isHeadline'], line['level']) Event True 0 Event 1 False 1 Event 2 False 1 @@ -516,9 +515,9 @@ and registration data. >>> regInfo = srvView.getRegistrationInfo(reg) >>> clientInfo = srvView.getDataForClient(reg) - >>> print srvView.formatClientInfo(clientInfo) + >>> print(srvView.formatClientInfo(clientInfo)) Skywalker - >>> print regInfo['number'], regInfo['stateTitle'] + >>> print(regInfo['number'], regInfo['stateTitle']) 1 temporary The service view also provides fields that sum up the numbers of all @@ -636,7 +635,7 @@ possible. False >>> for reg in sorted(event1.registrations.values(), key=lambda x: x.number): - ... print reg.number, reg.numberWaiting + ... print(reg.number, reg.numberWaiting) 0 3 1 0 @@ -659,7 +658,7 @@ What happens if one of the participants cancels her registration? >>> regView.update() False >>> for reg in sorted(event1.registrations.values(), key=lambda x: x.number): - ... print reg.number, reg.numberWaiting + ... print(reg.number, reg.numberWaiting) 0 3 As the participants on the waiting list get priority over newly registering @@ -674,7 +673,7 @@ people on the waiting list. >>> regView.update() False >>> for reg in sorted(event1.registrations.values(), key=lambda x: x.numberWaiting): - ... print reg.number, reg.numberWaiting + ... print(reg.number, reg.numberWaiting) 0 2 0 3 @@ -686,7 +685,7 @@ free place. >>> regView.update() False >>> for reg in sorted(event1.registrations.values(), key=lambda x: x.number): - ... print reg.number, reg.numberWaiting + ... print(reg.number, reg.numberWaiting) 0 2 1 2 @@ -705,18 +704,18 @@ Excel Export >>> from cybertools.organize.browser.report import RegistrationsExportCsv >>> input = dict(get_data_method='getData') >>> csv = RegistrationsExportCsv(workshop, TestRequest(form=input)) - >>> print csv.render() + >>> print(csv.render()) "Service","Client ID","Organization","First Name","Last Name","E-Mail","Number","State" "Event 1","...","","Walker","","john@walker.tv",1,"submitted" >>> input = dict(get_data_method='getAllDataInColumns') >>> csv = RegistrationsExportCsv(workshop, TestRequest(form=input)) >>> result = csv.render().splitlines() - >>> print result[0] + >>> print(result[0]) "Client ID","Time Stamp","Last Name","First Name","Email Address","Age","Personal Address","Academic Titles","Street","City","Country","Event 1","WL Event 1","Event 2","WL Event 2" >>> len(result) 2 - >>> print [f.strip('"') for f in result[1].split(',')[1:]] + >>> print([f.strip('"') for f in result[1].split(',')[1:]]) ['...', 'Walker', 'John', 'john@walker.tv', '', 'Mr', '', '', '', '', '1', '2', '0', '0'] diff --git a/cybertools/organize/task.py b/cybertools/organize/task.py index c0e480a..3b5c636 100644 --- a/cybertools/organize/task.py +++ b/cybertools/organize/task.py @@ -1,34 +1,16 @@ -# -# Copyright (c) 2008 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.organize.task -""" -Task management classes. - -$Id$ +""" Task management classes. """ from zope.component import adapts -from zope.interface import implements +from zope.interface import implementer from cybertools.organize.interfaces import ITask +@implementer(ITask) class Task(object): - implements(ITask) + pass diff --git a/cybertools/organize/work.py b/cybertools/organize/work.py index 7725e88..7d452f5 100644 --- a/cybertools/organize/work.py +++ b/cybertools/organize/work.py @@ -1,28 +1,11 @@ -# -# Copyright (c) 2018 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.organize.work -""" -Planning and recording activities (work items). +""" Planning and recording activities (work items). """ from zope import component from zope.component import adapts -from zope.interface import implementer, implements +from zope.interface import implementer from zope.traversing.api import getName, getParent from cybertools.organize.interfaces import IWorkItem, IWorkItems @@ -171,12 +154,11 @@ workItemTypes = Jeep(( )) +@implementer(IWorkItem) class WorkItem(Stateful, Track): """ A work item that may be stored as a track in a tracking storage. """ - implements(IWorkItem) - metadata_attributes = Track.metadata_attributes + ('state',) index_attributes = metadata_attributes typeName = 'WorkItem' @@ -423,11 +405,11 @@ class WorkItem(Stateful, Track): getParent(self).indexTrack(None, self, idx) +@implementer(IWorkItems) class WorkItems(object): """ A tracking storage adapter managing work items. """ - implements(IWorkItems) adapts(ITrackingStorage) def __init__(self, context): diff --git a/cybertools/stateful/base.py b/cybertools/stateful/base.py index 0373ecd..62d3646 100644 --- a/cybertools/stateful/base.py +++ b/cybertools/stateful/base.py @@ -1,23 +1,6 @@ -# -# Copyright (c) 2020 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.stateful.base -""" -Basic implementations for stateful objects and adapters. +""" Basic implementations for stateful objects and adapters. """ from persistent.interfaces import IPersistent @@ -26,17 +9,16 @@ from zope import component from zope.component import adapts from zope.interface.interfaces import ObjectEvent from zope.event import notify -from zope.interface import implements +from zope.interface import implementer from cybertools.stateful.definition import statesDefinitions from cybertools.stateful.interfaces import IStateful, IStatefulIndexInfo from cybertools.stateful.interfaces import ITransitionEvent +@implementer(IStateful) class Stateful(object): - implements(IStateful) - statesDefinition = 'default' state = None @@ -54,7 +36,7 @@ class Stateful(object): def doTransition(self, transition, historyInfo=None): sd = self.getStatesDefinition() previousState = self.getState() - if isinstance(transition, basestring): + if isinstance(transition, str): sd.doTransitionFor(self, transition) self.notify(transition, previousState) return @@ -127,10 +109,9 @@ class StatefulAdapter(Stateful): notify(TransitionEvent(self.context, transObject, previousState, self.request)) +@implementer(IStatefulIndexInfo) class IndexInfo(object): - implements(IStatefulIndexInfo) - availableStatesDefinitions = [] # to be overwritten by subclass! def __init__(self, context): @@ -145,10 +126,9 @@ class IndexInfo(object): # event +@implementer(ITransitionEvent) class TransitionEvent(ObjectEvent): - implements(ITransitionEvent) - def __init__(self, obj, transition, previousState, request=None): super(TransitionEvent, self).__init__(obj) self.transition = transition diff --git a/cybertools/stateful/definition.py b/cybertools/stateful/definition.py index 7dea42c..6326d5d 100644 --- a/cybertools/stateful/definition.py +++ b/cybertools/stateful/definition.py @@ -1,36 +1,18 @@ -# -# 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 -# +# cybertools.stateful.definition -""" -State definition implementation. +""" State definition implementation. """ -from zope.interface import implements +from zope.interface import implementer from cybertools.util.jeep import Jeep from cybertools.stateful.interfaces import IState, IAction, ITransition from cybertools.stateful.interfaces import IStatesDefinition +@implementer(IState) class State(object): - implements(IState) - setSecurity = lambda self, context: None icon = None color = 'blue' @@ -48,10 +30,9 @@ class State(object): return 'cybertools.icons/' + (self.icon or 'led%s.png' % self.color) +@implementer(IAction) class Action(object): - implements(IAction) - allowed = True permission = None roles = [] @@ -67,19 +48,17 @@ class Action(object): setattr(self, k, v) +@implementer(ITransition) class Transition(Action): - implements(ITransition) - def __init__(self, name, title, targetState, **kw): super(Transition, self).__init__(name, title, **kw) self.targetState = targetState +@implementer(IStatesDefinition) class StatesDefinition(object): - implements(IStatesDefinition) - initialState = 'started' msgFactory = None diff --git a/cybertools/util/format.py b/cybertools/util/format.py index 43c58c9..1eddc52 100644 --- a/cybertools/util/format.py +++ b/cybertools/util/format.py @@ -60,9 +60,9 @@ def formatNumber(num, type='decimal', lang='de', def toStr(value, encoding='UTF-8'): - if isinstance(value, unicode): + if isinstance(value, str): return value.encode(encoding) - return str(value) + return bytes(value) def toUnicode(value, encoding='UTF-8', fallback='ISO8859-15'): # or: fallback='CP852' diff --git a/pyproject.toml b/pyproject.toml index d84f2c6..aba2c01 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,6 +32,8 @@ dependencies = [ "zope.index", "zope.interface", "zope.lifecycleevent", + "zope.sendmail", + "zope.session", "zope.testing", ]