def _get_file_mode(filename, default='readonly'):
 mode = default
 closed = fileobj_closed(filename)
 fmode = fileobj_mode(filename)
 if (fmode is not None):
  mode = FILE_MODES.get(fmode)
  if (mode is None):
   raise IOError('File mode of the input file object ({!r}) cannot be used to read/write FITS files.'.format(fmode))
 return (mode, closed)

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