Skip to content

Commit

Permalink
Update Python version support.
Browse files Browse the repository at this point in the history
  • Loading branch information
icemac committed Jun 18, 2024
1 parent 700ad23 commit aebd856
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions src/Products/ZCTextIndex/WidCode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
36 changes: 17 additions & 19 deletions src/Products/ZCatalog/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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():
Expand Down Expand Up @@ -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))
Expand All @@ -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):
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit aebd856

Please sign in to comment.