#NEWLINE# def reverse_iter_lines( file_obj , blocksize = DEFAULT_BLOCKSIZE , preseek = True ) : #NEWLINE# #INDENT# 'Returns an iterator over the lines from a file object, in\n    reverse order, i.e., last line first, first line last. Uses the\n    :meth:`file.seek` method of file objects, and is tested compatible with\n    :class:`file` objects, as well as :class:`StringIO.StringIO`.\n\n    Args:\n        file_obj (file): An open file object. Note that ``reverse_iter_lines``\n            mutably reads from the file and other functions should not mutably\n            interact with the file object.\n        blocksize (int): The block size to pass to :meth:`file.read()`\n        preseek (bool): Tells the function whether or not to automatically\n            seek to the end of the file. Defaults to ``True``.\n            ``preseek=False`` is useful in cases when the\n            file cursor is already in position, either at the end of\n            the file or in the middle for relative reverse line\n            generation.\n    ' #NEWLINE# if preseek : #NEWLINE# #INDENT# file_obj . seek ( 0 , os . SEEK_END ) #NEWLINE# #UNINDENT# cur_pos = file_obj . tell ( ) #NEWLINE# buff = '' #NEWLINE# while ( 0 < cur_pos ) : #NEWLINE# #INDENT# read_size = min ( blocksize , cur_pos ) #NEWLINE# cur_pos -= read_size #NEWLINE# file_obj . seek ( cur_pos , os . SEEK_SET ) #NEWLINE# cur = file_obj . read ( read_size ) #NEWLINE# lines = cur . splitlines ( ) #NEWLINE# if ( cur [ ( - 1 ) ] == '\n' ) : #NEWLINE# #INDENT# lines . append ( '' ) #NEWLINE# #UNINDENT# if ( len ( lines ) == 1 ) : #NEWLINE# #INDENT# buff = ( lines [ 0 ] + buff ) #NEWLINE# continue #NEWLINE# #UNINDENT# last = lines . pop ( ) #NEWLINE# ( yield ( last + buff ) ) #NEWLINE# for line in lines [ : 0 : ( - 1 ) ] : #NEWLINE# #INDENT# ( yield line ) #NEWLINE# #UNINDENT# buff = lines [ 0 ] #NEWLINE# #UNINDENT# if buff : #NEWLINE# #INDENT# ( yield buff )