From aebd85689545c74764cd3ef7cda9cce8228e9d8e Mon Sep 17 00:00:00 2001 From: Michael Howitz Date: Tue, 18 Jun 2024 09:16:36 +0200 Subject: [PATCH] Update Python version support. --- setup.py | 3 +-- src/Products/ZCTextIndex/WidCode.py | 4 ++-- src/Products/ZCatalog/plan.py | 36 ++++++++++++++--------------- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/setup.py b/setup.py index 9967f502..1eaa4dc9 100644 --- a/setup.py +++ b/setup.py @@ -44,7 +44,6 @@ "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", @@ -54,7 +53,7 @@ "Topic :: Internet :: WWW/HTTP :: Indexing/Search", ], keywords='Zope catalog index search data', - python_requires='>=3.7', + python_requires='>=3.8', install_requires=[ 'setuptools', 'AccessControl >= 4.0a4', diff --git a/src/Products/ZCTextIndex/WidCode.py b/src/Products/ZCTextIndex/WidCode.py index 9efa8817..bf77cc71 100644 --- a/src/Products/ZCTextIndex/WidCode.py +++ b/src/Products/ZCTextIndex/WidCode.py @@ -75,7 +75,7 @@ def _encode(w): b, c = divmod(w, 0x80) a, b = divmod(b, 0x80) s = chr(b) + chr(c) - if a < 0x80: # no more than 21 data bits + if a < 0x80: # no more than 21 data bits return chr(a + 0x80) + s a, b = divmod(a, 0x80) assert a < 0x80, (w, a, b, s) # else more than 28 data bits @@ -86,7 +86,7 @@ def _encode(w): def decode(code): - # Handle bytes that were not properly decoded during Python 3 conversion + # Handle bytes that were not properly decoded during Python-3-conversion if isinstance(code, bytes): code = code.decode('latin1') # Decode a string into a list of wids. diff --git a/src/Products/ZCatalog/plan.py b/src/Products/ZCatalog/plan.py index 83b56996..8c4e0b62 100644 --- a/src/Products/ZCatalog/plan.py +++ b/src/Products/ZCatalog/plan.py @@ -104,7 +104,7 @@ def load_default(cls): try: pmap = resolve(location) cls.load_pmap(location, pmap) - except ImportError: + except ModuleNotFoundError: logger.warning(f'could not load priority map from {location}') @classmethod @@ -121,8 +121,7 @@ def load_from_path(cls, path): @classmethod def load_pmap(cls, location, pmap): - logger.info('loaded priority %d map(s) from %s', - len(pmap), location) + logger.info('loaded priority %d map(s) from %s', len(pmap), location) # Convert the simple benchmark tuples to namedtuples new_plan = {} for cid, plan in pmap.items(): @@ -251,8 +250,7 @@ def make_key(self, query): key = [name for name in key if name not in notkeys] key.extend([(name, "not") for name in notkeys]) # Workaround: Python only sorts on identical types. - tuple_keys = set(key) - { - x for x in key if not isinstance(x, tuple)} + tuple_keys = set(key) - {x for x in key if not isinstance(x, tuple)} str_keys = set(key) - tuple_keys return tuple(sorted(str_keys)) + tuple(sorted(tuple_keys)) @@ -264,9 +262,9 @@ def plan(self): # sort indexes on (limited result index, mean search time) # skip internal ('#') bookkeeping records - ranking = sorted( - [((value.limit, value.duration), name) - for name, value in benchmark.items() if '#' not in name]) + ranking = sorted([((value.limit, value.duration), name) + for name, value in benchmark.items() + if '#' not in name]) return [r[1] for r in ranking] def start(self): @@ -281,8 +279,7 @@ def stop_split(self, name, result=None, limit=False): start_time, stop_time = self.interim.get(name, Duration(None, None)) self.interim[name] = Duration(start_time, current) dt = current - start_time - self.res.append(IndexMeasurement( - name=name, duration=dt, limit=limit)) + self.res.append(IndexMeasurement(name=name, duration=dt, limit=limit)) if name.startswith('sort_on'): # sort_on isn't an index. We only do time reporting on it @@ -291,8 +288,7 @@ def stop_split(self, name, result=None, limit=False): # remember index's hits, search time and calls benchmark = self.benchmark if name not in benchmark: - benchmark[name] = Benchmark(duration=dt, - hits=1, limit=limit) + benchmark[name] = Benchmark(duration=dt, hits=1, limit=limit) else: duration, hits, limit = benchmark[name] duration = ((duration * hits) + dt) / float(hits + 1) @@ -316,8 +312,7 @@ def stop(self): if key in self.catalog.indexes: index = self.catalog.indexes[key] self.benchmark[key] = Benchmark( - 0, 0, ILimitedResultIndex.providedBy(index) - ) + 0, 0, ILimitedResultIndex.providedBy(index)) else: self.benchmark[key] = Benchmark(0, 0, False) PriorityMap.set_entry(self.cid, self.key, self.benchmark) @@ -354,11 +349,14 @@ def report(self): 'query': key, 'counter': report.hits, 'duration': report.duration * 1000, - 'last': {'duration': last.duration * 1000, - 'details': [dict(id=d.name, - duration=d.duration * 1000) - for d in last.details], - }, + 'last': { + 'duration': + last.duration * 1000, + 'details': [ + dict(id=d.name, duration=d.duration * 1000) + for d in last.details + ], + }, } rval.append(info)