Commit 983f4205 authored by Igor Dejanovic's avatar Igor Dejanovic

Fixing PEP8 violation in export.py

parent 297eea71
......@@ -10,6 +10,7 @@
import StringIO
from arpeggio import Terminal
class Export(object):
'''
Base class for all Exporters.
......@@ -19,14 +20,15 @@ class Export(object):
super(Export, self).__init__()
# Export initialization
self._render_set = set() # Used in rendering to prevent rendering
self._render_set = set() # Used in rendering to prevent
# rendering
# of the same node multiple times
self._adapter_map = {} # Used as a registry of adapters to ensure
self._adapter_map = {} # Used as a registry of adapters to
# ensure
# ensure that the same adapter is
# returned for the same adaptee object
def export(self, obj):
'''Export of obj to a string.'''
self._outf = StringIO()
......@@ -46,16 +48,17 @@ class Export(object):
def _start(self):
'''
Overide this to specify the begining of the graph representation.
Override this to specify the beginning of the graph representation.
'''
return ""
def _end(self):
'''
Overide this to specify the end of the graph representation.
Override this to specify the end of the graph representation.
'''
return ""
class ExportAdapter(object):
'''
Base adapter class for the export support.
......@@ -73,6 +76,7 @@ class ExportAdapter(object):
# -------------------------------------------------------------------------
# Support for DOT language
class DOTExportAdapter(ExportAdapter):
'''
Base adapter class for the DOT export support.
......@@ -109,18 +113,25 @@ class PMDOTExportAdapter(DOTExportAdapter):
def children(self):
if not hasattr(self, "_children"):
self._children = []
adapter_map = self.export._adapter_map # Registry of adapters used in this export
for c,n in enumerate(self.adaptee.nodes):
if isinstance(n, PMDOTExportAdapter): # if child node is already adapted use that adapter
self._children.append((str(c+1), n))
elif adapter_map.has_key(id(n)): # current node is adaptee -> there is registered adapter
self._children.append((str(c+1), adapter_map[id(n)]))
# Registry of adapters used in this export
adapter_map = self.export._adapter_map
for c, n in enumerate(self.adaptee.nodes):
if isinstance(n, PMDOTExportAdapter):
# if child node is already adapted use that adapter
self._children.append((str(c + 1), n))
elif id(n) in adapter_map:
# current node is adaptee -> there is registered adapter
self._children.append((str(c + 1), adapter_map[id(n)]))
else:
adapter = PMDOTExportAdapter(n, self.export)
self._children.append((str(c+1), adapter))
self._children.append((str(c + 1), adapter))
adapter_map[adapter.id] = adapter
return self._children
class PTDOTExportAdapter(PMDOTExportAdapter):
'''
Adapter for ParseTreeNode graph types.
......@@ -132,11 +143,12 @@ class PTDOTExportAdapter(PMDOTExportAdapter):
else:
if not hasattr(self, "_children"):
self._children = []
for c,n in enumerate(self.adaptee.nodes):
for c, n in enumerate(self.adaptee.nodes):
adapter = PTDOTExportAdapter(n, self.export)
self._children.append((str(c+1), adapter))
self._children.append((str(c + 1), adapter))
return self._children
class DOTExport(Export):
'''
Export to DOT language (part of GraphViz, see http://www.graphviz.org/)
......@@ -144,13 +156,16 @@ class DOTExport(Export):
def _render_node(self, node):
if not node in self._render_set:
self._render_set.add(node)
self._outf.write('\n%s [label="%s"];' % (node.id, self._dot_label_esc(node.desc)))
self._outf.write('\n%s [label="%s"];' %
(node.id, self._dot_label_esc(node.desc)))
#TODO Comment handling
# if hasattr(node, "comments") and root.comments:
# retval += self.node(root.comments)
# retval += '\n%s->%s [label="comment"]' % (id(root), id(root.comments))
# retval += '\n%s->%s [label="comment"]' % \
#(id(root), id(root.comments))
for name, n in node.children:
self._outf.write('\n%s->%s [label="%s"]' % (node.id, n.id, name))
self._outf.write('\n%s->%s [label="%s"]' %
(node.id, n.id, name))
self._outf.write('\n')
self._render_node(n)
......@@ -191,4 +206,3 @@ class PTDOTExport(DOTExport):
def exportFile(self, obj, file_name):
return super(PTDOTExport, self).\
exportFile(PTDOTExportAdapter(obj, self), file_name)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment