# Path: src/eutils/_internal/exceptions.py
# class EutilsError(Exception):
#     """Base class for all Eutils exceptions, and also used to raise
#     general exception.
# 
#     """
#     pass


import logging
import lxml.etree
from ..exceptions import EutilsError

logger = logging.getLogger(__name__)


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:

# 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
import logging
import lxml.etree
from ..exceptions import EutilsError


logger = logging.getLogger(__name__)


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(