33 from distutils.version 
import LooseVersion
 
   35     from urllib.request 
import quote
 
   37     from urllib 
import quote
 
   51         if name 
in [
'graph', 
'subgraph', 
'node', 
'edge']:
 
   58         ret = quote(name.strip())
 
   59         ret = ret.replace(
'/', 
'__')
 
   60         ret = ret.replace(
'%', 
'_')
 
   61         ret = ret.replace(
'-', 
'_')
 
   65             self, graph_type='digraph', rank='same', simplify=True,
 
   66             rankdir='TB', ranksep=0.2, compound=True):
 
   69         if LooseVersion(pydot.__version__) > LooseVersion(
'1.0.10'):
 
   70             graph = pydot.Dot(
'graphname',
 
   71                               graph_type=graph_type,
 
   76             graph.set_ranksep(ranksep)
 
   77             graph.set_compound(compound)
 
   79             graph = pydot.Dot(
'graphname',
 
   80                               graph_type=graph_type,
 
   94         Create a node item for this factory, adds it to the graph. 
   96         Node name can vary from label but must always be same for the same node label 
   98         if nodename 
is None or nodename == 
'':
 
   99             raise ValueError(
'Empty Node name')
 
  100         if nodelabel 
is None:
 
  103         node.set_shape(shape)
 
  105         if tooltip 
is not None:
 
  106             node.set_tooltip(tooltip)
 
  107         elif url 
is not None:
 
  108             node.set_tooltip(url)
 
  111         if color 
is not None:
 
  112             node.set_color(color)
 
  128         Create a cluster subgraph item for this factory, adds it to the graph. 
  130         cluster name can vary from label but must always be same for the same node label. 
  131         Most layouters require cluster names to start with cluster. 
  133         if subgraphname 
is None or subgraphname == 
'':
 
  134             raise ValueError(
'Empty subgraph name')
 
  136                           rank=rank, rankdir=rankdir, simplify=simplify)
 
  137         if 'set_style' in g.__dict__:
 
  139         if 'set_shape' in g.__dict__:
 
  141         if LooseVersion(pydot.__version__) > LooseVersion(
'1.0.10'):
 
  142             g.set_compound(compound)
 
  143             g.set_ranksep(ranksep)
 
  144         subgraphlabel = subgraphname 
if subgraphlabel 
is None else subgraphlabel
 
  147             g.set_label(subgraphlabel)
 
  148         if 'set_color' in g.__dict__:
 
  149             if color 
is not None:
 
  151         graph.add_subgraph(g)
 
  155             self, graph, nodename1, nodename2, label=None, url=None,
 
  156             simplify=True, style=None, penwidth=1, color=None):
 
  157         if simplify 
and LooseVersion(pydot.__version__) < LooseVersion(
'1.0.10'):
 
  161         if label 
is not None and label != 
'':
 
  162             edge.set_label(label)
 
  165         if style 
is not None:
 
  166             edge.set_style(style)
 
  167         edge.obj_dict[
'attributes'][
'penwidth'] = str(penwidth)
 
  168         if color 
is not None:
 
  169             edge.obj_dict[
'attributes'][
'colorR'] = str(color[0])
 
  170             edge.obj_dict[
'attributes'][
'colorG'] = str(color[1])
 
  171             edge.obj_dict[
'attributes'][
'colorB'] = str(color[2])
 
  175         dot = graph.create_dot()
 
  179         return dot.replace(
'\\%s' % os.linesep, 
'').replace(
'\\\n', 
'')