<commit_before>#!/usr/bin/env python

"""
 untangle

 Converts xml to python objects.

 The only method you need to call is parse()
 
 Partially inspired by xml2obj 
 (http://code.activestate.com/recipes/149368-xml2obj/)

 Author: <NAME> (http://0chris.com)
 License: MIT License - http://www.opensource.org/licenses/mit-license.php
"""

from xml.sax import make_parser, handler, SAXParseException
from StringIO import StringIO
import os

__version__ = '0.2'


class ParseException(Exception):
	"""
	Something happened while parsing the XML data.
	"""


class Element():
    """
    Representation of an XML element.
    """
    def __init__(self, name, attributes):
        self.name = name
        self.attributes = attributes
        self.children = []
        self.is_root = False

    def add_child(self, element):
        element.name = element.name.replace('-', '_')
        self.children.append(element)

    def get_attribute(self, key):
        return self.attributes.get(key)

    def get_elements(self, name=None):
        if name:
            return [e for e in self.children if e.name == name]
        else:
            return self.children

    def __getitem__(self, key):
        return self.get_attribute(key)<commit_msg>Removed unused import; removed tab indent<commit_after>#!/usr/bin/env python

"""
 untangle

 Converts xml to python objects.

 The only method you need to call is parse()
 
 Partially inspired by xml2obj 
 (http://code.activestate.com/recipes/149368-xml2obj/)

 Author: <NAME> (http://0chris.com)
 License: MIT License - http://www.opensource.org/licenses/mit-license.php
"""

from xml.sax import make_parser, handler, SAXParseException
from StringIO import StringIO

__version__ = '0.2'


class ParseException(Exception):
    """
    Something happened while parsing the XML data.
    """


class Element():
    """
    Representation of an XML element.
    """
    def __init__(self, name, attributes):
        self.name = name
        self.attributes = attributes
        self.children = []
        self.is_root = False

    def add_child(self, element):
        element.name = element.name.replace('-', '_')
        self.children.append(element)

    def get_attribute(self, key):
        return self.attributes.get(key)

    def get_elements(self, name=None):
        if name:
            return [e for e in self.children if e.name == name]
        else:
            return self.children

    def __getitem__(self, key):
        return self.get_attribute(key)
{'fraction_non_alphanumeric': 0.11146624051138633, 'fraction_numerical': 0.008789452656811825, 'mean_word_length': 2.7767722473604826, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 8}, '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': '183355', 'n_tokens_mistral': 765, 'n_tokens_neox': 727, 'n_words': 208}