def handle_fobj(backend, f, **kwargs):
    """
    Handle a file-like object.

    Called by `get()` when provided a file-like. This function will prefer the
    backend's `handle_fobj()` if one is provided. Otherwise, it will write the
    data to a temporary file and call `handle_path()`.
    """
    if not is_binary(f):
        raise AssertionError('File must be opened in binary mode.')

    if callable(getattr(backend, 'handle_fobj', None)):
        # Prefer handle_fobj() if present.
        LOGGER.debug("using handle_fobj")
        return backend.handle_fobj(f)

    elif callable(getattr(backend, 'handle_path', None)):
        # Fallback to handle_path(). Warn user since this is potentially
        # expensive.
        LOGGER.debug("using handle_path")
        LOGGER.warning(
            "Using disk, %r backend does not provide `handle_fobj()`", backend)

        ext = ''
        if 'ext' in kwargs:
            ext = '.' + kwargs['ext']

        with fobj_to_tempfile(f, suffix=ext) as fname:
            return backend.handle_path(fname, **kwargs)
    else:
        raise AssertionError(
            'Backend %s has no _get functions' % backend.__name__)
def handle_fobj ( backend , f , ** kwargs ) : if not is_binary ( f ) : raise AssertionError ( 'File must be opened in binary mode.' ) if callable ( getattr ( backend , 'handle_fobj' , None ) ) : LOGGER . debug ( "using handle_fobj" ) return backend . handle_fobj ( f ) elif callable ( getattr ( backend , 'handle_path' , None ) ) : LOGGER . debug ( "using handle_path" ) LOGGER . warning ( "Using disk, %r backend does not provide `handle_fobj()`" , backend ) ext = '' if 'ext' in kwargs : ext = '.' + kwargs [ 'ext' ] with fobj_to_tempfile ( f , suffix = ext ) as fname : return backend . handle_path ( fname , ** kwargs ) else : raise AssertionError ( 'Backend %s has no _get functions' % backend . __name__ )
Handle a file-like object.

    Called by `get()` when provided a file-like. This function will prefer the
    backend's `handle_fobj()` if one is provided. Otherwise, it will write the
    data to a temporary file and call `handle_path()`.