-
Notifications
You must be signed in to change notification settings - Fork 209
/
base.py
32 lines (21 loc) · 933 Bytes
/
base.py
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