<commit_before>""" Dotconf is an advanced configuration parser for Python.
"""


from dotconf.parser import DotconfParser, yacc


class Dotconf(object):

    def __init__(self, config, schema=None):
        self._config = config
        self._schema = schema

    def _parse(self):
        parser = DotconfParser(self._config, debug=False, write_tables=False,
                               errorlog=yacc.NullLogger())

        return parser.parse()

    def parse(self):
        config = self._parse()
        if self._schema is not None:
            config = self._schema.validate(config)
        return config<commit_msg>Added a from_filename contructor to Dotconf class<commit_after>""" Dotconf is an advanced configuration parser for Python.
"""


from dotconf.parser import DotconfParser, yacc


class Dotconf(object):

    def __init__(self, config, schema=None):
        self._config = config
        self._schema = schema

    @classmethod
    def from_filename(cls, filename, **kwargs):
        fconf = open(filename)
        return cls(fconf.read())

    def _parse(self):
        parser = DotconfParser(self._config, debug=False, write_tables=False,
                               errorlog=yacc.NullLogger())

        return parser.parse()

    def parse(self):
        config = self._parse()
        if self._schema is not None:
            config = self._schema.validate(config)
        return config
{'fraction_non_alphanumeric': 0.09335219236209336, 'fraction_numerical': 0.0, 'mean_word_length': 2.493827160493827, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '467223', 'n_tokens_mistral': 394, 'n_tokens_neox': 372, 'n_words': 106}