(val, import_custom_exceptions, instantiate_custom_exceptions, instantiate_oldstyle_exceptions)
return exc
Loads a dumped exception (the tuple returned by :func:`dump`) info a 
    throwable exception object. If the exception cannot be instantiated for any
    reason (i.e., the security parameters do not allow it, or the exception 
    class simply doesn't exist on the local machine), a :class:`GenericException`
    instance will be returned instead, containing all of the original exception's
    details.
    
    :param val: the dumped exception
    :param import_custom_exceptions: whether to allow this function to import custom modules 
                                     (imposes a security risk)
    :param instantiate_custom_exceptions: whether to allow this function to instantiate "custom 
                                          exceptions" (i.e., not one of the built-in exceptions,
                                          such as ``ValueError``, ``OSError``, etc.)
    :param instantiate_oldstyle_exceptions: whether to allow this function to instantiate exception 
                                            classes that do not derive from ``BaseException``.
                                            This is required to support old-style exceptions. 
                                            Not applicable for Python 3 and above.
    
    :returns: A throwable exception object
Loads a dumped exception (the tuple returned by :func:`dump`) info a 
    throwable exception object. If the exception cannot be instantiated for any
    reason (i.e., the security parameters do not allow it, or the exception 
    class simply doesn't exist on the local machine), a :class:`GenericException`
    instance will be returned instead, containing all of the original exception's
    details.
    
    :param val: the dumped exception
    :param import_custom_exceptions: whether to allow this function to import custom modules 
                                     (imposes a security risk)
    :param instantiate_custom_exceptions: whether to allow this function to instantiate "custom 
                                          exceptions" (i.e., not one of the built-in exceptions,
                                          such as ``ValueError``, ``OSError``, etc.)
    :param instantiate_oldstyle_exceptions: whether to allow this function to instantiate exception 
                                            classes that do not derive from ``BaseException``.
                                            This is required to support old-style exceptions. 
                                            Not applicable for Python 3 and above.
    
    :returns: A throwable exception object
Loads a dumped exception ( the tuple returned by : func : dump ) info a throwable exception object . If the exception cannot be instantiated for any reason ( i . e . the security parameters do not allow it or the exception class simply doesn t exist on the local machine ) a : class : GenericException instance will be returned instead containing all of the original exception s details . : param val : the dumped exception : param import_custom_exceptions : whether to allow this function to import custom modules ( imposes a security risk ) : param instantiate_custom_exceptions : whether to allow this function to instantiate custom exceptions ( i . e . not one of the built - in exceptions such as ValueError OSError etc . ) : param instantiate_oldstyle_exceptions : whether to allow this function to instantiate exception classes that do not derive from BaseException . This is required to support old - style exceptions . Not applicable for Python 3 and above . : returns : A throwable exception object
def load(val, import_custom_exceptions, instantiate_custom_exceptions, instantiate_oldstyle_exceptions):
    """
    Loads a dumped exception (the tuple returned by :func:`dump`) info a 
    throwable exception object. If the exception cannot be instantiated for any
    reason (i.e., the security parameters do not allow it, or the exception 
    class simply doesn't exist on the local machine), a :class:`GenericException`
    instance will be returned instead, containing all of the original exception's
    details.
    
    :param val: the dumped exception
    :param import_custom_exceptions: whether to allow this function to import custom modules 
                                     (imposes a security risk)
    :param instantiate_custom_exceptions: whether to allow this function to instantiate "custom 
                                          exceptions" (i.e., not one of the built-in exceptions,
                                          such as ``ValueError``, ``OSError``, etc.)
    :param instantiate_oldstyle_exceptions: whether to allow this function to instantiate exception 
                                            classes that do not derive from ``BaseException``.
                                            This is required to support old-style exceptions. 
                                            Not applicable for Python 3 and above.
    
    :returns: A throwable exception object
    """
    if val == consts.EXC_STOP_ITERATION:
        return StopIteration # optimization
    if type(val) is str:
        return val # deprecated string exceptions

    (modname, clsname), args, attrs, tbtext = val
    if import_custom_exceptions and modname not in sys.modules:
        try:
            __import__(modname, None, None, "*")
        except Exception:
            pass
    
    if instantiate_custom_exceptions:
        if modname in sys.modules:
            cls = getattr(sys.modules[modname], clsname, None)
        else:
            cls = None
    elif modname == exceptions_module.__name__:
        cls = getattr(exceptions_module, clsname, None)
    else:
        cls = None

    if is_py3k:
        if not isinstance(cls, type) or not issubclass(cls, BaseException):
            cls = None
    else:
        if not isinstance(cls, (type, ClassType)):
            cls = None
        elif issubclass(cls, ClassType) and not instantiate_oldstyle_exceptions:
            cls = None
        elif not issubclass(cls, BaseException):
            cls = None

    if cls is None:
        fullname = "%s.%s" % (modname, clsname)
        if fullname not in _generic_exceptions_cache:
            fakemodule = {"__module__" : "%s/%s" % (__name__, modname)}
            if isinstance(GenericException, ClassType):
                _generic_exceptions_cache[fullname] = ClassType(fullname, (GenericException,), fakemodule)
            else:
                _generic_exceptions_cache[fullname] = type(fullname, (GenericException,), fakemodule)
        cls = _generic_exceptions_cache[fullname]

    cls = _get_exception_class(cls)
    
    # support old-style exception classes
    if ClassType is not type and isinstance(cls, ClassType):
        exc = InstanceType(cls)
    else:
        exc = cls.__new__(cls)

    exc.args = args
    for name, attrval in attrs:
        setattr(exc, name, attrval)
    exc._remote_tb = tbtext
    return exc
def load ( val , import_custom_exceptions , instantiate_custom_exceptions , instantiate_oldstyle_exceptions ) : if val == consts . EXC_STOP_ITERATION : return StopIteration # optimization if type ( val ) is str : return val # deprecated string exceptions ( modname , clsname ) , args , attrs , tbtext = val if import_custom_exceptions and modname not in sys . modules : try : __import__ ( modname , None , None , "*" ) except Exception : pass if instantiate_custom_exceptions : if modname in sys . modules : cls = getattr ( sys . modules [ modname ] , clsname , None ) else : cls = None elif modname == exceptions_module . __name__ : cls = getattr ( exceptions_module , clsname , None ) else : cls = None if is_py3k : if not isinstance ( cls , type ) or not issubclass ( cls , BaseException ) : cls = None else : if not isinstance ( cls , ( type , ClassType ) ) : cls = None elif issubclass ( cls , ClassType ) and not instantiate_oldstyle_exceptions : cls = None elif not issubclass ( cls , BaseException ) : cls = None if cls is None : fullname = "%s.%s" % ( modname , clsname ) if fullname not in _generic_exceptions_cache : fakemodule = { "__module__" : "%s/%s" % ( __name__ , modname ) } if isinstance ( GenericException , ClassType ) : _generic_exceptions_cache [ fullname ] = ClassType ( fullname , ( GenericException , ) , fakemodule ) else : _generic_exceptions_cache [ fullname ] = type ( fullname , ( GenericException , ) , fakemodule ) cls = _generic_exceptions_cache [ fullname ] cls = _get_exception_class ( cls ) # support old-style exception classes if ClassType is not type and isinstance ( cls , ClassType ) : exc = InstanceType ( cls ) else : exc = cls . __new__ ( cls ) exc . args = args for name , attrval in attrs : setattr ( exc , name , attrval ) exc . _remote_tb = tbtext return exc