@@ -0,0 +1,2273 @@
+import sys%0A%0Apy_reserved = set(%22id is class def%22.split())  # FIXME%0Adef py_name(name):%0A    if name in py_reserved:%0A        return name + %22_%22%0A    return name%0A%0Asdl_to_python = %7B%0A    %22int32%22: %22int%22,%0A    %22int64%22: %22int%22,%0A    %22double%22: %22float%22,%0A    %22string%22: %22basestring%22%0A%7D%0Adef py_Typename(name):%0A    return sdl_to_python.get(name, name)%0A%0Aclass Pythonize(object):%0A    %22Add py_name node attributes%22%0A%0A    def visit_DEFAULT(self, node):%0A        print %22DEFAULT%22, repr(node)%0A%0A    def visit_Module(self, node):%0A        node.py_name = py_name(node.name)%0A%0A    def visit_Struct(self, node):%0A        node.py_name = py_name(node.name)%0A%0A    def visit_Field(self, node):%0A        node.py_name = py_name(node.name)%0A%0A    def visit_Parameter(self, node):%0A        node.py_name = py_name(node.name)%0A        if node.default:%0A            if node.default.name == %22null%22:%0A                node.default.py_name = %22None%22%0A            else:%0A                node.default.py_name = repr(node.default.name)%0A%0A    def visit_Operation(self, node):%0A        node.py_name = py_name(node.name)%0A%0A    def visit_Type(self, node):%0A        node.py_name = py_Typename(node.name)%0A%0Aclass PyOutput(object):%0A    %22Generate decent-looking Python code%22%0A%0A    def __init__(self):%0A        self.lines = %5B%5D%0A        self.main_indent_level = 0%0A        self.ref_indent_level = 0%0A%0A    def out(self, line):%0A        self.lines.append(self.main_indent_level * %22    %22 + line.strip())%0A%0A    def ref(self, line):%0A        self.lines.append(%22## %22 + self.ref_indent_level * %22    %22 + line.strip())%0A%0A    def indent(self):%0A        self.main_indent_level += 1%0A%0A    def dedent(self):%0A        assert self.main_indent_level %3E 0, (self.main_indent_level, %22%5Cn%22.join(self.lines))%0A        self.main_indent_level -= 1%0A%0A    def ref_indent(self):%0A        self.ref_indent_level += 1%0A%0A    def ref_dedent(self):%0A        assert self.ref_indent_level %3E 0, (self.ref_indent_level, %22%5Cn%22.join(self.lines))%0A        self.ref_indent_level -= 1%0A%0A    def dump(self, fd=sys.stdout):%0A        # Fancy print...%0A        wasPassThru = True%0A        for line in self.lines:%0A            isPassThru = line.startswith(%22## %22)%0A            if isPassThru != wasPassThru:%0A                fd.write(%22%5Cn%22)%0A            fd.write(line)%0A            fd.write(%22%5Cn%22)%0A            wasPassThru = isPassThru%0A

Add helpers for generating Python code