<commit_before>'''
@date 2013-5-10

@author <NAME> <<EMAIL>>
'''

import configparser
import io
import os
import re

##
# An advance ConfigParser build on configparser.ConfigParser.
#
# Features:
#
#  * set() will automatic create section if there do not have section.
#  * Support ini files that contained unnamed section.
#  * Default to case sensitive, actually most ini files are case sensitive,
#    if you want case insensitive, just set like below:
#        object.optionxform = rabird.core.ConfigParser.optionxform
#  * Removed spaces around '=', some ini parser do not accept the spaces
#    around '='.
#  * Support comments start with '#', ';'
#  * Support empty lines
#


class ConfigParser(configparser.ConfigParser):
    UNNAMED_SECTION = '#--CONFIGPARSER-UNNAMED-SECTION--#'
    # It will transfer to empty line
    _EMPTY_OPTION = '--CONFIGPARSER-EMPTY-OPTION'
    # It will transfer to comment line
    _COMMENT_OPTION = '--CONFIGPARSER-COMMENT-OPTION'

    def __init__(self, *args, **kwargs):
        if issubclass(ConfigParser, object):
            super(ConfigParser, self).__init__(*args, **kwargs)
        else:
            configparser.ConfigParser.__init__(self, *args, **kwargs)

        # Default to case sensitive
        self.optionxform = str
        # Added default unnamed section
        self.add_section(self.UNNAMED_SECTION)

        # Because readfp() may read multi-files, there may be same section with
        # some extension lines (comments or empty lines), so we can't just
        # start a line id with 0 in readfp(), that would lead
        # DuplicateOptionError error!
        self._line_id = 0

    def set(self, section, option, value):
        if not self.has_section(section):
            self.add_section(section)

        # In 3.x, the ConfigParser is a newstyle object
        if issubclass(ConfigParser, object):
            super(ConfigParser, self).set(section, option, str(value))
        else:
            configparser.ConfigParser.set(self, section, option, str(value))

    def readfp(self, fp, *args, **kwargs):
        # if hasattr(fp, 'name'):
        # We could only use the readline() by definitions
        abuffer = '[' + self.UNNAMED_SECTION + ']' + os.linesep

        while True:
            line = fp.readline()
            if len(line) <= 0:
                break

            temp_line = line.strip()
            if len(temp_line) <= 0:
                line = (self._EMPTY_OPTION +
                        str(self._line_id) + '=#' + os.linesep)
            elif temp_line.startswith('#') or temp_line.startswith(';'):
                line = self._COMMENT_OPTION + str(self._line_id) + '=#' + line
            abuffer += line

            self._line_id += 1

        # In 3.x, the ConfigParser is a newstyle object
        fp = io.StringIO(abuffer)
        if issubclass(ConfigParser, object):
            super(ConfigParser, self).readfp(fp, *args, **kwargs)
        else:
            configparser.ConfigParser.readfp(self, fp, *args, **kwargs)

    def write(self, fileobject):
        string_io = io.StringIO()

        # In 3.x, the ConfigParser is a newstyle object
        if issubclass(ConfigParser, object):
            super(ConfigParser, self).write(string_io)
        else:
            configparser.ConfigParser.write(self, string_io)

        abuffer = string_io.getvalue()
        string_io = io.StringIO(abuffer)
        # Remove unused UNNAMED section line.
        first_line = string_io.readline()
        # Sometimes UNNAMED section do not existed,
        # For example : We new a ConfigParser, then just created named section,
        # then write it to file.
        if self.UNNAMED_SECTION in first_line:
            abuffer = abuffer[len(first_line):]

            # Eat all empty lines after unnamed section
            while True:<commit_msg>Python3 have more arguments on write()<commit_after>'''
@date 2013-5-10

@author <NAME> <<EMAIL>>
'''

import configparser
import io
import os
import re

##
# An advance ConfigParser build on configparser.ConfigParser.
#
# Features:
#
#  * set() will automatic create section if there do not have section.
#  * Support ini files that contained unnamed section.
#  * Default to case sensitive, actually most ini files are case sensitive,
#    if you want case insensitive, just set like below:
#        object.optionxform = rabird.core.ConfigParser.optionxform
#  * Removed spaces around '=', some ini parser do not accept the spaces
#    around '='.
#  * Support comments start with '#', ';'
#  * Support empty lines
#


class ConfigParser(configparser.ConfigParser):
    UNNAMED_SECTION = '#--CONFIGPARSER-UNNAMED-SECTION--#'
    # It will transfer to empty line
    _EMPTY_OPTION = '--CONFIGPARSER-EMPTY-OPTION'
    # It will transfer to comment line
    _COMMENT_OPTION = '--CONFIGPARSER-COMMENT-OPTION'

    def __init__(self, *args, **kwargs):
        if issubclass(ConfigParser, object):
            super(ConfigParser, self).__init__(*args, **kwargs)
        else:
            configparser.ConfigParser.__init__(self, *args, **kwargs)

        # Default to case sensitive
        self.optionxform = str
        # Added default unnamed section
        self.add_section(self.UNNAMED_SECTION)

        # Because readfp() may read multi-files, there may be same section with
        # some extension lines (comments or empty lines), so we can't just
        # start a line id with 0 in readfp(), that would lead
        # DuplicateOptionError error!
        self._line_id = 0

    def set(self, section, option, value):
        if not self.has_section(section):
            self.add_section(section)

        # In 3.x, the ConfigParser is a newstyle object
        if issubclass(ConfigParser, object):
            super(ConfigParser, self).set(section, option, str(value))
        else:
            configparser.ConfigParser.set(self, section, option, str(value))

    def readfp(self, fp, *args, **kwargs):
        # if hasattr(fp, 'name'):
        # We could only use the readline() by definitions
        abuffer = '[' + self.UNNAMED_SECTION + ']' + os.linesep

        while True:
            line = fp.readline()
            if len(line) <= 0:
                break

            temp_line = line.strip()
            if len(temp_line) <= 0:
                line = (self._EMPTY_OPTION +
                        str(self._line_id) + '=#' + os.linesep)
            elif temp_line.startswith('#') or temp_line.startswith(';'):
                line = self._COMMENT_OPTION + str(self._line_id) + '=#' + line
            abuffer += line

            self._line_id += 1

        # In 3.x, the ConfigParser is a newstyle object
        fp = io.StringIO(abuffer)
        if issubclass(ConfigParser, object):
            super(ConfigParser, self).readfp(fp, *args, **kwargs)
        else:
            configparser.ConfigParser.readfp(self, fp, *args, **kwargs)

    def write(self, fileobject, *args, **kwargs):
        string_io = io.StringIO()

        # In 3.x, the ConfigParser is a newstyle object
        if issubclass(ConfigParser, object):
            super(ConfigParser, self).write(string_io, *args, **kwargs)
        else:
            configparser.ConfigParser.write(self, string_io, *args, **kwargs)

        abuffer = string_io.getvalue()
        string_io = io.StringIO(abuffer)
        # Remove unused UNNAMED section line.
        first_line = string_io.readline()
        # Sometimes UNNAMED section do not existed,
        # For example : We new a ConfigParser, then just created named section,
        # then write it to file.
        if self.UNNAMED_SECTION in first_line:
            abuffer = abuffer[len(first_line):]

            # Eat all empty lines after unnamed section
            while True:
{'fraction_non_alphanumeric': 0.10221706625418922, 'fraction_numerical': 0.003995875225573602, 'mean_word_length': 2.4150528169014085, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, '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': '2953000', 'n_tokens_mistral': 2279, 'n_tokens_neox': 2209, 'n_words': 670}