<commit_before># This file is part of cclib (http://cclib.sf.net), a library for parsing
# and interpreting the results of computational chemistry packages.
#
# Copyright (C) 2006-2014, the cclib development team
#
# The library is free software, distributed under the terms of
# the GNU Lesser General Public version 2.1 or later. You should have
# received a copy of the license along with cclib. You can also access
# the full license online at http://www.gnu.org/copyleft/lgpl.html.

import io
import collections

try:
    import bz2 # New in Python 2.3.
except ImportError:
    bz2 = None
import fileinput
import gzip
import inspect
import logging
logging.logMultiprocessing =  0 # To avoid a problem with Avogadro
import os
import random
try:
    set # Standard type from Python 2.4+.
except NameError:
    from sets import Set as set
import sys
import zipfile

import numpy

from . import utils
from .data import ccData

class myBZ2File(bz2.BZ2File):
    """Return string instead of bytes"""
    def __next__(self):
        line = super().__next__()
        return line.decode("ascii", "replace")

class myGzipFile(gzip.GzipFile):
    """Return string instead of bytes"""
    def __next__(self):
        line = super().__next__()
        return line.decode("ascii", "replace")

if int(sys.version[0]) == 2:
    class FileWrapper(object):
        """Wrap a file object so that we can maintain position"""

        def __init__(self, file):
            self.file = file
            self.pos = 0
            self.file.seek(0, 2)
            self.size = self.file.tell()
            self.file.seek(0, 0)

        def next(self):
            line = next(self.file)
            self.pos += len(line)
            return line

        def __iter__(self):
            return self

        def close(self):
            self.file.close()

        def seek(self, pos, ref):
            self.file.seek(pos, ref)

elif int(sys.version[0]) >= 3:
    class FileWrapper(object):
        """Wrap a file object so that we can maintain position"""

        def __init__(self, file):
            self.file = file
            self.pos = 0
            self.file.seek(0, 2)
            self.size = self.file.tell()
            self.file.seek(0, 0)

        def __next__(self):
            line = next(self.file)
            self.pos += len(line)
            return line

        def __iter__(self):
            line = next(self.file)
            while line:
                self.pos += len(line)
                yield line
                line = next(self.file)

        def close(self):
            self.file.close()

        def seek(self, pos, ref):
            self.file.seek(pos, ref)

def openlogfile(filename):
    """Return a file object given a filename.

    Given the filename of a log file or a gzipped, zipped, or bzipped
    log file, this function returns a regular Python file object.
    
    Given an address starting with http://, this function retrieves the url
    and returns a file object using a temporary file.

    Given a list of filenames, this function returns a FileInput object,
    which can be used for seamless iteration without concatenation.
    """

    # If there is a single string argument given.
    if type(filename) in [str, str]:
<commit_msg>Modify FileWrapper per Karol's suggestion to simplify implementation<commit_after># This file is part of cclib (http://cclib.sf.net), a library for parsing
# and interpreting the results of computational chemistry packages.
#
# Copyright (C) 2006-2014, the cclib development team
#
# The library is free software, distributed under the terms of
# the GNU Lesser General Public version 2.1 or later. You should have
# received a copy of the license along with cclib. You can also access
# the full license online at http://www.gnu.org/copyleft/lgpl.html.

import io
import collections

try:
    import bz2 # New in Python 2.3.
except ImportError:
    bz2 = None
import fileinput
import gzip
import inspect
import logging
logging.logMultiprocessing =  0 # To avoid a problem with Avogadro
import os
import random
try:
    set # Standard type from Python 2.4+.
except NameError:
    from sets import Set as set
import sys
import zipfile

import numpy

from . import utils
from .data import ccData

class myBZ2File(bz2.BZ2File):
    """Return string instead of bytes"""
    def __next__(self):
        line = super().__next__()
        return line.decode("ascii", "replace")

class myGzipFile(gzip.GzipFile):
    """Return string instead of bytes"""
    def __next__(self):
        line = super().__next__()
        return line.decode("ascii", "replace")


class FileWrapper(object):
    """Wrap a file object so that we can maintain position"""

    def __init__(self, file):
        self.file = file
        self.pos = 0
        self.file.seek(0, 2)
        self.size = self.file.tell()
        self.file.seek(0, 0)

    def next(self):
        line = next(self.file)
        self.pos += len(line)
        return line

    def __next__(self):
        return self.next()

    def __iter__(self):
        return self

    def close(self):
        self.file.close()

    def seek(self, pos, ref):
        self.file.seek(pos, ref)

def openlogfile(filename):
    """Return a file object given a filename.

    Given the filename of a log file or a gzipped, zipped, or bzipped
    log file, this function returns a regular Python file object.
    
    Given an address starting with http://, this function retrieves the url
    and returns a file object using a temporary file.

    Given a list of filenames, this function returns a FileInput object,
    which can be used for seamless iteration without concatenation.
    """

    # If there is a single string argument given.
    if type(filename) in [str, str]:

{'fraction_non_alphanumeric': 0.08826583592938733, 'fraction_numerical': 0.010211145725164416, 'mean_word_length': 2.5130699088145896, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2211274', 'n_tokens_mistral': 1706, 'n_tokens_neox': 1619, 'n_words': 651}