32
32
# https://www.gnu.org/licenses/
33
33
# ****************************************************************************
34
34
import bz2
35
- import os
36
- from sage .cpython .string import bytes_to_str
35
+ from pathlib import Path
37
36
38
37
39
- def _dbz_to_string (name ):
38
+ def _dbz_to_string (name ) -> str :
40
39
r"""
41
40
TESTS::
42
41
@@ -54,17 +53,16 @@ def _dbz_to_string(name):
54
53
'0\n1\n'
55
54
"""
56
55
from sage .env import SAGE_SHARE
57
- dblocation = os .path .join (SAGE_SHARE , 'kohel' )
58
- filename = os .path .join (dblocation , name )
56
+ filename = Path (SAGE_SHARE ) / 'kohel' / name
59
57
try :
60
58
with open (filename , 'rb' ) as f :
61
59
data = bz2 .decompress (f .read ())
62
60
except OSError :
63
- raise ValueError ('file not found in the Kohel database' )
64
- return bytes_to_str ( data )
61
+ raise FileNotFoundError ('file not found in the Kohel database' )
62
+ return data . decode ( )
65
63
66
64
67
- def _dbz_to_integer_list (name ):
65
+ def _dbz_to_integer_list (name ) -> list [ list ] :
68
66
r"""
69
67
TESTS::
70
68
@@ -90,7 +88,7 @@ def _dbz_to_integer_list(name):
90
88
for row in data .split ("\n " )[:- 1 ]]
91
89
92
90
93
- def _dbz_to_integers (name ):
91
+ def _dbz_to_integers (name ) -> list :
94
92
r"""
95
93
TESTS::
96
94
@@ -103,19 +101,20 @@ def _dbz_to_integers(name):
103
101
104
102
105
103
class ModularPolynomialDatabase :
106
- def _dbpath (self , level ):
104
+ def _dbpath (self , level ) -> Path :
107
105
r"""
108
106
TESTS::
109
107
110
108
sage: C = ClassicalModularPolynomialDatabase()
111
109
sage: C._dbpath(3)
112
- 'PolMod/Cls/pol.003.dbz'
110
+ PosixPath( 'PolMod/Cls/pol.003.dbz')
113
111
sage: C._dbpath(8)
114
- 'PolMod/Cls/pol.008.dbz'
112
+ PosixPath( 'PolMod/Cls/pol.008.dbz')
115
113
"""
116
- return "PolMod/%s/pol.%03d.dbz" % (self .model , level )
114
+ path = Path ("PolMod" )
115
+ return path / self .model / ("pol.%03d.dbz" % level )
117
116
118
- def __repr__ (self ):
117
+ def __repr__ (self ) -> str :
119
118
r"""
120
119
EXAMPLES::
121
120
@@ -161,7 +160,7 @@ def __getitem__(self, level):
161
160
sage: DBMP[50]
162
161
Traceback (most recent call last):
163
162
...
164
- ValueError : file not found in the Kohel database
163
+ FileNotFoundError : file not found in the Kohel database
165
164
"""
166
165
from sage .rings .integer import Integer
167
166
from sage .rings .integer_ring import IntegerRing
@@ -198,16 +197,16 @@ def __getitem__(self, level):
198
197
199
198
200
199
class ModularCorrespondenceDatabase (ModularPolynomialDatabase ):
201
- def _dbpath (self , level ):
200
+ def _dbpath (self , level ) -> Path :
202
201
r"""
203
202
TESTS::
204
203
205
204
sage: DB = DedekindEtaModularCorrespondenceDatabase()
206
205
sage: DB._dbpath((2,4))
207
- 'PolMod/EtaCrr/crr.02.004.dbz'
206
+ PosixPath( 'PolMod/EtaCrr/crr.02.004.dbz')
208
207
"""
209
- ( Nlevel , crrlevel ) = level
210
- return "PolMod/%s/ crr.%02d.%03d.dbz" % ( self . model , Nlevel , crrlevel )
208
+ path = Path ( "PolMod" )
209
+ return path / self . model / ( " crr.%02d.%03d.dbz" % level )
211
210
212
211
213
212
class ClassicalModularPolynomialDatabase (ModularPolynomialDatabase ):
0 commit comments