Пример #1
0
    def compile(self, song_func, text_formatter=None):
        tags = []
        queries = {}
        content = ["def f(s):", "  x = s." + song_func, "  r = []", "  a = r.append"]
        content.extend(self.__tag(self.__root, {}, {}, tags, queries, text_formatter))
        content.append("  return r")
        code = "\n".join(content)

        scope = dict(itervalues(queries))
        if text_formatter:
            scope["_format"] = text_formatter
        exec_(compile(code, "<string>", "exec"), scope)
        return scope["f"], tags
Пример #2
0
    def compile(self, song_func):
        tags = []
        queries = {}
        content = [
            "def f(s):", "  x = s." + song_func, "  r = []", "  a = r.append"
        ]
        content.extend(self.__tag(self.__root, {}, {}, tags, queries))
        content.append("  return r")
        code = "\n".join(content)

        scope = dict(itervalues(queries))
        exec_(compile(code, "<string>", "exec"), scope)
        return scope["f"], tags
Пример #3
0
    def __run(self, command):
        sys.stdout, self.stdout = self.stdout, sys.stdout
        sys.stderr, self.stderr = self.stderr, sys.stderr

        try:
            try:
                r = eval(command, self.namespace, self.namespace)
                if r is not None:
                    print_(repr(r))
            except SyntaxError:
                exec_(command, self.namespace)
        except:
            if hasattr(sys, 'last_type') and sys.last_type == SystemExit:
                self.destroy()
            else:
                traceback.print_exc()

        sys.stdout, self.stdout = self.stdout, sys.stdout
        sys.stderr, self.stderr = self.stderr, sys.stderr
Пример #4
0
    def __run(self, command):
        sys.stdout, self.stdout = self.stdout, sys.stdout
        sys.stderr, self.stderr = self.stderr, sys.stderr

        try:
            try:
                r = eval(command, self.namespace, self.namespace)
                if r is not None:
                    print_(repr(r))
            except SyntaxError:
                exec_(command, self.namespace)
        except:
            if hasattr(sys, "last_type") and sys.last_type == SystemExit:
                self.destroy()
            else:
                traceback.print_exc()

        sys.stdout, self.stdout = self.stdout, sys.stdout
        sys.stderr, self.stderr = self.stderr, sys.stderr