dcc_json_toolkit.cache

Internal module to interact with cache.

It is recommended not to import any of the code from this module into another project. If your project requires the direct managing of local cached 'dcc.xsd' files, then use the classes in this module at your own judgement.

Consider working directly with DccSchema if your goal is not only to create a local file cache, but also to communicate the data from DCC files for further operations.

CacheManager

CacheManager(version: str)

Object with the purpose of managing cache files of the same version.

It is assumed that each called version has at least one file named 'dcc.xsd' stored at https://www.ptb.de/dcc/v{version}/dcc.xsd.

The constructor creates a new folder with the same name as the value defined at the parameter 'version'. No file is automatically cached.

Parameters:
  • version (str) –

    String following the Semantic Versioning v2.0.0 rules to specify a version.

version property

version: str

Initialized version, equivalent to the name of the cache folder.

cache_xsd_file

cache_xsd_file(uri: str, update_cache: bool = False, verbose: bool = False) -> Path

Caching an XSD file, as well as all imports it has.

Explores a URI of an XSD file to locally cache the file and the imports to other files. The caching of any 'dcc.xsd' file is automatically done at the constructor.

Parameters:
  • uri (str) –

    Link to the file to cache. This is either an online link starting by 'https://' or a local link starting by 'file://'.

  • update_cache (bool, default: False ) –

    Flag to update any cache file. Updating the cache correlates to overwrite all its contents with the latest provided by the URI.

  • verbose (bool, default: False ) –

    When enabled, prints over the terminal the path of each cached file. Disabled by default.

Returns:
  • file_path( Path ) –

    The Path instance pointing to the cached file.

purge

purge(remove_folder: bool = False, verbose: bool = True)

Removes all files stored in the cache.

Parameters:
  • remove_folder (bool, default: False ) –

    If set to True, the folder created by the constructor is also removed. Beware that this might break any further use of the class.

  • verbose (bool, default: True ) –

    Allows printing on the terminal the path of each file that was removed.

check_schema_online_file

check_schema_online_file(version: str)

Checking existence of the URL for the specific XSD version.

Each versioned XSD is published at a URL https://ptb.de/dcc/v{version}/dcc.xsd, where version is specified as following the Semantic Versioning rules. If an incorrect version is specified, leading to a non-existing page, the link is always redirected to 'https://www.ptb.de/cms/'.

Raises:
  • FileNotFoundError

    If the specified version file is not found at the URL.