<commit_before>import glob
import fileinput
import sys


def modify(input_dir, file_reg, func, args=None):
    """Run func for every line in the files matching file_reg in input_dir."""
    with fileinput.input(glob.glob(input_dir + file_reg), inplace=True) as f:
        for line in f:
            try:
                if args:
                    sys.stdout.write(func(line, *args))
                else:
                    sys.stdout.write(func(line))
            except Exception:
                print(line)
                raise


def concat(input_dir, file_reg, output, *, encoding='utf-8'):
    """Concatenate all files matching file_reg in input_dir into output."""
    with fileinput.input(glob.glob(input_dir + file_reg),
                         openhook=fileinput.hook_encoded(encoding)) as f, \
            open(output, 'w', encoding=encoding) as o:
        for line in f:
            try:
                o.write(line)
            except Exception:
                print(line)
                raise


def func(input_dir, file_reg, func, args=None, *, inplace=False):
    with fileinput.input(glob.glob(input_dir + file_reg),
                         inplace=inplace) as f:
        for line in f:
            try:
                if args:
                    func(line, *args)
                else:
                    func(line)
            except Exception:
                print(line)
                raise<commit_msg>Modified func to accept encoding parameter.<commit_after>import glob
import fileinput
import sys


def modify(input_dir, file_reg, func, args=None):
    """Run func for every line in the files matching file_reg in input_dir."""
    with fileinput.input(glob.glob(input_dir + file_reg), inplace=True) as f:
        for line in f:
            try:
                if args:
                    sys.stdout.write(func(line, *args))
                else:
                    sys.stdout.write(func(line))
            except Exception:
                print(line)
                raise


def concat(input_dir, file_reg, output, *, encoding='utf-8'):
    """Concatenate all files matching file_reg in input_dir into output."""
    with fileinput.input(glob.glob(input_dir + file_reg),
                         openhook=fileinput.hook_encoded(encoding)) as f, \
            open(output, 'w', encoding=encoding) as o:
        for line in f:
            try:
                o.write(line)
            except Exception:
                print(line)
                raise


def func(input_dir, file_reg, func, args=None, *, encoding='utf-8'):
    with fileinput.input(glob.glob(input_dir + file_reg),
                         openhook=fileinput.hook_encoded(encoding)) as f:
        for line in f:
            try:
                if args:
                    func(line, *args)
                else:
                    func(line)
            except Exception:
                print(line)
                raise
{'fraction_non_alphanumeric': 0.09177755032412147, 'fraction_numerical': 0.0010235414534288639, 'mean_word_length': 1.5651793525809274, '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': '1603026', 'n_tokens_mistral': 813, 'n_tokens_neox': 772, 'n_words': 216}