1717
1818try :
1919 from compression import zstd # type: ignore[import-not-found]
20+
2021 HAVE_ZSTD = True
2122except ImportError : # PY313
2223 HAVE_ZSTD = False
2526from .optpkg import optional_package
2627
2728if ty .TYPE_CHECKING :
28-
2929 import indexed_gzip # type: ignore[import]
3030
3131 if not HAVE_ZSTD : # PY313
3232 from backports import zstd # type: ignore[import]
33+
3334 HAVE_ZSTD = True
3435
3536 HAVE_INDEXED_GZIP = True
7071 COMPRESSION_ERRORS += (zstd .ZstdError ,)
7172
7273
73-
7474class DeterministicGzipFile (gzip .GzipFile ):
7575 """Deterministic variant of GzipFile
7676
@@ -107,6 +107,7 @@ def __init__(
107107 mtime = mtime ,
108108 )
109109
110+
110111def gzip_open (
111112 filename : str ,
112113 mode : Mode = 'rb' ,
@@ -154,10 +155,10 @@ def zstd_open(
154155 filename : str ,
155156 mode : Mode = 'r' ,
156157 * ,
157- level : int | None = None ,
158- options : dict | None = None ,
158+ level : int | None = None ,
159+ options : dict | None = None ,
159160 zstd_dict : zstd .ZstdDict | None = None ,
160- level_or_option : int | dict | None = None
161+ level_or_option : int | dict | None = None ,
161162) -> zstd .ZstdFile :
162163 """Open a zstd file for reading or writing.
163164
@@ -180,25 +181,21 @@ def zstd_open(
180181 """
181182 if level_or_option is not None :
182183 alert_future_error (
183- 'The level_or_option parameter will be removed in a future '
184- 'version of nibabel' ,
184+ 'The level_or_option parameter will be removed in a future version of nibabel' ,
185185 '7.0' ,
186186 warning_rec = 'This warning can be silenced by using the separate '
187187 'level/option parameters' ,
188- error_rec = 'Future errors can be avoided by using the separate '
189- 'level/option parameters' ,
190- error_class = TypeError )
191- level_or_option_provided = sum (( level_or_option is not None ,
192- level is not None ,
193- options is not None ) )
188+ error_rec = 'Future errors can be avoided by using the separate level/option parameters' ,
189+ error_class = TypeError ,
190+ )
191+ level_or_option_provided = sum (
192+ ( level_or_option is not None , level is not None , options is not None )
193+ )
194194 if level_or_option_provided > 1 :
195- raise ValueError (
196- 'Only one of level_or_option, level or options may be '
197- 'specified' )
195+ raise ValueError ('Only one of level_or_option, level or options may be specified' )
198196 if level_or_option is not None :
199197 if isinstance (level_or_option , int ):
200198 level = level_or_option
201199 else :
202200 options = level_or_option
203- return zstd .ZstdFile (
204- filename , mode , level = level , options = options , zstd_dict = zstd_dict )
201+ return zstd .ZstdFile (filename , mode , level = level , options = options , zstd_dict = zstd_dict )
0 commit comments