示例#1
0
文件: jit.py 项目: CSRedRat/hope
def _check_state(fkt, state):
    for name in get_config_attrs():
        if name not in state or state[name] != getattr(config, name):
            raise LookupError("State is inconsistent with config. Inconsistent state key: [{0}].".format(name))
        
    if "main" not in state or "called" not in state or state["main"] != fkt.__name__:
        raise LookupError("State is inconsistent")
    
    for name, value in list((state["called"] if "called" in state else {}).items()):
        if name not in fkt.__globals__:
            #TODO: FIX! state of globals depends on the order of function in module. If called function comes later in the code we raise the error
            raise LookupError("State is inconsistent. Called function '%s' cannot be found in %s's global scope."%(name, fkt.__name__))

        glob_fkt = fkt.__globals__[name]
        if isinstance(glob_fkt, Wrapper):
            if "filename" in state and get_fkt_hash(glob_fkt.fkt) != value:
                raise LookupError("State is inconsistent. Hash(sha224) has changed")
        elif inspect.isbuiltin(glob_fkt) and hasattr(cache, str(id(glob_fkt))):
            if "filename" in state and get_fkt_hash(getattr(cache, str(id(glob_fkt)))) != value:
                raise LookupError("State is inconsistent. Hash(sha224) has changed")
        elif inspect.isfunction(glob_fkt):
            if "filename" in state and get_fkt_hash(glob_fkt) != value:
                raise LookupError("State is inconsistent. Hash(sha224) of called function '%s' has changed"%name)
        elif "filename" in state:
            raise LookupError("State is inconsistent.")
示例#2
0
文件: test_jit.py 项目: CSRedRat/hope
 def config_state(self):
     state = {}
     for name in _wrapper.get_config_attrs():
         state[name] = getattr(hope.config, name)
         
     state["filename"] = "filename"
     return state
示例#3
0
文件: test_jit.py 项目: sthagen/hope
 def config_state(self):
     state = {}
     for name in _wrapper.get_config_attrs():
         state[name] = getattr(hope.config, name)
         
     state["filename"] = "filename"
     return state
示例#4
0
文件: jit.py 项目: sthagen/hope
def _check_state(fkt, state):
    for name in get_config_attrs():
        if name not in state or state[name] != getattr(config, name):
            raise LookupError(
                "State is inconsistent with config. Inconsistent state key: [{0}]."
                .format(name))

    if "main" not in state or "called" not in state or state[
            "main"] != fkt.__name__:
        raise LookupError("State is inconsistent")

    for name, value in list(
        (state["called"] if "called" in state else {}).items()):
        if name not in fkt.__globals__:
            #TODO: FIX! state of globals depends on the order of function in module. If called function comes later in the code we raise the error
            raise LookupError(
                "State is inconsistent. Called function '%s' cannot be found in %s's global scope."
                % (name, fkt.__name__))

        glob_fkt = fkt.__globals__[name]
        if isinstance(glob_fkt, Wrapper):
            if "filename" in state and get_fkt_hash(glob_fkt.fkt) != value:
                raise LookupError(
                    "State is inconsistent. Hash(sha224) has changed")
        elif inspect.isbuiltin(glob_fkt) and hasattr(cache, str(id(glob_fkt))):
            if "filename" in state and get_fkt_hash(
                    getattr(cache, str(id(glob_fkt)))) != value:
                raise LookupError(
                    "State is inconsistent. Hash(sha224) has changed")
        elif inspect.isfunction(glob_fkt):
            if "filename" in state and get_fkt_hash(glob_fkt) != value:
                raise LookupError(
                    "State is inconsistent. Hash(sha224) of called function '%s' has changed"
                    % name)
        elif "filename" in state:
            raise LookupError("State is inconsistent.")