Source code for ctree.py.dotgen

"""
Support for Python ast nodes in the 'ast' module.
"""

import ast

# ---------------------------------------------------------------------------
# dot generator

from ctree.dotgen import DotGenLabeller


[docs]class PyDotLabeller(DotGenLabeller): """ Manages generation of DOT. """
[docs] def visit_arg(self, node): s = "name: %s" % node.arg if node.annotation and not isinstance(node.annotation, ast.AST): s += "\nannotation: %s" % self._qualified_name(node.annotation) return s
[docs] def visit_FunctionDef(self, node): return "name: %s" % node.name
[docs] def visit_Num(self, node): return "n: %s" % node.n
[docs] def visit_Name(self, node): return "id: %s" % node.id
[docs] def visit_Attribute(self, node): return "attr: %s" % node.attr
[docs] def visit_Str(self, node): return "str: %s" % node.s