import xml.sax
import xml.sax.handler

from ._CfgSaxHandler import _CfgSaxHandler
from ._Configuration import Configuration
from ._Group import Group
from ._InvalidConfigXml import InvalidConfigXml
from ._Key import Key

from ._util import (
    ARRAY,
    STRING,
    DATA,
    INTEGER,
    REAL,
    DATE,
    BOOLEAN,
)

def read(file_or_path) -> Configuration:
    handler = _CfgSaxHandler()
    xml.sax.parse(file_or_path, handler)
    return handler.cfg


def read_string(string) -> Configuration:
    handler = _CfgSaxHandler()
    xml.sax.parseString(string, handler)
    return handler.cfg
