예제 #1
0
파일: mode.py 프로젝트: lowks/untwisted
 def drive(self, event, *args):
     """ Spreads an event """
     try:
         item = self.base[event]
     except KeyError:
         pass
     else:
         for handle, data in item[:]:
             try:
                 # We call the handle associated to event.
                 # if it returns an iterator we just chain it.
                 seq = handle(self, *(args + data))
                 # In case of not having an iterator we go on
                 # processing.
                 if not seq:
                     continue
                 # It chains the iterator.
                 point = next(seq)
                 point(self, seq)
             # It stops processing handles linked to event.
             except Stop:
                 break
             # It stops all the sequence of events.
             except Kill, Root:
                 raise
             except StopIteration:
                 pass
             # It prints the exception.
             except Exception:
                 debug()
예제 #2
0
def exc(data, env):
    """
    This function is used to execute python code and it sets 
    the sys.stderr to sys.stdout so exceptions would be printed on sys.stdout. 
    After the code being executed then sys.stderr is restored to its 
    default value.

    The data argument is python code to be executed and env is a dictionary where
    the code will be executed.

    Note: It is mostly used to execute python code from vy.
    """

    import sys
    # It has to be set before because
    # if some data code catches an exception
    # then prints use print_exc it will go to
    # sys.__stderr__.

    tmp = sys.stderr
    sys.stderr = sys.stdout

    try:

        exec(data, env)
    except Exception:
        debug()
    finally:
        sys.stderr = tmp
예제 #3
0
    def drive(self, event, *args):
        """ It evaluates all callbacks linked to event """

        for signal, handle in self.base.keys():
            ################
            if signal == event:
                try:
                    old_args = self.base[signal, handle] 
                except KeyError:
                    continue
                new_args = glue(args, old_args)

                try:
                    #it evaluates handle
                    seq = handle(*new_args)

                    if seq:
                        chain(self, seq)        
                except Exception as excpt:
                    debug()

                    #it stops processing event
                    if isinstance(excpt, Stop):
                        break
                    elif isinstance(excpt, Kill):
                        raise excpt

             ################

        self.default(event, *args)
예제 #4
0
def execute(handle, *args, **kwargs):
    """

    """
    try:
        val = handle(*args, **kwargs)
    except Exception:
        debug()
    else:
        return val
예제 #5
0
파일: tools.py 프로젝트: joodicator/vy
def execute(handle, *args, **kwargs):
    """

    """
    try:
        val = handle(*args, **kwargs)
    except Exception:
        debug()
    else:
        return val
예제 #6
0
파일: cmd.py 프로젝트: curiousTauseef/vy
    def runcode(self, data, env):
        # It has to be set before because if some data code catches
        # an exception then prints use print_exc it will go to sys.__stderr__.
        tmp = sys.stderr
        sys.stderr = sys.stdout

        try:
            exec(data, env)
        except Exception as e:
            debug()
            root.status.set_msg('Error: %s' % e)
        finally:
            sys.stderr = tmp
예제 #7
0
    def get_data(self, spin, data):
        """

        """

        try:
            self.fd.write(data)
        except Exception:
            zmap(spin, LOAD, self.get_data)
            debug()

        is_done = self.check_data_size()

        if is_done:
            zmap(spin, LOAD, self.get_data)
예제 #8
0
    def wait_for_data(self):
        try:
            self.fd = tmpfile('a+')
        except Exception:
            debug()
            return

        try:
            self.fd.write(self.data)
        except Exception:
            debug()
            return

        is_done = self.check_data_size()

        if is_done:
            return

        xmap(self.spin, LOAD, self.get_data)
예제 #9
0
def exc(data, env):
    """

    """
    import sys
    # It has to be set before because
    # if some data code catches an exception
    # then prints use print_exc it will go to
    # sys.__stderr__.

    tmp = sys.stderr
    sys.stderr = sys.stdout

    try:

        exec(data, env)
    except Exception:
        debug()
    finally:
        sys.stderr = tmp
예제 #10
0
파일: tools.py 프로젝트: joodicator/vy
def exc(data, env):
    """

    """
    import sys
    # It has to be set before because
    # if some data code catches an exception
    # then prints use print_exc it will go to
    # sys.__stderr__.

    tmp        = sys.stderr
    sys.stderr = sys.stdout

    try:
    
        exec(data, env)
    except Exception:
        debug()
    finally:
        sys.stderr = tmp
예제 #11
0
def execute(handle, *args, **kwargs):
    """
    It executes handle and avoids throwing a exception but it prints the exception.

    Example:

    def func(a, b):
        return a/b

    # It wouldnt throw an exception.
    r = execute(func, 1, 0)

    # It would print None.
    print r

    """

    try:
        val = handle(*args, **kwargs)
    except Exception:
        debug()
    else:
        return val
예제 #12
0
파일: tools.py 프로젝트: zhangshiguang/vy
 def wrapper(*args, **kwargs):
     try:
         handle(*args, **kwargs)
     except Exception:
         debug()
     return 'break'