<commit_before># Nemubot is a smart and modulable IM bot.
# Copyright (C) 2012-2015  <NAME>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

class GenericNode:

    def __init__(self, tag, **kwargs):
        self.tag = tag
        self.attrs = kwargs
        self.content = ""
        self.children = []
        self._cur = None
        self._deep_cur = 0


    def startElement(self, name, attrs):
        if self._cur is None:
            self._cur = GenericNode(name, **attrs)
            self._deep_cur = 0
        else:
            self._deep_cur += 1
            self._cur.startElement(name, attrs)
        return True


    def characters(self, content):
        if self._cur is None:
            self.content += content
        else:
            self._cur.characters(content)


    def endElement(self, name):
        if name is None:
            return

        if self._deep_cur:
            self._deep_cur -= 1
            self._cur.endElement(name)
        else:
            self.children.append(self._cur)
            self._cur = None
        return True


    def hasNode(self, nodename):
        return self.getNode(nodename) is not None


    def getNode(self, nodename):
        for c in self.children:
            if c is not None and c.tag == nodename:
                return c
        return None


    def __getitem__(self, item):
        return self.attrs[item]

    def __contains__(self, item):
        return item in self.attrs<commit_msg>Xmlparser: new class that just store one node, futher nodes will be parsed<commit_after># Nemubot is a smart and modulable IM bot.
# Copyright (C) 2012-2015  <NAME>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

class ParsingNode:

    """Allow any kind of subtags, just keep parsed ones
    """

    def __init__(self, tag=None, **kwargs):
        self.tag = tag
        self.attrs = kwargs
        self.content = ""
        self.children = []


    def characters(self, content):
        self.content += content


    def addChild(self, name, child):
        self.children.append(child)
        return True


    def hasNode(self, nodename):
        return self.getNode(nodename) is not None


    def getNode(self, nodename):
        for c in self.children:
            if c is not None and c.tag == nodename:
                return c
        return None


    def __getitem__(self, item):
        return self.attrs[item]

    def __contains__(self, item):
        return item in self.attrs


class GenericNode(ParsingNode):

    """Consider all subtags as dictionnary
    """

    def __init__(self, tag, **kwargs):
        super().__init__(tag, **kwargs)
        self._cur = None
        self._deep_cur = 0


    def startElement(self, name, attrs):
        if self._cur is None:
            self._cur = GenericNode(name, **attrs)
            self._deep_cur = 0
        else:
            self._deep_cur += 1
            self._cur.startElement(name, attrs)
        return True


    def characters(self, content):
        if self._cur is None:
            super().characters(content)
        else:
            self._cur.characters(content)


    def endElement(self, name):
        if name is None:
            return

        if self._deep_cur:
            self._deep_cur -= 1
            self._cur.endElement(name)
        else:
            self.children.append(self._cur)
            self._cur = None
        return True
{'fraction_non_alphanumeric': 0.08111038820212535, 'fraction_numerical': 0.005638690088917805, 'mean_word_length': 2.18728403593642, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7305427', 'n_tokens_mistral': 1298, 'n_tokens_neox': 1234, 'n_words': 484}