'Open a FITS file from a file-like object, i.e. one that has
read and/or write methods.'

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

    self.file_like = True
    self._file = fileobj
    if fileobj_closed(fileobj):
        raise IOError('Cannot    read    from/write    to    a    closed    file-like    object    ({!r}).'.format(fileobj))
    if isinstance(fileobj, zipfile.ZipFile):
        self._open_zipfile(fileobj, mode)
        self._file.seek(0)
        return
    if ((not hasattr(self._file, 'seek')) or (not hasattr(self._file, 'tell'))):
        self.mode = mode = 'ostream'
    if (mode == 'ostream'):
        self._overwrite_existing(overwrite, fileobj, False)
    if ((self.mode in ('update', 'append', 'ostream')) and (not hasattr(self._file, 'write'))):
        raise IOError("File-like    object    does    not    have    a    'write'    method,    required    for    mode    '{}'.".format(self.mode))
    if ((self.mode != 'ostream') and (not hasattr(self._file, 'read'))):
        raise IOError("File-like    object    does    not    have    a    'read'    method,    required    for    mode    {!r}.".format(self.mode))
