<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def read_handle(url, cache=None, mode="rb"):
 """Read from any URL with a file handle. Use this to get a handle to a file rather than eagerly load the data: ``` with read_handle(url) as handle: result = something.load(handle) result.do_something() ``` When program execution leaves this `with` block, the handle will be closed automatically. Args: url: a URL including scheme or a local path Returns: A file handle to the specified resource if it could be reached. The handle will be closed automatically once execution leaves this context. """

    scheme = urlparse(url).scheme

    if cache == 'purge':
        _purge_cached(url)
        cache = None

    if _is_remote(scheme) and cache is None:
        cache = True
        log.debug("Cache not specified, enabling because resource is remote.")

    if cache:
        handle = _read_and_cache(url, mode=mode)
    else:
        if scheme in ("http", "https"):
            handle = _handle_web_url(url, mode=mode)
        elif scheme in ("gs"):
            handle = _handle_gfile(url, mode=mode)
        else:
            handle = open(url, mode=mode)

    yield handle
    handle.close()