Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions pytools/persistent_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ def __init__(self, identifier, key_builder=None, container_dir=None):

container_dir = join(
cache_dir,
"pdict-v4-{}-py{}".format(
"pdict-v5-{}-py{}".format(
identifier,
".".join(str(i) for i in sys.version_info)))

Expand All @@ -589,14 +589,20 @@ def fetch(self, key, _stacklevel=0):

@staticmethod
def _read(path):
import lzma
from pickle import load
with open(path, "rb") as inf:
return load(inf)
try:
with lzma.open(path, "rb") as inf:
return load(inf)
except lzma.LZMAError:
with open(path, "rb") as inf:
return load(inf)

@staticmethod
def _write(path, value):
import lzma
from pickle import HIGHEST_PROTOCOL, dump
with open(path, "wb") as outf:
with lzma.open(path, "wb") as outf:
dump(value, outf, protocol=HIGHEST_PROTOCOL)

def _item_dir(self, hexdigest_key):
Expand All @@ -607,9 +613,8 @@ def _item_dir(self, hexdigest_key):
# This doesn't solve that problem, but it makes it much less likely

return join(self.container_dir,
hexdigest_key[:3],
hexdigest_key[3:6],
hexdigest_key[6:])
hexdigest_key[:1],
hexdigest_key[1:])

def _key_file(self, hexdigest_key):
from os.path import join
Expand Down