コード例 #1
0
ファイル: statement.py プロジェクト: smurfix/HomEvenT
	def run(self,ctx,**k):
		if self.procs is None:
			raise SyntaxError("This can only be used as a complex statement")
		for proc in self.procs:
			res = proc.run(ctx)
			if isinstance(res,defer.Deferred):
				waitForDeferred(res)
			global _sleep
			_sleep += 1
			if _sleep > 100:
				_sleep = 0
				gevent.sleep(0) # give other tasks a chance
コード例 #2
0
ファイル: io.py プロジェクト: smurfix/HomEvenT
	def loseConnection(self):
		try:
			lc = super(Outputter,self).loseConnection
		except AttributeError:
			if self.transport:
				self.transport.loseConnection()
		else:
			lc()

		cb = self._drop_callbacks
		self._drop_callbacks = {}

		for proc,a,k in cb.itervalues():
			res = proc(*a,**k)
			if isinstance(res,defer.Deferred):
				waitForDeferred(res)
コード例 #3
0
ファイル: parser.py プロジェクト: smurfix/HomEvenT
    def _do_parse(self, t, txt, beg, end, line):
        # States: 0 newline, 1 after first word, 2 OK to extend word
        #         3+4 need newline+indent after sub-level start, 5 extending word
        # log("parser",TRACE,"PARSE",t,repr(txt))

        try:
            res = self._parseStep(t, txt, beg, end, line)
            if isinstance(res, defer.Deferred):
                waitForDeferred(res)

        except StopIteration:
            return

        except Exception as ex:
            fix_exception(ex)
            if self.p_stack:
                self.proc = self.p_stack[0]

            self.proc.error(self, ex)
            self.prompt()
コード例 #4
0
ファイル: parser.py プロジェクト: smurfix/HomEvenT
    def _parseStep(self, t, txt, beg, end, line):
        from token import NUMBER, NAME, DEDENT, INDENT, OP, NEWLINE, ENDMARKER, STRING
        from homevent.tokize import COMMENT, NL

        self.last_pos = beg

        if "logger" in self.ctx:
            self.ctx.logger("T", self.p_state, t, repr(txt), beg, end, repr(line))
        if t == COMMENT:
            return
        if self.p_state == 0:  # begin of statement
            if t == NAME:
                self.p_args = [txt]
                self.p_state = 1
                return
            elif t == DEDENT:
                self.proc.done()
                if self.p_stack:
                    self.proc = self.p_stack.pop()
                    return
                else:
                    raise StopIteration
            elif t == ENDMARKER:
                self.proc.done()
                while self.p_stack:
                    self.proc = self.p_stack.pop()
                    self.proc.done()
                raise StopIteration
            elif t in (NL, NEWLINE):
                self.prompt()
                return
            elif t == OP and txt == ".":
                return  # "I am done"
        elif self.p_state in (1, 2):  # after first word
            if t == NAME:
                self.p_args.append(txt)
                self.p_state = 2
                return
            elif t == OP and txt in ("*", "+", "-"):
                self.p_args.append(txt)
                self.p_state = 1
                return
            elif t == NUMBER:
                self.p_args.append(eval(txt, {}, {}))
                self.p_state = 1
                return
            elif t == STRING:
                self.p_args.append(eval(txt, {}, {}))
                self.p_state = 1
                return
            elif t == OP and txt[0] in ("$", "*"):
                self.p_args.append(txt)
                self.p_state = 1
                return
            elif t == OP and txt == "." and self.p_state == 2:
                self.p_state = 5
                return
            elif t == OP and txt == ":":
                log("parser", TRACE, "RUN2")
                log("parser", TRACE, self.proc.complex_statement, self.p_args)
                self.p_state = 3
                _ = waitForDeferred(self.proc.complex_statement(self.p_args))

                self.p_stack.append(self.proc)
                self.proc = _
                return
            elif t == NEWLINE:
                log("parser", TRACE, "RUN3")
                log("parser", TRACE, self.proc.simple_statement, self.p_args)
                # defer setting state to zero when pop_after is set
                # because that would break one-line compound statements
                # ("wait :for 2").
                # On the other hand, setting it later anyway breaks
                # statements which terminate the parser ("exit")
                if not self.p_pop_after:
                    self.p_state = 0
                waitForDeferred(self.proc.simple_statement(self.p_args))

                if self.p_pop_after:
                    self.proc.done()
                    self.proc = self.p_stack.pop()
                    self.p_pop_after = False
                    self.p_state = 0
                self.prompt()
                return
        elif self.p_state == 3:
            if t == NEWLINE:
                self.p_state = 4
                self.prompt()
                return
            elif t == NAME:
                self.p_args = [txt]
                self.p_state = 1
                self.p_pop_after = True
                return
            else:
                self.proc = self.p_stack.pop()
        elif self.p_state == 4:
            if t == INDENT:
                self.p_state = 0
                return
            elif t == NEWLINE:
                # ignore
                return
            else:
                self.proc = self.p_stack.pop()
        elif self.p_state == 5:
            if t == NAME:
                self.p_args[-1] += "." + txt
                self.p_state = 2
                return

        if self.p_pop_after:
            self.proc = self.p_stack.pop()
            self.p_pop_after = False

        raise SyntaxError(
            "Unknown token %s (%s, state %d) in %s:%d"
            % (repr(txt), tok_name[t] if t in tok_name else t, self.p_state, self.ctx.filename, beg[0])
        )
コード例 #5
0
ファイル: io.py プロジェクト: smurfix/HomEvenT
def dropConnections():
	for c in conns:
		waitForDeferred(c.loseConnection())
コード例 #6
0
ファイル: rpc.py プロジェクト: smurfix/HomEvenT
	def simple_statement(self,args):
		fn = self.lookup(args)
		fn.parent = self.parent
		res = fn.run(self.ctx)
		res = waitForDeferred(res)
		return res
コード例 #7
0
ファイル: rpc.py プロジェクト: smurfix/HomEvenT
	def run(self):
		res = self.fn.run(self.ctx)
		return waitForDeferred(res)