<commit_before># -*- coding:utf-8 -*-

import six

from .pystring import PyString


class PyFile(object):
    """More human-friendly file access interface.
    Works on Python2 and 3.

    Usage:
        file = File(".bashrc")
        file.write("Hello, world!!")
        print(file.read())
        del file
    """
    class Mode:
        r = "rb"
        w = "wb+"
        a = "ab+"

    def __init__(self, path, encoding="utf-8"):
        self.path = path
        self.encoding = encoding
        self.mode = None
        self._fd   = None

    def __del__(self):
        self.ensure_close()

    def __str__(self):
        return "<File object: path={}, encoding={} mode={}".format(
            self.path, self.encoding, self.mode 
        )

    def top(self):
        """
        Usage:
            >>> file = File("hello.txt")
            >>> print(file.read())
            hello, world
            >>> print(file.read())

            >>> print(file.top())
            >>> print(file.read())
            hello, world
        """
        return self.seek(0)

    def end(self):
        """
        Usage:
            >>> file = File("hello.txt")
            >>> print(file.end())
            >>> print(file.read())

        """
        return self.seek(0, 2)

    def seek(self, *args, **kwargs):<commit_msg>iterable<commit_after># -*- coding:utf-8 -*-

import six

from .pystring import PyString


class PyFile(object):
    """More human-friendly file access interface.
    Works on Python2 and 3.

    Usage:
        file = File(".bashrc")
        file.write("Hello, world!!")
        print(file.read())
        del file
    """
    class Mode:
        r = "rb"
        w = "wb+"
        a = "ab+"

    def __init__(self, path, encoding="utf-8"):
        self.path = path
        self.encoding = encoding
        self.mode = None
        self._fd   = None

    def __del__(self):
        self.ensure_close()

    def __str__(self):
        return "<File object: path={}, encoding={} mode={}".format(
            self.path, self.encoding, self.mode 
        )

    def __iter__(self):
        self.ensure_open(self.Mode.r)
        for l in self._fd:
            yield PyString(l)

    def top(self):
        """
        Usage:
            >>> file = File("hello.txt")
            >>> print(file.read())
            hello, world
            >>> print(file.read())

            >>> print(file.top())
            >>> print(file.read())
            hello, world
        """
        return self.seek(0)

    def end(self):
        """
        Usage:
            >>> file = File("hello.txt")
            >>> print(file.end())
            >>> print(file.read())

        """
        return self.seek(0, 2)

    def seek(self, *args, **kwargs):
{'fraction_non_alphanumeric': 0.15603353991979585, 'fraction_numerical': 0.005103900838497995, 'mean_word_length': 1.5430954587581094, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 51, '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': '4962479', 'n_tokens_mistral': 840, 'n_tokens_neox': 802, 'n_words': 190}