#NEWLINE# def truncate( self , size = None ) : #NEWLINE# #INDENT# "Truncate the file's size.\n\n        If the optional size argument is present, the file is truncated to\n        (at most) that size. The size defaults to the current position.\n        The current file position is not changed unless the position\n        is beyond the new file size.\n\n        If the specified size exceeds the file's current size, the\n        file remains unchanged.\n        " #NEWLINE# _complain_ifclosed ( self . closed ) #NEWLINE# if ( size is None ) : #NEWLINE# #INDENT# size = self . pos #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( size < 0 ) : #NEWLINE# #INDENT# raise IOError ( EINVAL , 'Negative size not allowed' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( size < size . pos ) : #NEWLINE# #INDENT# self . pos = size #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# self . buf = self . getvalue ( ) [ : size ] #NEWLINE# self . len = size