# Path: elbepack/treeutils.py
# class etree(ebase):
#     def __init__(self, fname):
#         if fname is not None:
#             parser = XMLParser(huge_tree=True, remove_comments=False)
#             et = parse(fname, parser=parser)
#         else:
#             et = ElementTree(file=None)
# 
#         ebase.__init__(self, et)
# 
#     def write(self, fname, encoding=None):
#         # Make sure, that we end with a newline
#         self.et.getroot().tail = '\n'
#         self.et.write(fname, encoding=encoding)
# 
#     def tostring(self):
#         return self.et.tostring()
# 
#     def ensure_child(self, tag):
#         retval = self.et.find("./" + tag)
#         if retval is not None:
#             return elem(retval)
#         return elem(SubElement(self.et.getroot(), tag))
# 
#     def set_child_position(self, child, pos):
#         root = self.et.getroot()
#         root.remove(child.et)
#         root.insert(pos, child.et)
# 
#     def setroot(self, tag):
#         retval = elem(Element(tag))
#         # pylint: disable=protected-access
#         self.et._setroot(retval.et)
#         return retval
# 
#     @property
#     def root(self):
#         return elem(self.et.getroot())
# 
# Path: elbepack/validate.py
# def validate_xml(fname):
#     if os.path.getsize(fname) > (1 << 30):
#         return ["%s is greater than 1 GiB. "
#                 "Elbe does not support files of this size." % fname]
# 
#     schema_file = "https://www.linutronix.de/projects/Elbe/dbsfed.xsd"
#     parser = XMLParser(huge_tree=True)
#     schema_tree = etree.parse(schema_file)
#     schema = etree.XMLSchema(schema_tree)
# 
#     try:
#         xml = parse(fname, parser=parser)
# 
#         if schema.validate(xml):
#             return validate_xml_content(xml)
#     except etree.XMLSyntaxError:
#         return ["XML Parse error\n" + str(sys.exc_info()[1])]
#     except BaseException:
#         return ["Unknown Exception during validation\n" +
#                 str(sys.exc_info()[1])]
# 
#     # We have errors, return them in string form...
#     return error_log_to_strings(schema.error_log)
# 
# Path: elbepack/xmldefaults.py
# class ElbeDefaults:
# 
#     def __init__(self, build_type):
# 
#         assert build_type in defaults, ("Invalid buildtype %s\n"
#                                         "Valid buildtypes are:\n  - %s" %
#                                         (build_type, "\n  - ".join(defaults.keys())))
# 
#         self.defaults = defaults[build_type]
#         self.defaults["nicmac"] = get_random_mac()
# 
#         self.generic_defaults = archindep_defaults
# 
#     def __getitem__(self, key):
#         if key in self.defaults:
#             return self.defaults[key]
#         if key in self.generic_defaults:
#             return self.generic_defaults[key]
# 
#         return None
# 
# Path: elbepack/version.py



import os
import re
from urllib.error import URLError
from urllib.request import (urlopen, install_opener, build_opener,
                            HTTPPasswordMgrWithDefaultRealm,
                            HTTPBasicAuthHandler)
from elbepack.treeutils import etree
from elbepack.validate import validate_xml
from elbepack.xmldefaults import ElbeDefaults
from elbepack.version import elbe_version, is_devel
    pass

class ValidationMode:
    NO_CHECK = 1
    CHECK_BINARIES = 2
    CHECK_ALL = 0

def replace_localmachine(mirror, initvm=True):
    if initvm:
        localmachine = "10.0.2.2"
    else:
        localmachine = "localhost"

    return mirror.replace("LOCALMACHINE", localmachine)

class ElbeXML:

    # pylint: disable=too-many-public-methods

    def __init__(
            self,
            fname,
            buildtype=None,
            skip_validate=False,
            url_validation=ValidationMode.NO_CHECK):
        if not skip_validate:
            validation = validate_xml(fname)
            if validation:
                raise ValidationError(validation)


