From fad566b3545ead13ed31b804fa2febd635c9990e Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Wed, 29 Nov 2023 11:48:36 +0100 Subject: [PATCH] make package cybertools.tracking Python3-ready --- LICENSE | 21 ++++++++++++++++ cybertools/text/base.py | 23 ++---------------- cybertools/tracking/btree.py | 35 ++++++--------------------- cybertools/tracking/comment/tests.py | 8 +++--- cybertools/tracking/notify/README.txt | 6 ++--- cybertools/tracking/notify/base.py | 30 ++++------------------- cybertools/tracking/notify/tests.py | 9 ++++--- cybertools/tracking/tests.py | 10 +++++--- 8 files changed, 55 insertions(+), 87 deletions(-) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1ae14e4 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (C) 2023 cyberconcepts.org team + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/cybertools/text/base.py b/cybertools/text/base.py index 8bc4c4c..65ea3cb 100644 --- a/cybertools/text/base.py +++ b/cybertools/text/base.py @@ -1,27 +1,8 @@ -# -# 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.text.base -""" -Base classes for text transformations. +"""Base classes for text transformations. Based on code provided by zc.index and TextIndexNG3. - -$Id$ """ diff --git a/cybertools/tracking/btree.py b/cybertools/tracking/btree.py index 3325325..e8c5b3b 100644 --- a/cybertools/tracking/btree.py +++ b/cybertools/tracking/btree.py @@ -1,23 +1,6 @@ -# -# Copyright (c) 2016 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.tracking.btree -""" -ZODB-/BTree-based implementation of user interaction tracking. +"""ZODB-/BTree-based implementation of user interaction tracking. """ import time @@ -25,7 +8,7 @@ from persistent import Persistent from BTrees import OOBTree, IOBTree from BTrees.IFBTree import intersection, union from zope.component import adapter -from zope.interface import implements +from zope.interface import implementer from zope.app.container.btree import BTreeContainer from zope.app.container.interfaces import IObjectRemovedEvent from zope.index.field import FieldIndex @@ -36,10 +19,9 @@ from cybertools.tracking.interfaces import IRun, ITrackingStorage, ITrack from cybertools.util.date import getTimeStamp, timeStamp2ISO +@implementer(IRun) class Run(object): - implements(IRun) - id = start = end = 0 finished = False @@ -53,11 +35,9 @@ class Run(object): str(self.finished))) +@implementer(ITrack) class Track(Persistent): - #implements(ITrack, IPhysicallyLocatable) - implements(ITrack) - metadata_attributes = ('taskId', 'runId', 'userName', 'timeStamp') index_attributes = metadata_attributes typeName = 'Track' @@ -112,10 +92,9 @@ class Track(Persistent): return self.__name__ +@implementer(ITrackingStorage) class TrackingStorage(BTreeContainer): - implements(ITrackingStorage) - trackFactory = Track indexAttributes = trackFactory.index_attributes @@ -293,7 +272,7 @@ class TrackingStorage(BTreeContainer): resultx = None for v in value: v2 = v - if isinstance(v, basestring) and v.endswith('*'): + if isinstance(v, str) and v.endswith('*'): v = v[:-1] v2 = v + 'z' resultx = self.union(resultx, self.indexes[idx].apply((v, v2))) diff --git a/cybertools/tracking/comment/tests.py b/cybertools/tracking/comment/tests.py index 4fdbe82..a4a0584 100755 --- a/cybertools/tracking/comment/tests.py +++ b/cybertools/tracking/comment/tests.py @@ -1,6 +1,8 @@ import unittest, doctest +import warnings +#warnings.filterwarnings('ignore', category=DeprecationWarning) class Test(unittest.TestCase): "Basic tests for the cybertools.tracking.comment package." @@ -12,9 +14,9 @@ class Test(unittest.TestCase): def test_suite(): flags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS return unittest.TestSuite(( - unittest.makeSuite(Test), - doctest.DocFileSuite('README.txt', optionflags=flags), - )) + unittest.TestLoader().loadTestsFromTestCase(Test), + doctest.DocFileSuite('README.txt', optionflags=flags), + )) if __name__ == '__main__': unittest.main(defaultTest='test_suite') diff --git a/cybertools/tracking/notify/README.txt b/cybertools/tracking/notify/README.txt index 5befa67..438843a 100644 --- a/cybertools/tracking/notify/README.txt +++ b/cybertools/tracking/notify/README.txt @@ -23,9 +23,9 @@ Storing and Retrieving Notifications >>> ntf01 = list(manager.query(userName='user01'))[0] >>> ntf01 + {'type': 'object_changed', 'state': 'new', 'media': ['inbox']}> - >>> print ntf01.state + >>> print(ntf01.state) new - >>> print ntf01.timingType + >>> print(ntf01.timingType) None diff --git a/cybertools/tracking/notify/base.py b/cybertools/tracking/notify/base.py index 2f7d57b..20bfa56 100644 --- a/cybertools/tracking/notify/base.py +++ b/cybertools/tracking/notify/base.py @@ -1,38 +1,19 @@ -# -# 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.tracking.notify.base -""" -Base classes for a notification framework. - -$Id$ +"""Base classes for a notification framework. """ from zope.component import adapts -from zope.interface import implements +from zope.interface import implementer from cybertools.tracking.btree import Track from cybertools.tracking.interfaces import ITrackingStorage from cybertools.tracking.notify.interfaces import INotification, INotificationManager +@implementer(INotificationManager) class NotificationManager(object): - implements(INotificationManager) adapts(ITrackingStorage) def __init__(self, context): @@ -53,10 +34,9 @@ class NotificationManager(object): return self.context.query(**kw) +@implementer(INotification) class Notification(Track): - implements(INotification) - typeName = 'Notification' def __getattr__(self, attr): diff --git a/cybertools/tracking/notify/tests.py b/cybertools/tracking/notify/tests.py index 0d2bd6d..c640abc 100755 --- a/cybertools/tracking/notify/tests.py +++ b/cybertools/tracking/notify/tests.py @@ -1,5 +1,8 @@ import unittest, doctest +import warnings + +warnings.filterwarnings('ignore', category=DeprecationWarning) class Test(unittest.TestCase): @@ -12,9 +15,9 @@ class Test(unittest.TestCase): def test_suite(): flags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS return unittest.TestSuite(( - unittest.makeSuite(Test), - doctest.DocFileSuite('README.txt', optionflags=flags), - )) + unittest.TestLoader().loadTestsFromTestCase(Test), + doctest.DocFileSuite('README.txt', optionflags=flags), + )) if __name__ == '__main__': unittest.main(defaultTest='test_suite') diff --git a/cybertools/tracking/tests.py b/cybertools/tracking/tests.py index 096813e..1e997a7 100755 --- a/cybertools/tracking/tests.py +++ b/cybertools/tracking/tests.py @@ -1,10 +1,12 @@ import unittest, doctest import os - +import warnings testDir = os.path.join(os.path.dirname(__file__), 'testdata') +#warnings.filterwarnings('ignore', category=DeprecationWarning) + class Test(unittest.TestCase): "Basic tests for the loops.track package." @@ -16,9 +18,9 @@ class Test(unittest.TestCase): def test_suite(): flags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS return unittest.TestSuite(( - unittest.makeSuite(Test), - doctest.DocFileSuite('README.txt', optionflags=flags), - )) + unittest.TestLoader().loadTestsFromTestCase(Test), + doctest.DocFileSuite('README.txt', optionflags=flags), + )) if __name__ == '__main__': unittest.main(defaultTest='test_suite')