# Path: hgvs/exceptions.py
# class HGVSDataNotAvailableError(HGVSError):
#     pass


import logging
import os
import bioutils.seqfetcher
from ..exceptions import HGVSDataNotAvailableError
            from biocommons.seqrepo import SeqRepo
            from biocommons.seqrepo.dataproxy import SeqRepoRESTDataProxy

    def __init__(self):
        # If HGVS_SEQREPO_DIR is defined, we use seqrepo for *all* sequences.
        # If HGVS_SEQREPO_URL is defined, use instance of seqrepo-rest-service for *all* sequences.
        #   (see https://github.com/biocommons/seqrepo-rest-service for more info)
        # Otherwise, we fall back to remote sequence fetching
        seqrepo_dir = os.environ.get("HGVS_SEQREPO_DIR")
        seqrepo_url = os.environ.get("HGVS_SEQREPO_URL")
        if seqrepo_dir:
            self.sr = SeqRepo(seqrepo_dir)

            def _fetch_seq_seqrepo(ac, start_i=None, end_i=None):
                return self.sr.fetch(ac, start_i, end_i)

            self.fetcher = _fetch_seq_seqrepo
            self.source = "SeqRepo ({})".format(seqrepo_dir)
        elif seqrepo_url:
            self.sr = SeqRepoRESTDataProxy(seqrepo_url)
            self.fetcher = lambda ac, start_i=None, end_i=None: self.sr.get_sequence(ac, start_i, end_i)
            self.source = f"SeqRepo REST ({seqrepo_url})"
        else:
            self.sr = None
            self.fetcher = bioutils.seqfetcher.fetch_seq
            self.source = "bioutils.seqfetcher (network fetching)"
        _logger.info("Fetching sequences with " + self.source)

    def fetch_seq(self, ac, start_i=None, end_i=None):
        try:
            return self.fetcher(ac, start_i, end_i)
        except Exception as ex:

# Path: hgvs/exceptions.py
# class HGVSDataNotAvailableError(HGVSError):
#     pass


# Path: hgvs/dataproviders/seqfetcher.py
import logging
import os
import bioutils.seqfetcher
from ..exceptions import HGVSDataNotAvailableError
            from biocommons.seqrepo import SeqRepo
            from biocommons.seqrepo.dataproxy import SeqRepoRESTDataProxy


    def __init__(self):
        # If HGVS_SEQREPO_DIR is defined, we use seqrepo for *all* sequences.
        # If HGVS_SEQREPO_URL is defined, use instance of seqrepo-rest-service for *all* sequences.
        #   (see https://github.com/biocommons/seqrepo-rest-service for more info)
        # Otherwise, we fall back to remote sequence fetching
        seqrepo_dir = os.environ.get("HGVS_SEQREPO_DIR")
        seqrepo_url = os.environ.get("HGVS_SEQREPO_URL")
        if seqrepo_dir:
            self.sr = SeqRepo(seqrepo_dir)

            def _fetch_seq_seqrepo(ac, start_i=None, end_i=None):
                return self.sr.fetch(ac, start_i, end_i)

            self.fetcher = _fetch_seq_seqrepo
            self.source = "SeqRepo ({})".format(seqrepo_dir)
        elif seqrepo_url:
            self.sr = SeqRepoRESTDataProxy(seqrepo_url)
            self.fetcher = lambda ac, start_i=None, end_i=None: self.sr.get_sequence(ac, start_i, end_i)
            self.source = f"SeqRepo REST ({seqrepo_url})"
        else:
            self.sr = None
            self.fetcher = bioutils.seqfetcher.fetch_seq
            self.source = "bioutils.seqfetcher (network fetching)"
        _logger.info("Fetching sequences with " + self.source)

    def fetch_seq(self, ac, start_i=None, end_i=None):
        try:
            return self.fetcher(ac, start_i, end_i)
        except Exception as ex:

            raise HGVSDataNotAvailableError("Failed to fetch {ac} from {self.source} ({ex})".format(