# Path: socceraction/data/opta/parsers/base.py
# class OptaXMLParser(OptaParser):
#     """Extract data from an Opta XML data stream.
# 
#     Parameters
#     ----------
#     path : str
#         Path of the data file.
#     """
# 
#     def __init__(self, path: str, **kwargs: Any) -> None:
#         with open(path, 'rb') as fh:
#             self.root = objectify.fromstring(fh.read())
# 
# def assertget(dictionary: Dict[str, Any], key: str) -> Any:
#     """Return the value of the item with the specified key.
# 
#     In contrast to the default `get` method, this version will raise an
#     assertion error if the given key is not present in the dict.
# 
#     Parameters
#     ----------
#     dictionary : dict
#         A Python dictionary.
#     key : str
#         A key in the dictionary.
# 
#     Returns
#     -------
#     Any
#         Returns the value for the specified key if the key is in the dictionary.
# 
#     Raises
#     ------
#     AssertionError
#         If the given key could not be found in the dictionary.
#     """
#     value = dictionary.get(key)
#     assert value is not None, 'KeyError: ' + key + ' not found in ' + str(dictionary)
#     return value


from datetime import datetime
from typing import Any, Dict, Tuple
from lxml import objectify
from .base import OptaXMLParser, assertget
    """

    def _get_doc(self) -> objectify.ObjectifiedElement:
        optadocument = self.root.find('SoccerDocument')
        return optadocument

    def _get_stats(self, obj: objectify.ObjectifiedElement) -> Dict[str, Any]:
        stats = {}
        for stat in obj.find('Stat'):
            stats[stat.attrib['Type']] = stat.text
        return stats

    def _get_name(self, obj: objectify.ObjectifiedElement) -> str:
        if "Known" in obj:
            return obj.Known
        return obj.First + " " + obj.Last

    def extract_competitions(self) -> Dict[Tuple[int, int], Dict[str, Any]]:
        """Return a dictionary with all available competitions.

        Returns
        -------
        dict
            A mapping between (competion ID, season ID) tuples and the
            information available about each competition in the data stream.
        """
        optadocument = self._get_doc()
        competition = optadocument.Competition
        competition_id = int(competition.attrib['uID'][1:])
        stats = self._get_stats(competition)

# Path: socceraction/data/opta/parsers/base.py
# class OptaXMLParser(OptaParser):
#     """Extract data from an Opta XML data stream.
# 
#     Parameters
#     ----------
#     path : str
#         Path of the data file.
#     """
# 
#     def __init__(self, path: str, **kwargs: Any) -> None:
#         with open(path, 'rb') as fh:
#             self.root = objectify.fromstring(fh.read())
# 
# def assertget(dictionary: Dict[str, Any], key: str) -> Any:
#     """Return the value of the item with the specified key.
# 
#     In contrast to the default `get` method, this version will raise an
#     assertion error if the given key is not present in the dict.
# 
#     Parameters
#     ----------
#     dictionary : dict
#         A Python dictionary.
#     key : str
#         A key in the dictionary.
# 
#     Returns
#     -------
#     Any
#         Returns the value for the specified key if the key is in the dictionary.
# 
#     Raises
#     ------
#     AssertionError
#         If the given key could not be found in the dictionary.
#     """
#     value = dictionary.get(key)
#     assert value is not None, 'KeyError: ' + key + ' not found in ' + str(dictionary)
#     return value


# Path: socceraction/data/opta/parsers/f7_xml.py
from datetime import datetime
from typing import Any, Dict, Tuple
from lxml import objectify
from .base import OptaXMLParser, assertget

    """

    def _get_doc(self) -> objectify.ObjectifiedElement:
        optadocument = self.root.find('SoccerDocument')
        return optadocument

    def _get_stats(self, obj: objectify.ObjectifiedElement) -> Dict[str, Any]:
        stats = {}
        for stat in obj.find('Stat'):
            stats[stat.attrib['Type']] = stat.text
        return stats

    def _get_name(self, obj: objectify.ObjectifiedElement) -> str:
        if "Known" in obj:
            return obj.Known
        return obj.First + " " + obj.Last

    def extract_competitions(self) -> Dict[Tuple[int, int], Dict[str, Any]]:
        """Return a dictionary with all available competitions.

        Returns
        -------
        dict
            A mapping between (competion ID, season ID) tuples and the
            information available about each competition in the data stream.
        """
        optadocument = self._get_doc()
        competition = optadocument.Competition
        competition_id = int(competition.attrib['uID'][1:])
        stats = self._get_stats(competition)

        season_id = int(assertget(stats, 'season_id'))