Skip to content

Commit

Permalink
Allow lzma compressed data file
Browse files Browse the repository at this point in the history
  • Loading branch information
tornaria committed Nov 28, 2023
1 parent 507b0a5 commit 894da33
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/conway_polynomials/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ def _parse_line(l: str) -> tuple[int, int, tuple[int,...]]:

return (p, n, coeffs)

def _open_database():
r"""
Open the database, possibly lzma compressed.
"""
from importlib.resources import files
dbpath = files('conway_polynomials').joinpath('CPimport.txt')
try:
import lzma
return lzma.open(dbpath.with_suffix(".txt.lzma"), "rt")
except FileNotFoundError:
return dbpath.open("r")

from typing import Optional
_conway_dict: Optional[ dict[int,dict[int,tuple[int,...]]] ]
Expand Down Expand Up @@ -117,9 +128,7 @@ def database() -> dict[int,dict[int,tuple[int,...]]]:
return _conway_dict

_conway_dict = {}
from importlib.resources import files
dbpath = files('conway_polynomials').joinpath('CPimport.txt')
with dbpath.open("r") as f:
with _open_database() as f:
# The first line of the file is "allConwayPolynomials := ["
f.readline()

Expand Down

0 comments on commit 894da33

Please sign in to comment.