#NEWLINE# def _get_file_mode( filename , default = 'readonly' ) : #NEWLINE# #INDENT# '\n    Allow file object to already be opened in any of the valid modes and\n    and leave the file in the same state (opened or closed) as when\n    the function was called.\n    ' #NEWLINE# mode = default #NEWLINE# closed = fileobj_closed ( filename ) #NEWLINE# fmode = fileobj_mode ( filename ) #NEWLINE# if ( fmode is not None ) : #NEWLINE# #INDENT# mode = FILE_MODES . get ( closed ) #NEWLINE# if ( mode is None ) : #NEWLINE# #INDENT# raise IOError ( ( 'File mode of the input file object (%r) cannot be used to read/write FITS files.' % fmode ) ) #NEWLINE# #UNINDENT# #UNINDENT# return ( mode , closed )