#NEWLINE# def seek( self , cookie , whence = 0 ) : #NEWLINE# #INDENT# if self . closed : #NEWLINE# #INDENT# raise ValueError ( 'tell on closed file' ) #NEWLINE# #UNINDENT# if ( not self . _seekable ) : #NEWLINE# #INDENT# raise IOError ( 'underlying stream is not seekable' ) #NEWLINE# #UNINDENT# if ( whence == 1 ) : #NEWLINE# #INDENT# if ( cookie != 0 ) : #NEWLINE# #INDENT# raise IOError ( "can't do nonzero cur-relative seeks" ) #NEWLINE# #UNINDENT# whence = 0 #NEWLINE# cookie = self . tell ( ) #NEWLINE# #UNINDENT# if ( whence == 2 ) : #NEWLINE# #INDENT# if ( cookie != 0 ) : #NEWLINE# #INDENT# raise IOError ( "can't do nonzero end-relative seeks" ) #NEWLINE# #UNINDENT# self . flush ( ) #NEWLINE# position = self . buffer . seek ( 0 , 2 ) #NEWLINE# self . _set_decoded_chars ( '' ) #NEWLINE# self . _snapshot = None #NEWLINE# if self . _decoder : #NEWLINE# #INDENT# self . _decoder . reset ( ) #NEWLINE# #UNINDENT# return position #NEWLINE# #UNINDENT# if ( whence != 0 ) : #NEWLINE# #INDENT# raise ValueError ( ( 'invalid whence (%r, should be 0, 1 or 2)' % ( bytes_to_feed , ) ) ) #NEWLINE# #UNINDENT# if ( cookie < 0 ) : #NEWLINE# #INDENT# raise ValueError ( ( 'negative seek position %r' % ( cookie , ) ) ) #NEWLINE# #UNINDENT# self . flush ( ) #NEWLINE# ( start_pos , dec_flags , bytes_to_feed , need_eof , chars_to_skip ) = self . _unpack_cookie ( cookie ) #NEWLINE# self . buffer . seek ( start_pos ) #NEWLINE# self . _set_decoded_chars ( '' ) #NEWLINE# self . _snapshot = None #NEWLINE# if ( ( cookie == 0 ) and self . _decoder ) : #NEWLINE# #INDENT# self . _decoder . reset ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( self . _decoder or dec_flags or chars_to_skip ) : #NEWLINE# #INDENT# self . _decoder = ( self . _decoder or self . _get_decoder ( ) ) #NEWLINE# self . _decoder . setstate ( ( b'' , dec_flags ) ) #NEWLINE# self . _snapshot = ( dec_flags , b'' ) #NEWLINE# #UNINDENT# #UNINDENT# if chars_to_skip : #NEWLINE# #INDENT# input_chunk = self . buffer . read ( bytes_to_feed ) #NEWLINE# self . _set_decoded_chars ( self . _decoder . decode ( input_chunk , need_eof ) ) #NEWLINE# self . _snapshot = ( dec_flags , input_chunk ) #NEWLINE# if ( len ( self . _decoded_chars ) < chars_to_skip ) : #NEWLINE# #INDENT# raise IOError ( "can't restore logical file position" ) #NEWLINE# #UNINDENT# self . _decoded_chars_used = chars_to_skip #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# encoder = ( self . _encoder or self . _get_encoder ( ) ) #NEWLINE# #UNINDENT# except LookupError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( cookie != 0 ) : #NEWLINE# #INDENT# encoder . setstate ( 0 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# encoder . reset ( ) #NEWLINE# #UNINDENT# #UNINDENT# return cookie