"""
This module provides a Python implementation of functionality of the GNU tail command.
"""
import os

class TailError(Exception):
    """Tail exceptions"""

class TailBase:
    """
    Operations to extract the beginning or end of a stream
    """
    def __init__(self, initial_position):
        """
        We have to keep track of the current position we are at.
        """
        self.position_index = initial_position

    def head(self, number_entries):
        """
        Retrieve the first number of entries from the stream
        :number_entries: how many items to retrieve
        """
        raise NotImplementedError()

    def tail(self, number_entries):
        """
        Retrieve the last number of entries from the stream
        :number_entries: how many items to retrieve
        """
        raise NotImplementedError()

    def seek_forwards_to_next_separator(self):
        """Seek forwards until the next separator is found"""
        raise NotImplementedError()

    def seek_backwards_to_next_separator(self):
        """Seek backwards until the next separator is found, then set the position
        to be just after that separator."""
        raise NotImplementedError()

    def read(self, read_size=None):
        """Read from the stream.
        :read_size: number of items to read from the current position onwards,
                    if not parameter given the default is to read everything from the current position onwards.
        :returns: A tuple of the length of the data and the data
        """
        raise NotImplementedError()


class FileBasedTail(TailBase):
    """Implement tail operations for a file object"""

    def __init__(self, filename):
        """
        :filename: The name of the file to open
        """
        self.filename = filename
        check_file_validity(self.filename)
        self.file_obj = open(filename)

    def tail(self, number_lines=10):
        """
        :number_lines: the number of lines to take from the end of the file
        """
        raise NotImplementedError()

    def seek(self, position, whence=0):
        """
        Seek to position relative to place specified by whence
        :position: where to move the filepointer to
        :whence: which relative position to use, same as Python's file objects.
                 0 is beginning of file, 1 is the current position, 2 is end of file position.
        """
        self.file_obj.seek(position, whence)

    def seek_to_end(self):
        """Seek to the end of the file"""
        self.seek(0, 2)

    def read(self, read_size=None):
        """Read the next read_size bytes from the current file position or all of
        the rest of the file if not specified.
        """
        if read_size:
            data = self.file_obj.read(read_size)
        else:
            data = self.file_obj.read(read_size)
        return len(data), data

def check_file_validity(filename):
    """Check if a file exists is readable and is a vaild file"""
    if not os.access(filename, os.F_OK):
        raise TailError("File '{}' does not exist".format(filename))
    if not os.access(filename, os.R_OK):
        raise TailError("File '{}' is not readable".format(filename))
    if os.path.isdir(filename):
        raise TailError("'{}' is a directory and not a file".format(filename))


@@ -659,32 +659,35 @@
 , number_entries
+=10
 ):%0A        %22%22%22%0A 
@@ -1351,16 +1351,32 @@
 onwards,
+ if no parameter
 %0A       
@@ -1393,23 +1393,9 @@
    i
-f not parameter
+s
  giv
@@ -1580,16 +1580,146 @@
 rror()%0A%0A
+    def current_position(self):%0A        %22%22%22Return the current index in the stream%0A        %22%22%22%0A        return self.position_index%0A%0A
 %0Aclass F
@@ -2017,16 +2017,43 @@
 ilename)
+%0A        super().__init__()
 %0A%0A    de
@@ -2072,19 +2072,21 @@
  number_
-lin
+entri
 es=10):%0A
@@ -2113,19 +2113,21 @@
 :number_
-lin
+entri
 es: the 
@@ -3061,16 +3061,226 @@
 , data%0A%0A
+    def current_position(self):%0A        %22%22%22Return the current position in the file that the file pointer is pointed at%22%22%22%0A        self.position_index = self.file_obj.tell()%0A        return self.position_index%0A%0A%0A
 def chec
@@ -3703,9 +3703,8 @@
 ename))%0A
-%0A

Implement current position method for files