#NEWLINE# def tailFile( filename , offset , length ) : #NEWLINE# #INDENT# '\n    Read length bytes from the file named by filename starting at\n    offset, automatically increasing offset and setting overflow\n    flag if log size has grown beyond (offset + length).  If length\n    bytes are not available, as many bytes as are available are returned.\n    ' #NEWLINE# overflow = False #NEWLINE# try : #NEWLINE# #INDENT# f = open ( filename , 'rb' ) #NEWLINE# f . seek ( 0 , 2 ) #NEWLINE# sz = f . tell ( ) #NEWLINE# if ( sz > ( offset + length ) ) : #NEWLINE# #INDENT# overflow = True #NEWLINE# offset = ( sz - 1 ) #NEWLINE# #UNINDENT# if ( ( offset + length ) > sz ) : #NEWLINE# #INDENT# if ( offset > ( sz - 1 ) ) : #NEWLINE# #INDENT# length = 0 #NEWLINE# #UNINDENT# offset = ( sz - length ) #NEWLINE# #UNINDENT# if ( offset < 0 ) : #NEWLINE# #INDENT# offset = 0 #NEWLINE# #UNINDENT# if ( length < 0 ) : #NEWLINE# #INDENT# length = 0 #NEWLINE# #UNINDENT# if ( length == 0 ) : #NEWLINE# #INDENT# data = '' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# f . seek ( offset ) #NEWLINE# data = f . read ( length ) #NEWLINE# #UNINDENT# offset = sz #NEWLINE# return [ data , offset , overflow ] #NEWLINE# #UNINDENT# except ( OSError , IOError ) : #NEWLINE# #INDENT# return [ '' , offset , False ]