File: base.py

package info (click to toggle)
python-graphviz 0.20.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,188 kB
  • sloc: python: 4,098; makefile: 13
file content (32 lines) | stat: -rw-r--r-- 965 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""Iterables of DOT source code lines (including final newline)."""

import typing

from . import copying

__all__ = ['Base']


class LineIterable:
    """Iterable of DOT Source code lines
        (mimics ``file`` objects in text mode)."""

    def __iter__(self) -> typing.Iterator[str]:  # pragma: no cover
        r"""Yield the generated DOT source line by line.

        Yields: Line ending with a newline (``'\n'``).
        """
        raise NotImplementedError('to be implemented by concrete subclasses')


# Common base interface for all exposed classes
class Base(LineIterable, copying.CopyBase):
    """LineIterator with ``.source`` attribute, that it returns for ``str()``."""

    @property
    def source(self) -> str:  # pragma: no cover
        raise NotImplementedError('to be implemented by concrete subclasses')

    def __str__(self) -> str:
        """The DOT source code as string."""
        return self.source