资源简介
GraphViz和DOT语言的Python界面。
这个软件包包含一个GraphViz的接口,用于表示图形并将它们转储为DOT语言的类[2],以及来自DOT的解析器。
代码片段和文件信息
# -*- coding: Latin-1 -*-
“““Graphviz‘s dot language parser.
The dotparser parses graphviz files in dot and dot files and transforms them
into a class representation defined by pydot.
The module needs pyparsing (tested with version 1.2.2) and pydot
Author: Michael Krause
Fixes by: Ero Carrera
“““
__author__ = [‘Michael Krause‘ ‘Ero Carrera‘]
__license__ = ‘MIT‘
import sys
import glob
import pydot
import re
import codecs
from pyparsing import __version__ as pyparsing_version
from pyparsing import ( nestedExpr Literal CaselessLiteral Word OneOrMore ZeroOrMore
Forward NotAny delimitedList oneOf Group Optional Combine alphas nums
restOfLine cstyleComment nums alphanums printables empty quotedString
ParseException ParseResults CharsNotIn dblQuotedString QuotedString ParserElement )
class P_AttrList:
def __init__(self toks):
self.attrs = {}
i = 0
while i < len(toks):
attrname = toks[i]
if i+2 < len(toks) and toks[i+1] == ‘=‘:
attrvalue = toks[i+2]
i += 3
else:
attrvalue = None
i += 1
self.attrs[attrname] = attrvalue
def __repr__(self):
return “%s(%r)“ % (self.__class__.__name__ self.attrs)
class DefaultStatement(P_AttrList):
def __init__(self default_type attrs):
self.default_type = default_type
self.attrs = attrs
def __repr__(self):
return “%s(%s %r)“ % (self.__class__.__name__
self.default_type self.attrs)
top_graphs = list()
def push_top_graph_stmt(str loc toks):
attrs = {}
g = None
for element in toks:
if( isinstance(element (ParseResults tuple list)) and
len(element) == 1 and isinstance(element[0] basestring) ):
element = element[0]
if element == ‘strict‘:
attrs[‘strict‘] = True
elif element in [‘graph‘ ‘digraph‘]:
attrs = {}
g = pydot.Dot(graph_type=element **attrs)
attrs[‘type‘] = element
top_graphs.append( g )
elif isinstance( element basestring):
g.set_name( element )
elif isinstance(element pydot.Subgraph):
g.obj_dict[‘attributes‘].update( element.obj_dict[‘attributes‘] )
g.obj_dict[‘edges‘].update( element.obj_dict[‘edges‘] )
g.obj_dict[‘nodes‘].update( element.obj_dict[‘nodes‘] )
g.obj_dict[‘subgraphs‘].update( element.obj_dict[‘subgraphs‘] )
g.set_parent_graph(g)
elif isinstance(element P_AttrList):
attrs.update(element.attrs)
elif isinstance(element (ParseResults list)):
add_elements(g element)
else:
raise ValueError “Unknown element statement: %r “ % element
for g in top_graphs:
update_parent_graph_hierarchy(g)
if le
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2016-05-24 01:32 pydot-1.1.0\
文件 90 2016-05-24 01:32 pydot-1.1.0\.gitattributes
文件 170 2016-05-24 01:32 pydot-1.1.0\.gitignore
文件 1861 2016-05-24 01:32 pydot-1.1.0\ChangeLog
文件 1125 2016-05-24 01:32 pydot-1.1.0\LICENSE
文件 50 2016-05-24 01:32 pydot-1.1.0\MANIFEST.in
文件 639 2016-05-24 01:32 pydot-1.1.0\README
文件 14396 2016-05-24 01:32 pydot-1.1.0\dot_parser.py
文件 57526 2016-05-24 01:32 pydot-1.1.0\pydot.py
文件 1191 2016-05-24 01:32 pydot-1.1.0\setup.py
目录 0 2016-05-24 01:32 pydot-1.1.0\test\
目录 0 2016-05-24 01:32 pydot-1.1.0\test\from-past-to-future\
文件 3998 2016-05-24 01:32 pydot-1.1.0\test\from-past-to-future\AI.png
文件 8305 2016-05-24 01:32 pydot-1.1.0\test\from-past-to-future\Agents.png
文件 5007 2016-05-24 01:32 pydot-1.1.0\test\from-past-to-future\Automata.png
文件 8899 2016-05-24 01:32 pydot-1.1.0\test\from-past-to-future\Berners_Lee.png
文件 11775 2016-05-24 01:32 pydot-1.1.0\test\from-past-to-future\Biology.png
文件 4830 2016-05-24 01:32 pydot-1.1.0\test\from-past-to-future\Chaos.png
文件 10328 2016-05-24 01:32 pydot-1.1.0\test\from-past-to-future\Computers.png
文件 19732 2016-05-24 01:32 pydot-1.1.0\test\from-past-to-future\Cryptography.png
文件 5729 2016-05-24 01:32 pydot-1.1.0\test\from-past-to-future\Dertouzos.png
文件 7796 2016-05-24 01:32 pydot-1.1.0\test\from-past-to-future\Ontology.png
文件 6493 2016-05-24 01:32 pydot-1.1.0\test\from-past-to-future\Rejewski.png
文件 5832 2016-05-24 01:32 pydot-1.1.0\test\from-past-to-future\Search_Engines.png
文件 2995 2016-05-24 01:32 pydot-1.1.0\test\from-past-to-future\Semantic_Web.png
文件 3370 2016-05-24 01:32 pydot-1.1.0\test\from-past-to-future\Small_World.png
文件 7481 2016-05-24 01:32 pydot-1.1.0\test\from-past-to-future\Social_Networks.png
文件 10235 2016-05-24 01:32 pydot-1.1.0\test\from-past-to-future\Turing.png
文件 3905 2016-05-24 01:32 pydot-1.1.0\test\from-past-to-future\xm
文件 4666 2016-05-24 01:32 pydot-1.1.0\test\from-past-to-future\from-past-to-future.dot
目录 0 2016-05-24 01:32 pydot-1.1.0\test\graphs\
............此处省略208个文件信息
评论
共有 条评论