Esempio n. 1
0
    def print_if(self, ast):
        statement = First("if %s:", "elif %s:")

        for i, (condition, block) in enumerate(ast.entries):
            # The non-Unicode string "True" is the condition for else:.
            if (i + 1) == len(ast.entries) and isinstance(condition, str):
                self.indent()
                self.write("else:")
            else:
                self.advance_to_line(condition.linenumber)
                self.indent()
                self.write(statement() % condition)

            self.print_nodes(block, 1)
Esempio n. 2
0
    def _print_if(self, ast, keyword):
        # the first condition is named if or showif, the rest elif
        keyword = First(keyword, "elif")
        for condition, block in ast.entries:
            self.advance_to_line(block.location[1])
            self.indent()
            # if condition is None, this is the else clause
            if condition is None:
                self.write("else:")
            else:
                self.write("%s %s:" % (keyword(), condition))

            # Every condition has a block of type slast.SLBlock
            if block.keyword or block.children:
                self.print_block(block)
            else:
                with self.increase_indent():
                    self.indent()
                    self.write("pass")