def PyException_GetContext(space, w_exc):
    """Return the context (another exception instance during whose handling ex was
    raised) associated with the exception as a new reference, as accessible from
    Python through __context__.  If there is no context associated, this
    returns NULL."""
    w_ctx = space.getattr(w_exc, space.wrap('__context__'))
    if space.is_none(w_ctx):
        return None
    return w_ctx