σ —ΐv]c@s‡dZddlmZmZddgZdejfd„ƒYZdefd„ƒYZdefd „ƒYZ defd „ƒYZ d S( sγAssemble DOT source code objects. >>> dot = Graph(comment=u'M\xf8nti Pyth\xf8n ik den H\xf8lie Grailen') >>> dot.node(u'M\xf8\xf8se') >>> dot.node('trained_by', u'trained by') >>> dot.node('tutte', u'TUTTE HERMSGERVORDENBROTBORDA') >>> dot.edge(u'M\xf8\xf8se', 'trained_by') >>> dot.edge('trained_by', 'tutte') >>> dot.node_attr['shape'] = 'rectangle' >>> print(dot.source.replace(u'\xf8', '0')) #doctest: +NORMALIZE_WHITESPACE // M0nti Pyth0n ik den H0lie Grailen graph { node [shape=rectangle] "M00se" trained_by [label="trained by"] tutte [label="TUTTE HERMSGERVORDENBROTBORDA"] "M00se" -- trained_by trained_by -- tutte } >>> dot.view('test-output/m00se.gv') # doctest: +SKIP 'test-output/m00se.gv.pdf' i(tlangtfilestGraphtDigraphtDotc Bs<eZdZdZdZdZdZZedZdZ e e j ƒZ e e jƒZe e jƒZe e jƒZddddddejjdddded„ Zd „Zed „Zed „Zd „Zeed ejƒZddd„Z ddd„Z!d„Z"ddd„Z#dddddddd„Z$RS(sBAssemble, save, and render DOT source code, open result in viewer.s// %ss subgraph %s{s%s{s %s%ss%stt}c CsΕ||_||_tt|ƒj|||||ƒ|dk rLt|ƒni|_| dk rmt| ƒni|_| dk rŽt| ƒni|_ | dk r―t | ƒng|_ | |_ dS(N( tnametcommenttsuperRt__init__tNonetdictt graph_attrt node_attrt edge_attrtlisttbodytstrict( tselfRRtfilenamet directorytformattenginetencodingR RRRR((s0/tmp/pip-install-Qvdv_2/graphviz/graphviz/dot.pyR 4s  "!!!!cCs„tt|ƒjƒ}|ji|jd6|jd6t|jƒd6t|jƒd6t|j ƒd6t |j ƒd6|j d6ƒ|S(NRRR RRRR( R Rt_kwargstupdateRRR R RRRRR(Rtresult((s0/tmp/pip-install-Qvdv_2/graphviz/graphviz/dot.pyRGs cCsA|s6x-|j|j|jfD]}|jƒqWn|j2dS(s’Reset content to an empty body, clear graph/node/egde_attr mappings. Args: keep_attrs (bool): preserve graph/node/egde_attr mappings N(R RRtclearR(Rt keep_attrsta((s0/tmp/pip-install-Qvdv_2/graphviz/graphviz/dot.pyRRsccs |jr|j|jVn|rW|jr9tdƒ‚n|jrK|jn|j}n|jri|jn|j}||jr”|j |jƒdndVxHd D]@}t |d|ƒ}|r‘|j ||j d|ƒfVq‘q‘Wx|jD] }|VqοW|jVdS( s>Yield the DOT source code line by line (as graph or subgraph).ssubgraphs cannot be strictt Rtgraphtnodetedges%s_attrN(R R!R"(Rt_commentRt ValueErrorRt _subgrapht_subgraph_plaint _head_strictt_headt_quotetgetattrt_attrt _attr_listR Rt_tail(Rtsubgraphtheadtkwtattrstline((s0/tmp/pip-install-Qvdv_2/graphviz/graphviz/dot.pyt__iter__]s  ( % cCs dj|ƒS(sThe DOT source code as string.s (tjoin(R((s0/tmp/pip-install-Qvdv_2/graphviz/graphviz/dot.pyt__str__tstdoccKsK|j|ƒ}|j|||ƒ}|j||f}|jj|ƒdS(sϋCreate a node. Args: name: Unique identifier for the node inside the source. label: Caption to be displayed (defaults to the node ``name``). attrs: Any additional node attributes (must be strings). N(R)R,t_nodeRtappend(RRtlabelt _attributesR1t attr_listR2((s0/tmp/pip-install-Qvdv_2/graphviz/graphviz/dot.pyR!zscKs]|j|ƒ}|j|ƒ}|j|||ƒ}|j|||f}|jj|ƒdS(sCreate an edge between two nodes. Args: tail_name: Start node identifier. head_name: End node identifier. label: Caption to be displayed near the edge. attrs: Any additional edge attributes (must be strings). N(t _quote_edgeR,t_edgeRR8(Rt tail_namet head_nameR9R:R1R;R2((s0/tmp/pip-install-Qvdv_2/graphviz/graphviz/dot.pyR"‡s cs?|j‰|j‰‡‡fd†|Dƒ}|jj|ƒdS(szCreate a bunch of edges. Args: tail_head_iter: Iterable of ``(tail_name, head_name)`` pairs. c3s1|]'\}}ˆˆ|ƒˆ|ƒfVqdS(N((t.0ttth(R"tquote(s0/tmp/pip-install-Qvdv_2/graphviz/graphviz/dot.pys žsN(t _edge_plainR<Rtextend(Rttail_head_itertlines((R"RCs0/tmp/pip-install-Qvdv_2/graphviz/graphviz/dot.pytedges–s  cKs­|dk r1|jƒdkr1td|ƒ‚n|s=|r©|dkrn|jd||ƒ}|j|}n(|jd||ƒ}|j||f}|jj|ƒndS(s2Add a general or graph/node/edge attribute statement. Args: kw: Attributes target (``None`` or ``'graph'``, ``'node'``, ``'edge'``). attrs: Attributes to be set (must be strings, may be empty). See the :ref:`usage examples in the User Guide `. R R!R"s3attr statement must target graph, node, or edge: %rN(R R!R"( R tlowerR$t_a_listt _attr_plainR,R+RR8(RR0R:R1ta_listR2R;((s0/tmp/pip-install-Qvdv_2/graphviz/graphviz/dot.pytattr‘s    c Csξ|d krIi|d6|d6|d6|d6|d6|d6}t||ƒS||||||g} td„| Dƒƒs†tdƒ‚n|j|jkr±td ||fƒ‚ng|jd tƒD]} d | ^qΔ} |jj| ƒd S( s­Add the current content of the given sole ``graph`` argument as subgraph or return a context manager returning a new graph instance created with the given (``name``, ``comment``, etc.) arguments whose content is added as subgraph when leaving the context manager's ``with``-block. Args: graph: An instance of the same kind (:class:`.Graph`, :class:`.Digraph`) as the current graph (sole argument in non-with-block use). name: Subgraph name (``with``-block use). comment: Subgraph comment (``with``-block use). graph_attr: Subgraph-level attribute-value mapping (``with``-block use). node_attr: Node-level attribute-value mapping (``with``-block use). edge_attr: Edge-level attribute-value mapping (``with``-block use). body: Verbatim lines to add to the subgraph ``body`` (``with``-block use). See the :ref:`usage examples in the User Guide `. .. note:: If the ``name`` of the subgraph begins with ``'cluster'`` (all lowercase) the layout engine will treat it as a special cluster subgraph. RRR RRRcss|]}|dkVqdS(N(R (R@R((s0/tmp/pip-install-Qvdv_2/graphviz/graphviz/dot.pys Τss)graph must be sole argument of subgraph()s-%r cannot add subgraph of different kind: %r R.s N( R tSubgraphContexttallR$tdirectedR3tTrueRRE( RR RRR RRRtkwargstargsR2RG((s0/tmp/pip-install-Qvdv_2/graphviz/graphviz/dot.pyR.Άs  )(s%sRN(%t__name__t __module__t__doc__R#R%R&R7R+RKR-t staticmethodRRCR)t quote_edgeR<RLRJR;R,R RtFilet _encodingtFalseR RRR3R5tpropertytsourceR!R"RHRMR.(((s0/tmp/pip-install-Qvdv_2/graphviz/graphviz/dot.pyR$s6         RNcBs)eZdZd„Zd„Zd„ZRS(sBReturn a blank instance of the parent and add as subgraph on exit.cCs||_|j||_dS(N(tparentt __class__R (RR^RR((s0/tmp/pip-install-Qvdv_2/graphviz/graphviz/dot.pyR ΰs cCs|jS(N(R (R((s0/tmp/pip-install-Qvdv_2/graphviz/graphviz/dot.pyt __enter__δscCs&|dkr"|jj|jƒndS(N(R R^R.R (Rttype_tvaluet traceback((s0/tmp/pip-install-Qvdv_2/graphviz/graphviz/dot.pyt__exit__ηs (RTRURVR R`Rd(((s0/tmp/pip-install-Qvdv_2/graphviz/graphviz/dot.pyRNέs  cBs=eZdZdZdeZdZedZed„ƒZRS(sοGraph source code in the DOT language. Args: name: Graph name used in the source code. comment: Comment added to the first line of the source. filename: Filename for saving the source (defaults to ``name`` + ``'.gv'``). directory: (Sub)directory for source saving and rendering. format: Rendering output format (``'pdf'``, ``'png'``, ...). engine: Layout command used (``'dot'``, ``'neato'``, ...). encoding: Encoding for saving the source. graph_attr: Mapping of ``(attribute, value)`` pairs for the graph. node_attr: Mapping of ``(attribute, value)`` pairs set for all nodes. edge_attr: Mapping of ``(attribute, value)`` pairs set for all edges. body: Iterable of verbatim lines to add to the graph ``body``. strict (bool): Rendering should merge multi-edges. Note: All parameters are optional and can be changed under their corresponding attribute name after instance creation. s graph %s{s strict %ss %s -- %s%ss%sRcCstS(s ``False``(R[(R((s0/tmp/pip-install-Qvdv_2/graphviz/graphviz/dot.pyRPs(s%ss%sR( RTRURVR(R'R=RDR\RP(((s0/tmp/pip-install-Qvdv_2/graphviz/graphviz/dot.pyRμs   cBsieZdZejd k r8eejjdƒd7ZndZdeZdZed Z e d„ƒZ RS( s/Directed graph source code in the DOT language.t.is digraph %s{s strict %ss %s -> %s%ss%sRcCstS(s``True``(RQ(R((s0/tmp/pip-install-Qvdv_2/graphviz/graphviz/dot.pyRPsN(s%ss%sR( RTRURVRR t partitionR(R'R=RDR\RP(((s0/tmp/pip-install-Qvdv_2/graphviz/graphviz/dot.pyR s  N( RVRRRt__all__RYRtobjectRNRR(((s0/tmp/pip-install-Qvdv_2/graphviz/graphviz/dot.pyts  Ή!