Example #1
0
File: jit.py Project: 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.")
Example #2
0
 def config_state(self):
     state = {}
     for name in _wrapper.get_config_attrs():
         state[name] = getattr(hope.config, name)
         
     state["filename"] = "filename"
     return state
Example #3
0
 def config_state(self):
     state = {}
     for name in _wrapper.get_config_attrs():
         state[name] = getattr(hope.config, name)
         
     state["filename"] = "filename"
     return state
Example #4
0
File: jit.py Project: 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.")