diff --git a/swig/python/gdal-utils/osgeo_utils/auxiliary/util.py b/swig/python/gdal-utils/osgeo_utils/auxiliary/util.py index 7a5189a07e06..d9f3d802c9e6 100644 --- a/swig/python/gdal-utils/osgeo_utils/auxiliary/util.py +++ b/swig/python/gdal-utils/osgeo_utils/auxiliary/util.py @@ -34,7 +34,7 @@ from typing import Any, Dict, Iterator, List, Optional, Sequence, Tuple, Union from osgeo import __version__ as gdal_version_str -from osgeo import gdal +from osgeo import gdal, ogr, osr from osgeo_utils.auxiliary.base import ( MaybeSequence, OptionalBoolStr, @@ -54,6 +54,16 @@ ] +def enable_gdal_exceptions(fun): + def enable_exceptions_wrapper(*args, **kwargs): + with gdal.ExceptionMgr(useExceptions=True), osr.ExceptionMgr( + useExceptions=True + ), ogr.ExceptionMgr(useExceptions=True): + return fun(*args, **kwargs) + + return enable_exceptions_wrapper + + def DoesDriverHandleExtension(drv: gdal.Driver, ext: str) -> bool: exts = drv.GetMetadataItem(gdal.DMD_EXTENSIONS) return exts is not None and ext.lower() in exts.lower().split(" ") diff --git a/swig/python/gdal-utils/osgeo_utils/gdal2tiles.py b/swig/python/gdal-utils/osgeo_utils/gdal2tiles.py index 6d3d01a33a56..69639d3823ec 100644 --- a/swig/python/gdal-utils/osgeo_utils/gdal2tiles.py +++ b/swig/python/gdal-utils/osgeo_utils/gdal2tiles.py @@ -56,6 +56,7 @@ from xml.etree import ElementTree from osgeo import gdal, osr +from osgeo_utils.auxiliary.util import enable_gdal_exceptions Options = Any @@ -4585,20 +4586,9 @@ def single_threaded_tiling( shutil.rmtree(os.path.dirname(conf.src_file)) +@enable_gdal_exceptions def multi_threaded_tiling( input_file: str, output_folder: str, options: Options, pool -) -> None: - with gdal.ExceptionMgr(), osr.ExceptionMgr(): - return _multi_threaded_tiling( - input_file=input_file, - output_folder=output_folder, - options=options, - pool=pool, - ) - - -def _multi_threaded_tiling( - input_file: str, output_folder: str, options: Options, pool ) -> None: nb_processes = options.nb_processes or 1 @@ -4696,14 +4686,8 @@ def main(argv: List[str] = sys.argv, called_from_main=False) -> int: return submain(argv, called_from_main=called_from_main) +@enable_gdal_exceptions def submain(argv: List[str], pool=None, pool_size=0, called_from_main=False) -> int: - with gdal.ExceptionMgr(), osr.ExceptionMgr(): - return _submain( - argv=argv, pool=pool, pool_size=pool_size, called_from_main=called_from_main - ) - - -def _submain(argv: List[str], pool=None, pool_size=0, called_from_main=False) -> int: argv = gdal.GeneralCmdLineProcessor(argv) if argv is None: diff --git a/swig/python/gdal-utils/osgeo_utils/gdal2xyz.py b/swig/python/gdal-utils/osgeo_utils/gdal2xyz.py index 2ce2fe6b01c8..e21268124996 100644 --- a/swig/python/gdal-utils/osgeo_utils/gdal2xyz.py +++ b/swig/python/gdal-utils/osgeo_utils/gdal2xyz.py @@ -44,9 +44,15 @@ OptionalProgressCallback, get_progress_callback, ) -from osgeo_utils.auxiliary.util import PathOrDS, get_bands, open_ds +from osgeo_utils.auxiliary.util import ( + PathOrDS, + enable_gdal_exceptions, + get_bands, + open_ds, +) +@enable_gdal_exceptions def gdal2xyz( srcfile: PathOrDS, dstfile: PathLikeOrStr = None, @@ -60,37 +66,6 @@ def gdal2xyz( return_np_arrays: bool = False, pre_allocate_np_arrays: bool = True, progress_callback: OptionalProgressCallback = ..., -) -> Optional[Tuple]: - with gdal.ExceptionMgr(): - return _gdal2xyz( - srcfile=srcfile, - dstfile=dstfile, - srcwin=srcwin, - skip=skip, - band_nums=band_nums, - delim=delim, - skip_nodata=skip_nodata, - src_nodata=src_nodata, - dst_nodata=dst_nodata, - return_np_arrays=return_np_arrays, - pre_allocate_np_arrays=pre_allocate_np_arrays, - progress_callback=progress_callback, - ) - - -def _gdal2xyz( - srcfile: PathOrDS, - dstfile: PathLikeOrStr = None, - srcwin: Optional[Sequence[int]] = None, - skip: Union[int, Sequence[int]] = 1, - band_nums: Optional[Sequence[int]] = None, - delim: str = " ", - skip_nodata: bool = False, - src_nodata: Optional[Union[Sequence, Number]] = None, - dst_nodata: Optional[Union[Sequence, Number]] = None, - return_np_arrays: bool = False, - pre_allocate_np_arrays: bool = True, - progress_callback: OptionalProgressCallback = ..., ) -> Optional[Tuple]: """ translates a raster file (or dataset) into xyz format diff --git a/swig/python/gdal-utils/osgeo_utils/gdal_calc.py b/swig/python/gdal-utils/osgeo_utils/gdal_calc.py index 11a0e9f6f11f..69f134871a3b 100644 --- a/swig/python/gdal-utils/osgeo_utils/gdal_calc.py +++ b/swig/python/gdal-utils/osgeo_utils/gdal_calc.py @@ -50,7 +50,11 @@ from osgeo_utils.auxiliary.extent_util import GT, Extent from osgeo_utils.auxiliary.gdal_argparse import GDALArgumentParser, GDALScript from osgeo_utils.auxiliary.rectangle import GeoRectangle -from osgeo_utils.auxiliary.util import GetOutputDriverFor, open_ds +from osgeo_utils.auxiliary.util import ( + GetOutputDriverFor, + enable_gdal_exceptions, + open_ds, +) GDALDataType = int @@ -104,6 +108,7 @@ """ +@enable_gdal_exceptions def Calc( calc: MaybeSequence[str], outfile: Optional[PathLikeOrStr] = None, @@ -124,49 +129,6 @@ def Calc( progress_callback: Optional = gdal.TermProgress_nocb, **input_files, ): - with gdal.ExceptionMgr(): - return _Calc( - calc=calc, - outfile=outfile, - NoDataValue=NoDataValue, - type=type, - format=format, - creation_options=creation_options, - allBands=allBands, - overwrite=overwrite, - hideNoData=hideNoData, - projectionCheck=projectionCheck, - color_table=color_table, - extent=extent, - projwin=projwin, - user_namespace=user_namespace, - debug=debug, - quiet=quiet, - progress_callback=progress_callback, - **input_files, - ) - - -def _Calc( - calc: MaybeSequence[str], - outfile: Optional[PathLikeOrStr] = None, - NoDataValue: Optional[Number] = None, - type: Optional[Union[GDALDataType, str]] = None, - format: Optional[str] = None, - creation_options: Optional[Sequence[str]] = None, - allBands: str = "", - overwrite: bool = False, - hideNoData: bool = False, - projectionCheck: bool = False, - color_table: Optional[ColorTableLike] = None, - extent: Optional[Extent] = None, - projwin: Optional[Union[Tuple, GeoRectangle]] = None, - user_namespace: Optional[Dict] = None, - debug: bool = False, - quiet: bool = False, - progress_callback: Optional = gdal.TermProgress_nocb, - **input_files, -): if debug: print(f"gdal_calc.py starting calculation {calc}") diff --git a/swig/python/gdal-utils/osgeo_utils/gdal_edit.py b/swig/python/gdal-utils/osgeo_utils/gdal_edit.py index f395098b7e33..50a401b58a7f 100755 --- a/swig/python/gdal-utils/osgeo_utils/gdal_edit.py +++ b/swig/python/gdal-utils/osgeo_utils/gdal_edit.py @@ -32,6 +32,7 @@ import sys from osgeo import gdal, osr +from osgeo_utils.auxiliary.util import enable_gdal_exceptions def Usage(isError): @@ -86,12 +87,8 @@ def ArgIsNumeric(s): return True +@enable_gdal_exceptions def gdal_edit(argv): - with gdal.ExceptionMgr(), osr.ExceptionMgr(): - return _gdal_edit(argv) - - -def _gdal_edit(argv): argv = gdal.GeneralCmdLineProcessor(argv) if argv is None: diff --git a/swig/python/gdal-utils/osgeo_utils/gdal_fillnodata.py b/swig/python/gdal-utils/osgeo_utils/gdal_fillnodata.py index c352b4866bd1..e036b2c4ea3c 100644 --- a/swig/python/gdal-utils/osgeo_utils/gdal_fillnodata.py +++ b/swig/python/gdal-utils/osgeo_utils/gdal_fillnodata.py @@ -37,6 +37,7 @@ from osgeo import gdal from osgeo_utils.auxiliary.gdal_argparse import GDALArgumentParser, GDALScript +from osgeo_utils.auxiliary.util import enable_gdal_exceptions def CopyBand(srcband, dstband): @@ -47,6 +48,7 @@ def CopyBand(srcband, dstband): ) +@enable_gdal_exceptions def gdal_fillnodata( src_filename: Optional[str] = None, band_number: int = 1, @@ -59,35 +61,6 @@ def gdal_fillnodata( smoothing_iterations: int = 0, interpolation: Optional[str] = None, options: Optional[list] = None, -): - with gdal.ExceptionMgr(): - return _gdal_fillnodata( - src_filename=src_filename, - band_number=band_number, - dst_filename=dst_filename, - driver_name=driver_name, - creation_options=creation_options, - quiet=quiet, - mask=mask, - max_distance=max_distance, - smoothing_iterations=smoothing_iterations, - interpolation=interpolation, - options=options, - ) - - -def _gdal_fillnodata( - src_filename: Optional[str] = None, - band_number: int = 1, - dst_filename: Optional[str] = None, - driver_name: str = "GTiff", - creation_options: Optional[list] = None, - quiet: bool = False, - mask: str = "default", - max_distance: Real = 100, - smoothing_iterations: int = 0, - interpolation: Optional[str] = None, - options: Optional[list] = None, ): options = options or [] creation_options = creation_options or [] diff --git a/swig/python/gdal-utils/osgeo_utils/gdal_pansharpen.py b/swig/python/gdal-utils/osgeo_utils/gdal_pansharpen.py index ef0322b00197..d2d7ee1efb6a 100644 --- a/swig/python/gdal-utils/osgeo_utils/gdal_pansharpen.py +++ b/swig/python/gdal-utils/osgeo_utils/gdal_pansharpen.py @@ -37,7 +37,7 @@ from typing import List, Optional, Sequence, Union from osgeo import gdal -from osgeo_utils.auxiliary.util import GetOutputDriverFor +from osgeo_utils.auxiliary.util import GetOutputDriverFor, enable_gdal_exceptions def Usage(isError): @@ -68,12 +68,8 @@ def Usage(isError): return 2 if isError else 0 +@enable_gdal_exceptions def main(argv=None): - with gdal.ExceptionMgr(): - return _main(argv=argv) - - -def _main(argv=sys.argv): argv = gdal.GeneralCmdLineProcessor(argv) if argv is None: diff --git a/swig/python/gdal-utils/osgeo_utils/gdal_polygonize.py b/swig/python/gdal-utils/osgeo_utils/gdal_polygonize.py index f00314782e8f..ab6702e85a7e 100644 --- a/swig/python/gdal-utils/osgeo_utils/gdal_polygonize.py +++ b/swig/python/gdal-utils/osgeo_utils/gdal_polygonize.py @@ -37,9 +37,10 @@ from osgeo import gdal, ogr from osgeo_utils.auxiliary.gdal_argparse import GDALArgumentParser, GDALScript -from osgeo_utils.auxiliary.util import GetOutputDriverFor +from osgeo_utils.auxiliary.util import GetOutputDriverFor, enable_gdal_exceptions +@enable_gdal_exceptions def gdal_polygonize( src_filename: Optional[str] = None, band_number: Union[int, str] = 1, @@ -54,37 +55,6 @@ def gdal_polygonize( layer_creation_options: Optional[list] = None, connectedness8: bool = False, ): - with gdal.ExceptionMgr(), ogr.ExceptionMgr(): - return _gdal_polygonize( - src_filename=src_filename, - band_number=band_number, - dst_filename=dst_filename, - overwrite=overwrite, - driver_name=driver_name, - dst_layername=dst_layername, - dst_fieldname=dst_fieldname, - quiet=quiet, - mask=mask, - options=options, - layer_creation_options=layer_creation_options, - connectedness8=connectedness8, - ) - - -def _gdal_polygonize( - src_filename: Optional[str] = None, - band_number: Union[int, str] = 1, - dst_filename: Optional[str] = None, - overwrite: bool = False, - driver_name: Optional[str] = None, - dst_layername: Optional[str] = None, - dst_fieldname: Optional[str] = None, - quiet: bool = False, - mask: str = "default", - options: Optional[list] = None, - layer_creation_options: Optional[list] = None, - connectedness8: bool = False, -): if isinstance(band_number, str) and not band_number.startswith("mask"): band_number = int(band_number) diff --git a/swig/python/gdal-utils/osgeo_utils/gdal_proximity.py b/swig/python/gdal-utils/osgeo_utils/gdal_proximity.py index 441a36b5a720..93a39c294107 100644 --- a/swig/python/gdal-utils/osgeo_utils/gdal_proximity.py +++ b/swig/python/gdal-utils/osgeo_utils/gdal_proximity.py @@ -35,7 +35,7 @@ from typing import Optional, Sequence from osgeo import gdal -from osgeo_utils.auxiliary.util import GetOutputDriverFor +from osgeo_utils.auxiliary.util import GetOutputDriverFor, enable_gdal_exceptions def Usage(isError): @@ -54,12 +54,9 @@ def Usage(isError): return 2 if isError else 0 +@enable_gdal_exceptions def main(argv=sys.argv): - with gdal.ExceptionMgr(): - return _main(argv=argv) - -def _main(argv=sys.argv): driver_name = None creation_options = [] alg_options = [] diff --git a/swig/python/gdal-utils/osgeo_utils/gdal_retile.py b/swig/python/gdal-utils/osgeo_utils/gdal_retile.py index 56957b568342..2452c7e98f89 100644 --- a/swig/python/gdal-utils/osgeo_utils/gdal_retile.py +++ b/swig/python/gdal-utils/osgeo_utils/gdal_retile.py @@ -34,6 +34,7 @@ import sys from osgeo import gdal, ogr, osr +from osgeo_utils.auxiliary.util import enable_gdal_exceptions progress = gdal.TermProgress_nocb @@ -941,12 +942,8 @@ def Usage(isError): return 2 if isError else 0 +@enable_gdal_exceptions def main(args=None, g=None): - with gdal.ExceptionMgr(), ogr.ExceptionMgr(), osr.ExceptionMgr(): - return _main(args=args, g=g) - - -def _main(args=None, g=None): if g is None: g = RetileGlobals() diff --git a/swig/python/gdal-utils/osgeo_utils/gdal_sieve.py b/swig/python/gdal-utils/osgeo_utils/gdal_sieve.py index 99c003bbf31a..4699d62fbd00 100644 --- a/swig/python/gdal-utils/osgeo_utils/gdal_sieve.py +++ b/swig/python/gdal-utils/osgeo_utils/gdal_sieve.py @@ -35,7 +35,7 @@ from osgeo import gdal from osgeo_utils.auxiliary.base import PathLikeOrStr -from osgeo_utils.auxiliary.util import GetOutputDriverFor +from osgeo_utils.auxiliary.util import GetOutputDriverFor, enable_gdal_exceptions def Usage(isError=True): @@ -128,6 +128,7 @@ def main(argv=sys.argv): ) +@enable_gdal_exceptions def gdal_sieve( src_filename: Optional[str] = None, dst_filename: PathLikeOrStr = None, @@ -136,27 +137,6 @@ def gdal_sieve( threshold: int = 2, connectedness: int = 4, quiet: bool = False, -): - with gdal.ExceptionMgr(): - return _gdal_sieve( - src_filename=src_filename, - dst_filename=dst_filename, - driver_name=driver_name, - mask=mask, - threshold=threshold, - connectedness=connectedness, - quiet=quiet, - ) - - -def _gdal_sieve( - src_filename: Optional[str] = None, - dst_filename: PathLikeOrStr = None, - driver_name: Optional[str] = None, - mask: str = "default", - threshold: int = 2, - connectedness: int = 4, - quiet: bool = False, ): # ============================================================================= # Verify we have next gen bindings with the sievefilter method. diff --git a/swig/python/gdal-utils/osgeo_utils/gdalattachpct.py b/swig/python/gdal-utils/osgeo_utils/gdalattachpct.py index e3d8ffa374fa..e13a9608a3de 100644 --- a/swig/python/gdal-utils/osgeo_utils/gdalattachpct.py +++ b/swig/python/gdal-utils/osgeo_utils/gdalattachpct.py @@ -37,7 +37,11 @@ from osgeo import gdal from osgeo_utils.auxiliary.base import PathLikeOrStr from osgeo_utils.auxiliary.color_table import ColorTableLike, get_color_table -from osgeo_utils.auxiliary.util import GetOutputDriverFor, open_ds +from osgeo_utils.auxiliary.util import ( + GetOutputDriverFor, + enable_gdal_exceptions, + open_ds, +) def Usage(isError=True): @@ -47,12 +51,8 @@ def Usage(isError=True): return 2 if isError else 0 +@enable_gdal_exceptions def main(argv=sys.argv): - with gdal.ExceptionMgr(): - return _main(argv=argv) - - -def _main(argv=sys.argv): pct_filename = None src_filename = None diff --git a/swig/python/gdal-utils/osgeo_utils/gdalcompare.py b/swig/python/gdal-utils/osgeo_utils/gdalcompare.py index e84b692f3eed..f27434170228 100644 --- a/swig/python/gdal-utils/osgeo_utils/gdalcompare.py +++ b/swig/python/gdal-utils/osgeo_utils/gdalcompare.py @@ -39,6 +39,7 @@ ####################################################### from osgeo_utils.auxiliary.base import PathLikeOrStr +from osgeo_utils.auxiliary.util import enable_gdal_exceptions my_print = print @@ -502,12 +503,8 @@ def Usage(isError=True): # +@enable_gdal_exceptions def main(argv=sys.argv): - with gdal.ExceptionMgr(): - return _main(argv=argv) - - -def _main(argv=sys.argv): # Default GDAL argument parsing. argv = gdal.GeneralCmdLineProcessor(argv) diff --git a/swig/python/gdal-utils/osgeo_utils/gdalmove.py b/swig/python/gdal-utils/osgeo_utils/gdalmove.py index bdb097dea93f..8d40b4542c15 100644 --- a/swig/python/gdal-utils/osgeo_utils/gdalmove.py +++ b/swig/python/gdal-utils/osgeo_utils/gdalmove.py @@ -34,6 +34,7 @@ from typing import Optional from osgeo import gdal, osr +from osgeo_utils.auxiliary.util import enable_gdal_exceptions ############################################################################### @@ -47,24 +48,13 @@ def fmt_loc(srs_obj, loc): ############################################################################### +@enable_gdal_exceptions def move( filename: str, t_srs: str, s_srs: Optional[str] = None, pixel_threshold: Optional[float] = None, ): - with gdal.ExceptionMgr(), osr.ExceptionMgr(): - return _move( - filename=filename, t_srs=t_srs, s_srs=s_srs, pixel_threshold=pixel_threshold - ) - - -def _move( - filename: str, - t_srs: str, - s_srs: Optional[str] = None, - pixel_threshold: Optional[float] = None, -): # ------------------------------------------------------------------------- # Open the file. diff --git a/swig/python/gdal-utils/osgeo_utils/ogr_layer_algebra.py b/swig/python/gdal-utils/osgeo_utils/ogr_layer_algebra.py index 20a6b6c723f3..587d501ffe11 100644 --- a/swig/python/gdal-utils/osgeo_utils/ogr_layer_algebra.py +++ b/swig/python/gdal-utils/osgeo_utils/ogr_layer_algebra.py @@ -33,6 +33,7 @@ import sys from osgeo import gdal, ogr, osr +from osgeo_utils.auxiliary.util import enable_gdal_exceptions ############################################################################### @@ -171,12 +172,8 @@ def CreateLayer( ############################################################################### +@enable_gdal_exceptions def main(argv=sys.argv): - with gdal.ExceptionMgr(), ogr.ExceptionMgr(), osr.ExceptionMgr(): - return _main(argv=argv) - - -def _main(argv=sys.argv): driver_name = "ESRI Shapefile" quiet = False diff --git a/swig/python/gdal-utils/osgeo_utils/ogrmerge.py b/swig/python/gdal-utils/osgeo_utils/ogrmerge.py index 578f32e0a672..0cc32e1ed1ac 100644 --- a/swig/python/gdal-utils/osgeo_utils/ogrmerge.py +++ b/swig/python/gdal-utils/osgeo_utils/ogrmerge.py @@ -38,7 +38,7 @@ from osgeo import gdal, ogr, osr from osgeo_utils.auxiliary.base import PathLikeOrStr -from osgeo_utils.auxiliary.util import GetOutputDriverFor +from osgeo_utils.auxiliary.util import GetOutputDriverFor, enable_gdal_exceptions def Usage(isError): @@ -167,12 +167,8 @@ def close_element(self, closing_name=None): # process() +@enable_gdal_exceptions def process(argv, progress=None, progress_arg=None): - with gdal.ExceptionMgr(), ogr.ExceptionMgr(), osr.ExceptionMgr(): - return _process(argv=argv, progress=progress, progress_arg=progress_arg) - - -def _process(argv, progress=None, progress_arg=None): if not argv: return Usage(isError=True) diff --git a/swig/python/gdal-utils/osgeo_utils/pct2rgb.py b/swig/python/gdal-utils/osgeo_utils/pct2rgb.py index d50f5404439f..66d81d04b1bd 100644 --- a/swig/python/gdal-utils/osgeo_utils/pct2rgb.py +++ b/swig/python/gdal-utils/osgeo_utils/pct2rgb.py @@ -42,11 +42,16 @@ from osgeo_utils.auxiliary.color_palette import get_color_palette from osgeo_utils.auxiliary.color_table import get_color_table from osgeo_utils.auxiliary.gdal_argparse import GDALArgumentParser, GDALScript -from osgeo_utils.auxiliary.util import GetOutputDriverFor, open_ds +from osgeo_utils.auxiliary.util import ( + GetOutputDriverFor, + enable_gdal_exceptions, + open_ds, +) progress = gdal.TermProgress_nocb +@enable_gdal_exceptions def pct2rgb( src_filename: PathLikeOrStr, pct_filename: Optional[PathLikeOrStr], @@ -54,25 +59,6 @@ def pct2rgb( band_number: int = 1, out_bands: int = 3, driver_name: Optional[str] = None, -): - with gdal.ExceptionMgr(): - return _pct2rgb( - src_filename=src_filename, - pct_filename=pct_filename, - dst_filename=dst_filename, - band_number=band_number, - out_bands=out_bands, - driver_name=driver_name, - ) - - -def _pct2rgb( - src_filename: PathLikeOrStr, - pct_filename: Optional[PathLikeOrStr], - dst_filename: PathLikeOrStr, - band_number: int = 1, - out_bands: int = 3, - driver_name: Optional[str] = None, ): # Open source file src_ds = open_ds(src_filename) diff --git a/swig/python/gdal-utils/osgeo_utils/rgb2pct.py b/swig/python/gdal-utils/osgeo_utils/rgb2pct.py index 34803a7e3f7b..b689a08a6e95 100644 --- a/swig/python/gdal-utils/osgeo_utils/rgb2pct.py +++ b/swig/python/gdal-utils/osgeo_utils/rgb2pct.py @@ -39,32 +39,20 @@ from osgeo_utils.auxiliary.base import PathLikeOrStr from osgeo_utils.auxiliary.color_table import get_color_table from osgeo_utils.auxiliary.gdal_argparse import GDALArgumentParser, GDALScript -from osgeo_utils.auxiliary.util import GetOutputDriverFor, open_ds +from osgeo_utils.auxiliary.util import ( + GetOutputDriverFor, + enable_gdal_exceptions, + open_ds, +) +@enable_gdal_exceptions def rgb2pct( src_filename: PathLikeOrStr, pct_filename: Optional[PathLikeOrStr] = None, dst_filename: Optional[PathLikeOrStr] = None, color_count: int = 256, driver_name: Optional[str] = None, -): - with gdal.ExceptionMgr(): - return _rgb2pct( - src_filename=src_filename, - pct_filename=pct_filename, - dst_filename=dst_filename, - color_count=color_count, - driver_name=driver_name, - ) - - -def _rgb2pct( - src_filename: PathLikeOrStr, - pct_filename: Optional[PathLikeOrStr] = None, - dst_filename: Optional[PathLikeOrStr] = None, - color_count: int = 256, - driver_name: Optional[str] = None, ): # Open source file src_ds = open_ds(src_filename)