_Downloader.validate_file_format

classmethod _Downloader.validate_file_format(osm_file_format, valid_file_formats=None, raise_err=True, **kwargs)

Validate an input file format of OSM data.

The validation is done by matching the input to a filename extension available on a free download server.

Parameters
  • osm_file_format (str) – file format/extension of the data available on a free download server

  • valid_file_formats (Iterable) – fil extensions of the data available on a free download server

  • raise_err (bool) – (if the input fails to match a valid name) whether to raise the error pydriosm.downloader.InvalidFileFormatError, defaults to True

  • kwargs – [optional] parameters of pyhelpers.text.find_similar_str()

Returns

validated file format

Return type

str

Tests:

>>> from pydriosm.downloader import _Downloader

>>> file_fmt = 'abc'
>>> _Downloader.validate_file_format(file_fmt)  # Raise an error
Traceback (most recent call last):
  ...
pydriosm.errors.InvalidFileFormatError:
  `osm_file_format='abc'` -> The input `osm_file_format` is unidentifiable.
    Valid options include: {'.garmin-opentopo.zip', '.osm.bz2', '.osm.pbf', '.garmin-...

>>> avail_file_fmts = ['.osm.pbf', '.shp.zip', '.osm.bz2']

>>> file_fmt = 'pbf'
>>> _Downloader.validate_file_format(file_fmt, avail_file_fmts)
'.osm.pbf'

>>> file_fmt = 'shp'
>>> _Downloader.validate_file_format(file_fmt, avail_file_fmts)
'.shp.zip'