From 61c78fe3e7147f3ab6527f5768ca46e2bdad28ff Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Mon, 23 Sep 2024 13:12:33 +0200 Subject: [PATCH] reporter: Python3 fixes --- cybertools/reporter/README.txt | 25 ++++++++++---------- cybertools/reporter/batch.py | 27 +++------------------ cybertools/reporter/browser/batch.py | 29 ++++------------------- cybertools/reporter/data.py | 28 ++++------------------ cybertools/reporter/resultset.py | 35 ++++++---------------------- cybertools/reporter/tests.py | 3 +-- 6 files changed, 32 insertions(+), 115 deletions(-) diff --git a/cybertools/reporter/README.txt b/cybertools/reporter/README.txt index 68772f5..3c212bc 100644 --- a/cybertools/reporter/README.txt +++ b/cybertools/reporter/README.txt @@ -23,9 +23,9 @@ then provide a listing of persons... >>> 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', '1981-10-11')) + >>> pdata = (('John', 'Smith', '1956-08-01'), + ... ('David', 'Waters', '1972-12-24'), + ... ('Carla', 'Myers', '1981-10-11')) >>> persons = DataSource([Person(f, s, date(*[int(d) for d in b.split('-')])) ... for f, s, b in pdata]) @@ -41,18 +41,18 @@ then provide a listing of persons... >>> component.provideAdapter(DateFieldInstance, name='date') >>> rset = IResultSet(persons) - >>> rset.schema = Schema(Field(u'firstName'), Field(u'lastName'), - ... Field(u'birthDate', fieldType='date')) + >>> rset.schema = Schema(Field('firstName'), Field('lastName'), + ... Field('birthDate', fieldType='date')) >>> rows = list(rset.getRows()) >>> len(rows) 3 >>> for r in rows: - ... print r.applyTemplate() - {u'lastName': u'John', u'birthDate': '1956-08-01', u'firstName': u'Smith'} - {u'lastName': u'David', u'birthDate': '1972-12-24', u'firstName': u'Waters'} - {u'lastName': u'Carla', u'birthDate': '1981-10-11', u'firstName': u'Myers'} + ... print(r.applyTemplate()) + {'firstName': 'Smith', 'lastName': 'John', 'birthDate': '1956-08-01'} + {'firstName': 'Waters', 'lastName': 'David', 'birthDate': '1972-12-24'} + {'firstName': 'Myers', 'lastName': 'Carla', 'birthDate': '1981-10-11'} For the browser presentation we can also use a browser view providing the result set with extended attributes: @@ -72,7 +72,7 @@ Batching We'll use a fairly simple Iterable: - >>> it = xrange(14) + >>> it = range(14) >>> from cybertools.reporter.batch import Batch >>> b = Batch(it, size=5, overlap=1, orphan=2) @@ -99,8 +99,7 @@ We are now ready to use the corresponding browser view: >>> bview.items() [3, 4, 5, 6] >>> bview.last - {'url': 'http://127.0.0.1?b_size=4&b_overlap=1&b_page=5&b_orphan=0', - 'navOnClick': "dojo.io.updateNode(...); return false;", - 'title': 5} + {'title': 5, 'url': 'http://127.0.0.1?b_page=5&b_size=4&b_overlap=1&b_orphan=0', + 'navOnClick': "dojo.io.updateNode(...); return false;"} diff --git a/cybertools/reporter/batch.py b/cybertools/reporter/batch.py index cdecbcb..084475b 100644 --- a/cybertools/reporter/batch.py +++ b/cybertools/reporter/batch.py @@ -1,30 +1,9 @@ -# -# 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.reporter.batch -""" -Batching implementation. - -$Id$ +""" Batching implementation. """ import itertools -from zope.interface import implements -from interfaces import IBatch class Batch(object): @@ -36,7 +15,7 @@ class Batch(object): iterable = list(iterable) self.iterable = iterable length = len(self.iterable) - self.pages = range(0, length, size-overlap) + self.pages = list(range(0, length, size-overlap)) if pageIndex >= len(self.pages): pageIndex = len(self.pages) - 1 if pageIndex < 0: diff --git a/cybertools/reporter/browser/batch.py b/cybertools/reporter/browser/batch.py index fe6a447..b0c7b48 100644 --- a/cybertools/reporter/browser/batch.py +++ b/cybertools/reporter/browser/batch.py @@ -1,29 +1,10 @@ -# -# 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.reporter.browser.batch -""" -A browser view class for batching to be used by a macro or some other +""" A browser view class for batching to be used by a macro or some other HTML providing template. - -$Id$ """ -import urllib +import urllib.parse from zope.cachedescriptors.property import Lazy from cybertools.reporter.batch import Batch @@ -81,7 +62,7 @@ class BatchView(object): v = form.get(p) if v: params[p] = v - return '?' + urllib.urlencode(params) + return '?' + urllib.parse.urlencode(params) def url(self, page): return str(self.request.URL) + self.urlParams(page) @@ -90,7 +71,7 @@ class BatchView(object): try: url = self.request.URL[-1] except KeyError: # make DocTest/TestRequest happy - url = `self.request.URL` + url = 'self.request.URL' return ''.join((url, '/@@ajax.inner.html', self.urlParams(page))) def navOnClick(self, page): diff --git a/cybertools/reporter/data.py b/cybertools/reporter/data.py index 8add6d5..3b7a8fd 100644 --- a/cybertools/reporter/data.py +++ b/cybertools/reporter/data.py @@ -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.reporter.data -""" -Basic data / data source implementations. - -$Id$ +""" Basic data / data source implementations. """ -from zope.interface import implements +from zope.interface import implementer from cybertools.reporter.interfaces import IDataSource +@implementer(IDataSource) class DataSource(object): - implements(IDataSource) - def __init__(self, iterable): self.data = iterable diff --git a/cybertools/reporter/resultset.py b/cybertools/reporter/resultset.py index b6fcd8e..75e17d1 100644 --- a/cybertools/reporter/resultset.py +++ b/cybertools/reporter/resultset.py @@ -1,35 +1,16 @@ -# -# 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.reporter.resultset -""" -Result set and related classes for reporting. +""" Result set and related classes for reporting. Now obsolete (but still used in some projects), use cybertools.composer.report.result instead. - -$Id$ """ # TODO: move the generic stuff to cybertools.reporter.result from zope.cachedescriptors.property import Lazy from zope.component import adapts -from zope.interface import Interface, implements +from zope.interface import Interface, implementer from cybertools.composer.schema import Schema from cybertools.composer.schema.instance import Instance @@ -37,11 +18,10 @@ from cybertools.reporter.interfaces import IDataSource from cybertools.reporter.interfaces import IResultSet, IRow, ICell +@implementer(ICell) class Cell(object): # TODO: replace Cell by FieldInstance - implements(ICell) - def __init__(self, field, value, row): self.field = field self.value = value @@ -66,10 +46,9 @@ class Cell(object): url = urlTitle = u'' +@implementer(IRow) class Row(Instance): - implements(IRow) - def __init__(self, context, resultSet): self.context = context self.resultSet = resultSet @@ -89,11 +68,11 @@ class Row(Instance): yield rf(f, getattr(self.context, f.name), self) +@implementer(IRow) class ContentRow(Instance): """ A row adapter for standard content objects. """ - implements(IRow) adapts(Interface) @Lazy @@ -101,9 +80,9 @@ class ContentRow(Instance): return self.template.fields +@implementer(IResultSet) class ResultSet(object): - implements(IResultSet) adapts(IDataSource) view = None diff --git a/cybertools/reporter/tests.py b/cybertools/reporter/tests.py index 4437f9a..7a6e195 100755 --- a/cybertools/reporter/tests.py +++ b/cybertools/reporter/tests.py @@ -1,9 +1,8 @@ -# $Id$ +# cybertools.reporter.tests import unittest, doctest from zope.app.testing import ztapi from zope.interface.verify import verifyClass -from zope.interface import implements from cybertools.reporter.interfaces import IResultSet, IRow, ICell