# Path: elbepack/treeutils.py
# class etree(ebase):
#     def __init__(self, fname):
#         if fname is not None:
#             parser = XMLParser(huge_tree=True, remove_comments=False)
#             et = parse(fname, parser=parser)
#         else:
#             et = ElementTree(file=None)
# 
#         ebase.__init__(self, et)
# 
#     def write(self, fname, encoding=None):
#         # Make sure, that we end with a newline
#         self.et.getroot().tail = '\n'
#         self.et.write(fname, encoding=encoding)
# 
#     def tostring(self):
#         return self.et.tostring()
# 
#     def ensure_child(self, tag):
#         retval = self.et.find("./" + tag)
#         if retval is not None:
#             return elem(retval)
#         return elem(SubElement(self.et.getroot(), tag))
# 
#     def set_child_position(self, child, pos):
#         root = self.et.getroot()
#         root.remove(child.et)
#         root.insert(pos, child.et)
# 
#     def setroot(self, tag):
#         retval = elem(Element(tag))
#         # pylint: disable=protected-access
#         self.et._setroot(retval.et)
#         return retval
# 
#     @property
#     def root(self):
#         return elem(self.et.getroot())
# 
# Path: elbepack/validate.py
# def validate_xml(fname):
#     if os.path.getsize(fname) > (1 << 30):
#         return ["%s is greater than 1 GiB. "
#                 "Elbe does not support files of this size." % fname]
# 
#     schema_file = "https://www.linutronix.de/projects/Elbe/dbsfed.xsd"
#     parser = XMLParser(huge_tree=True)
#     schema_tree = etree.parse(schema_file)
#     schema = etree.XMLSchema(schema_tree)
# 
#     try:
#         xml = parse(fname, parser=parser)
# 
#         if schema.validate(xml):
#             return validate_xml_content(xml)
#     except etree.XMLSyntaxError:
#         return ["XML Parse error\n" + str(sys.exc_info()[1])]
#     except BaseException:
#         return ["Unknown Exception during validation\n" +
#                 str(sys.exc_info()[1])]
# 
#     # We have errors, return them in string form...
#     return error_log_to_strings(schema.error_log)
# 
# Path: elbepack/xmldefaults.py
# class ElbeDefaults:
# 
#     def __init__(self, build_type):
# 
#         assert build_type in defaults, ("Invalid buildtype %s\n"
#                                         "Valid buildtypes are:\n  - %s" %
#                                         (build_type, "\n  - ".join(defaults.keys())))
# 
#         self.defaults = defaults[build_type]
#         self.defaults["nicmac"] = get_random_mac()
# 
#         self.generic_defaults = archindep_defaults
# 
#     def __getitem__(self, key):
#         if key in self.defaults:
#             return self.defaults[key]
#         if key in self.generic_defaults:
#             return self.generic_defaults[key]
# 
#         return None
# 
# Path: elbepack/version.py



# Path: elbepack/elbexml.py
import os
import re
from urllib.error import URLError
from urllib.request import (urlopen, install_opener, build_opener,
                            HTTPPasswordMgrWithDefaultRealm,
                            HTTPBasicAuthHandler)
from elbepack.treeutils import etree
from elbepack.validate import validate_xml
from elbepack.xmldefaults import ElbeDefaults
from elbepack.version import elbe_version, is_devel

    pass

class ValidationMode:
    NO_CHECK = 1
    CHECK_BINARIES = 2
    CHECK_ALL = 0

def replace_localmachine(mirror, initvm=True):
    if initvm:
        localmachine = "10.0.2.2"
    else:
        localmachine = "localhost"

    return mirror.replace("LOCALMACHINE", localmachine)

class ElbeXML:

    # pylint: disable=too-many-public-methods

    def __init__(
            self,
            fname,
            buildtype=None,
            skip_validate=False,
            url_validation=ValidationMode.NO_CHECK):
        if not skip_validate:
            validation = validate_xml(fname)
            if validation:
                raise ValidationError(validation)


        self.xml = etree(fname)