$45 GRAYBYTE WORDPRESS FILE MANAGER $84

SERVER : vnpttt-amd7f72-h1.vietnix.vn #1 SMP Fri May 24 12:42:50 UTC 2024
SERVER IP : 103.200.23.149 | ADMIN IP 216.73.216.22
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/opt/cloudlinux/venv/lib/python3.11/site-packages/pylint/pyreverse/

HOME
Current File : /opt/cloudlinux/venv/lib/python3.11/site-packages/pylint/pyreverse//mermaidjs_printer.py
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt

"""Class to generate files in mermaidjs format."""

from __future__ import annotations

from pylint.pyreverse.printer import EdgeType, NodeProperties, NodeType, Printer
from pylint.pyreverse.utils import get_annotation_label


class MermaidJSPrinter(Printer):
    """Printer for MermaidJS diagrams."""

    DEFAULT_COLOR = "black"

    NODES: dict[NodeType, str] = {
        NodeType.CLASS: "class",
        NodeType.INTERFACE: "class",
        NodeType.PACKAGE: "class",
    }
    ARROWS: dict[EdgeType, str] = {
        EdgeType.INHERITS: "--|>",
        EdgeType.IMPLEMENTS: "..|>",
        EdgeType.ASSOCIATION: "--*",
        EdgeType.AGGREGATION: "--o",
        EdgeType.USES: "-->",
    }

    def _open_graph(self) -> None:
        """Emit the header lines."""
        self.emit("classDiagram")
        self._inc_indent()

    def emit_node(
        self,
        name: str,
        type_: NodeType,
        properties: NodeProperties | None = None,
    ) -> None:
        """Create a new node.

        Nodes can be classes, packages, participants etc.
        """
        # pylint: disable=duplicate-code
        if properties is None:
            properties = NodeProperties(label=name)
        stereotype = "~~Interface~~" if type_ is NodeType.INTERFACE else ""
        nodetype = self.NODES[type_]
        body = []
        if properties.attrs:
            body.extend(properties.attrs)
        if properties.methods:
            for func in properties.methods:
                args = self._get_method_arguments(func)
                line = f"{func.name}({', '.join(args)})"
                line += "*" if func.is_abstract() else ""
                if func.returns:
                    line += f" {get_annotation_label(func.returns)}"
                body.append(line)
        name = name.split(".")[-1]
        self.emit(f"{nodetype} {name}{stereotype} {{")
        self._inc_indent()
        for line in body:
            self.emit(line)
        self._dec_indent()
        self.emit("}")

    def emit_edge(
        self,
        from_node: str,
        to_node: str,
        type_: EdgeType,
        label: str | None = None,
    ) -> None:
        """Create an edge from one node to another to display relationships."""
        from_node = from_node.split(".")[-1]
        to_node = to_node.split(".")[-1]
        edge = f"{from_node} {self.ARROWS[type_]} {to_node}"
        if label:
            edge += f" : {label}"
        self.emit(edge)

    def _close_graph(self) -> None:
        """Emit the lines needed to properly close the graph."""
        self._dec_indent()


class HTMLMermaidJSPrinter(MermaidJSPrinter):
    """Printer for MermaidJS diagrams wrapped in a html boilerplate."""

    HTML_OPEN_BOILERPLATE = """<html>
  <body>
    <script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
      <div class="mermaid">
    """
    HTML_CLOSE_BOILERPLATE = """
       </div>
  </body>
</html>
"""
    GRAPH_INDENT_LEVEL = 4

    def _open_graph(self) -> None:
        self.emit(self.HTML_OPEN_BOILERPLATE)
        for _ in range(self.GRAPH_INDENT_LEVEL):
            self._inc_indent()
        super()._open_graph()

    def _close_graph(self) -> None:
        for _ in range(self.GRAPH_INDENT_LEVEL):
            self._dec_indent()
        self.emit(self.HTML_CLOSE_BOILERPLATE)

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
14 Aug 2025 9.24 PM
root / root
0755
__pycache__
--
14 Aug 2025 9.24 PM
root / root
0755
__init__.py
0.268 KB
17 Apr 2025 8.10 PM
root / root
0644
diadefslib.py
8.503 KB
17 Apr 2025 8.10 PM
root / root
0644
diagrams.py
10.623 KB
17 Apr 2025 8.10 PM
root / root
0644
dot_printer.py
6.33 KB
17 Apr 2025 8.10 PM
root / root
0644
inspector.py
14.723 KB
17 Apr 2025 8.10 PM
root / root
0644
main.py
8.758 KB
17 Apr 2025 8.10 PM
root / root
0644
mermaidjs_printer.py
3.469 KB
17 Apr 2025 8.10 PM
root / root
0644
plantuml_printer.py
3.558 KB
17 Apr 2025 8.10 PM
root / root
0644
printer.py
3.646 KB
17 Apr 2025 8.10 PM
root / root
0644
printer_factory.py
0.879 KB
17 Apr 2025 8.10 PM
root / root
0644
utils.py
8.129 KB
17 Apr 2025 8.10 PM
root / root
0644
vcg_printer.py
8.672 KB
17 Apr 2025 8.10 PM
root / root
0644
writer.py
6.092 KB
17 Apr 2025 8.10 PM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF