# Path: securesystemslib/exceptions.py
# class Error(Exception):
# class Warning(Warning):
# class FormatError(Error):
# class InvalidMetadataJSONError(FormatError):
# class UnsupportedAlgorithmError(Error):
# class BadHashError(Error):
# class BadPasswordError(Error):
# class CryptoError(Error):
# class BadSignatureError(CryptoError):
# class UnknownMethodError(CryptoError):
# class UnsupportedLibraryError(Error):
# class InvalidNameError(Error):
# class NotFoundError(Error):
# class URLMatchesNoPatternError(Error):
# class InvalidConfigurationError(Error):
# class StorageError(Error):
#   def __init__(self, exception):
#   def __str__(self):
#   def __init__(self, expected_hash, observed_hash):
#   def __str__(self):
#   def __init__(self, metadata_role_name):
#   def __str__(self):


import abc
import errno
import logging
import os
import shutil
from contextlib import contextmanager
from securesystemslib import exceptions
from typing import BinaryIO, IO, Iterator, List



class FilesystemBackend(StorageBackendInterface):
  """
  <Purpose>
    A concrete implementation of StorageBackendInterface which interacts with
    local filesystems using Python standard library functions.
  """

  # As FilesystemBackend is effectively a stateless wrapper around various
  # standard library operations, we only ever need a single instance of it.
  # That single instance is safe to be (re-)used by all callers. Therefore
  # implement the singleton pattern to avoid uneccesarily creating multiple
  # objects.
  _instance = None

  def __new__(cls, *args, **kwargs):
    if cls._instance is None:
      cls._instance = object.__new__(cls, *args, **kwargs)
    return cls._instance


  @contextmanager
  def get(self, filepath:str) -> Iterator[BinaryIO]:
    file_object = None
    try:
      file_object = open(filepath, 'rb')
      yield file_object
    except OSError:

# Path: securesystemslib/exceptions.py
# class Error(Exception):
# class Warning(Warning):
# class FormatError(Error):
# class InvalidMetadataJSONError(FormatError):
# class UnsupportedAlgorithmError(Error):
# class BadHashError(Error):
# class BadPasswordError(Error):
# class CryptoError(Error):
# class BadSignatureError(CryptoError):
# class UnknownMethodError(CryptoError):
# class UnsupportedLibraryError(Error):
# class InvalidNameError(Error):
# class NotFoundError(Error):
# class URLMatchesNoPatternError(Error):
# class InvalidConfigurationError(Error):
# class StorageError(Error):
#   def __init__(self, exception):
#   def __str__(self):
#   def __init__(self, expected_hash, observed_hash):
#   def __str__(self):
#   def __init__(self, metadata_role_name):
#   def __str__(self):


# Path: securesystemslib/storage.py
import abc
import errno
import logging
import os
import shutil
from contextlib import contextmanager
from securesystemslib import exceptions
from typing import BinaryIO, IO, Iterator, List




class FilesystemBackend(StorageBackendInterface):
  """
  <Purpose>
    A concrete implementation of StorageBackendInterface which interacts with
    local filesystems using Python standard library functions.
  """

  # As FilesystemBackend is effectively a stateless wrapper around various
  # standard library operations, we only ever need a single instance of it.
  # That single instance is safe to be (re-)used by all callers. Therefore
  # implement the singleton pattern to avoid uneccesarily creating multiple
  # objects.
  _instance = None

  def __new__(cls, *args, **kwargs):
    if cls._instance is None:
      cls._instance = object.__new__(cls, *args, **kwargs)
    return cls._instance


  @contextmanager
  def get(self, filepath:str) -> Iterator[BinaryIO]:
    file_object = None
    try:
      file_object = open(filepath, 'rb')
      yield file_object
    except OSError:

      raise exceptions.StorageError(