def tailFile(filename, offset, length):
 try:
  with open(filename, 'rb') as f:
   overflow = False
   f.seek(0, 2)
   sz = f.tell()
   if (sz > (offset + length)):
    overflow = True
    offset = (sz - 1)
   if ((offset + length) > sz):
    if (offset > (sz - 1)):
     length = 0
    offset = (sz - length)
   if (offset < 0):
    offset = 0
   if (length < 0):
    length = 0
   if (length == 0):
    data = ''
   else:
    f.seek(offset)
    data = f.read(length)
   offset = sz
   return [as_string(data), offset, overflow]
 except (OSError, IOError):
  return ['', offset, False]

def tailFile ( filename , offset , length ) : try : with open ( filename , 'rb' ) as f : overflow = False f . seek ( 0 , 2 ) sz = f . tell ( ) if ( sz > ( offset + length ) ) : overflow = True offset = ( sz - 1 ) if ( ( offset + length ) > sz ) : if ( offset > ( sz - 1 ) ) : length = 0 offset = ( sz - length ) if ( offset < 0 ) : offset = 0 if ( length < 0 ) : length = 0 if ( length == 0 ) : data = '' else : f . seek ( offset ) data = f . read ( length ) offset = sz return [ as_string ( data ) , offset , overflow ] except ( OSError , IOError ) : return [ '' , offset , False ]
read length bytes from the file named by filename starting at offset .