'Open a FITS file from a file object or a GzipFile object.'

def _open_fileobj(self, fileobj, mode, overwrite):

    closed = fileobj_closed(fileobj)
    fmode = (fileobj_mode(fileobj) or IO_FITS_MODES[mode])
    if (mode == 'ostream'):
        self._overwrite_existing(overwrite, fileobj, closed)
    if (not closed):
        if (((mode in ('readonly', 'denywrite', 'copyonwrite')) and (not (('r' in fmode) or ('+' in fmode)))) or ((mode == 'append') and (fmode not in ('ab+', 'rb+'))) or ((mode == 'ostream') and (not (('w' in fmode) or ('a' in fmode) or ('+' in fmode)))) or ((mode == 'update') and (fmode not in ('rb+', 'wb+')))):
            raise ValueError("Mode    argument    '{}'    does    not    match    mode    of    the    input    file    ({}).".format(mode, fmode))
        self._file = fileobj
    elif isfile(fileobj):
        self._file = fileobj_open(self.name, IO_FITS_MODES[mode])
    else:
        self._file = gzip.open(self.name, IO_FITS_MODES[mode])
    if (fmode == 'ab+'):
        self._file.seek(0)
