예제 #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.")