# Path: src/eutils/_internal/exceptions.py
# class EutilsError(Exception):
#     """Base class for all Eutils exceptions, and also used to raise
#     general exception.
# 
#     """
#     pass
# 
# Path: src/eutils/_internal/xmlfacades/base.py
# class Base(object):
#     """Root class for all xmlfacade classes.
# 
#     This class is instantiated only by subclasses.
# 
#     xmlfacades must be instantiated with an XML document, passed
#     either as XML text or as the root of a parsed XML document.
# 
#     _root_tag must be defined by the subclass. It is used to validate
#     the node type upon instantiation of the subclass.
# 
#     """
# 
#     _root_tag = None
# 
#     def __init__(self, xml):
#         if isinstance(xml, lxml.etree._Element):
#             self._xml_root = xml
#         elif isinstance(xml, str) or isinstance(xml, bytes):
#             self._xml_root = lxml.etree.XML(xml)
#         else:
#             raise EutilsError("Cannot create object from type " + type(xml).__name__)
# 
#         if self._root_tag is None:
#             raise EutilsError("_root_tag not defined for class {}".format(type(self).__name__))
#         elif self._root_tag != self._xml_root.tag:
#             raise EutilsError("XML for {} object must be a {} element (got {})".format(
#                 type(self).__name__, self._root_tag, self._xml_root.tag))


from ..exceptions import EutilsError
from .base import Base

class GeneCommentaryGenomicCoords(Base):
    """This class  a rudimentary interface for using "Gene-commentary_genomic-coords" XML
    nodes in NCBI eutilities (efetch) responses.
    """

    _root_tag = "Gene-commentary_genomic-coords"

    def __str__(self):
        return "{self.gi}:{self.strand}:{self._interval_str}".format(self=self)

    @property
    def strand(self):
        nastrand = self._xml_root.find(".//Na-strand").get("value")
        return 1 if nastrand == "plus" else -1 if nastrand == "minus" else None

    @property
    def gi(self):
        return self._xml_root.findtext(".//Seq-id_gi")

    @property
    def intervals(self):
        return [(i.interval_from, i.interval_to)
                for i in (SeqInterval(n) for n in self._xml_root.findall(".//Seq-interval"))]

    @property
    def _interval_str(self):
        return ";".join(str(i) for i in self.intervals)



# Path: src/eutils/_internal/exceptions.py
# class EutilsError(Exception):
#     """Base class for all Eutils exceptions, and also used to raise
#     general exception.
# 
#     """
#     pass
# 
# Path: src/eutils/_internal/xmlfacades/base.py
# class Base(object):
#     """Root class for all xmlfacade classes.
# 
#     This class is instantiated only by subclasses.
# 
#     xmlfacades must be instantiated with an XML document, passed
#     either as XML text or as the root of a parsed XML document.
# 
#     _root_tag must be defined by the subclass. It is used to validate
#     the node type upon instantiation of the subclass.
# 
#     """
# 
#     _root_tag = None
# 
#     def __init__(self, xml):
#         if isinstance(xml, lxml.etree._Element):
#             self._xml_root = xml
#         elif isinstance(xml, str) or isinstance(xml, bytes):
#             self._xml_root = lxml.etree.XML(xml)
#         else:
#             raise EutilsError("Cannot create object from type " + type(xml).__name__)
# 
#         if self._root_tag is None:
#             raise EutilsError("_root_tag not defined for class {}".format(type(self).__name__))
#         elif self._root_tag != self._xml_root.tag:
#             raise EutilsError("XML for {} object must be a {} element (got {})".format(
#                 type(self).__name__, self._root_tag, self._xml_root.tag))


# Path: src/eutils/_internal/xmlfacades/genecommentary.py
from ..exceptions import EutilsError
from .base import Base


class GeneCommentaryGenomicCoords(Base):
    """This class  a rudimentary interface for using "Gene-commentary_genomic-coords" XML
    nodes in NCBI eutilities (efetch) responses.
    """

    _root_tag = "Gene-commentary_genomic-coords"

    def __str__(self):
        return "{self.gi}:{self.strand}:{self._interval_str}".format(self=self)

    @property
    def strand(self):
        nastrand = self._xml_root.find(".//Na-strand").get("value")
        return 1 if nastrand == "plus" else -1 if nastrand == "minus" else None

    @property
    def gi(self):
        return self._xml_root.findtext(".//Seq-id_gi")

    @property
    def intervals(self):
        return [(i.interval_from, i.interval_to)
                for i in (SeqInterval(n) for n in self._xml_root.findall(".//Seq-interval"))]

    @property
    def _interval_str(self):
        return ";".join(str(i) for i in self.intervals)



class SeqInterval(Base):