<commit_before># coding: utf-8
"""
    pyalysis.utils
    ~~~~~~~~~~~~~~

    :copyright: 2014 by <NAME> and Contributors
    :license: BSD, see LICENSE.rst for details
"""
import math
import re
import codecs
import tokenize

from pyalysis._compat import PY2


# as defined in PEP 263
_magic_encoding_comment = re.compile("coding[:=]\s*([-\w.]+)")


if PY2:
    def detect_encoding(file):
        encoding = 'utf-8'
        bom_found = False
        possible_bom = file.read(len(codecs.BOM_UTF8))
        if possible_bom == codecs.BOM_UTF8:
            encoding = 'utf-8-sig'
            bom_found = True
        file.seek(0)
        first = file.readline()
        match = _magic_encoding_comment.search(first)
        if match is None:
            second = file.readline()
            match = _magic_encoding_comment.search(second)
            if match is not None:
                encoding = match.group(1)
        else:
            encoding = match.group(1)
        if bom_found:
            if encoding == 'utf-8' or encoding == 'utf-8-sig':
                encoding = 'utf-8-sig'
            else:
                raise SyntaxError(
                    'Found utf8 BOM in conflict with encoding declaration'
                )
        file.seek(0)
        return encoding
else:
    def detect_encoding(file):
        try:
            encoding = tokenize.detect_encoding(file.readline)[0]
        finally:
            file.seek(0)
        return encoding


class classproperty(object):
    def __init__(self, fget):
        self.fget = fget

    def __get__(self, instance, owner):
        return self.fget(owner)


def iter_subclasses(cls):
    for subclass in cls.__subclasses__():
        for subsubclass in iter_subclasses(subclass):
            yield subsubclass
    yield cls


def count_digits(n):
    return int(math.floor(math.log10(n))) + 1<commit_msg>Add docstring to count_digits<commit_after># coding: utf-8
"""
    pyalysis.utils
    ~~~~~~~~~~~~~~

    :copyright: 2014 by <NAME> and Contributors
    :license: BSD, see LICENSE.rst for details
"""
import math
import re
import codecs
import tokenize

from pyalysis._compat import PY2


# as defined in PEP 263
_magic_encoding_comment = re.compile("coding[:=]\s*([-\w.]+)")


if PY2:
    def detect_encoding(file):
        encoding = 'utf-8'
        bom_found = False
        possible_bom = file.read(len(codecs.BOM_UTF8))
        if possible_bom == codecs.BOM_UTF8:
            encoding = 'utf-8-sig'
            bom_found = True
        file.seek(0)
        first = file.readline()
        match = _magic_encoding_comment.search(first)
        if match is None:
            second = file.readline()
            match = _magic_encoding_comment.search(second)
            if match is not None:
                encoding = match.group(1)
        else:
            encoding = match.group(1)
        if bom_found:
            if encoding == 'utf-8' or encoding == 'utf-8-sig':
                encoding = 'utf-8-sig'
            else:
                raise SyntaxError(
                    'Found utf8 BOM in conflict with encoding declaration'
                )
        file.seek(0)
        return encoding
else:
    def detect_encoding(file):
        try:
            encoding = tokenize.detect_encoding(file.readline)[0]
        finally:
            file.seek(0)
        return encoding


class classproperty(object):
    def __init__(self, fget):
        self.fget = fget

    def __get__(self, instance, owner):
        return self.fget(owner)


def iter_subclasses(cls):
    for subclass in cls.__subclasses__():
        for subsubclass in iter_subclasses(subclass):
            yield subsubclass
    yield cls


def count_digits(n):
    """
    Returns the number of digits in the given integer `n`.
    """
    return int(math.floor(math.log10(n))) + 1
{'fraction_non_alphanumeric': 0.10384514778969396, 'fraction_numerical': 0.014125032696834947, 'mean_word_length': 2.027711797307997, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '303482', 'n_tokens_mistral': 1187, 'n_tokens_neox': 1135, 'n_words': 294}