vcorelib.io.file_writer
index
/home/vkottler/src/vkottler/workspace/vcorelib/vcorelib/io/file_writer.py

A module implementing an interface for writing to variably indented files.

 
Modules
       
os

 
Classes
       
builtins.object
IndentedFileWriter
enum.Enum(builtins.object)
CommentStyle

 
class CommentStyle(enum.Enum)
    CommentStyle(*values)
 
An enumeration describing different comment styles.
 
 
Method resolution order:
CommentStyle
enum.Enum
builtins.object

Data and other attributes defined here:
C = <CommentStyle.C: 1>
CPP = <CommentStyle.CPP: 3>
C_DOXYGEN = <CommentStyle.C_DOXYGEN: 2>
SCRIPT = <CommentStyle.SCRIPT: 4>

Data descriptors inherited from enum.Enum:
name
The name of the Enum member.
value
The value of the Enum member.

Methods inherited from enum.EnumType:
__contains__(value) from enum.EnumType
Return True if `value` is in `cls`.
 
`value` is in `cls` if:
1) `value` is a member of `cls`, or
2) `value` is the value of one of the `cls`'s members.
__getitem__(name) from enum.EnumType
Return the member matching `name`.
__iter__() from enum.EnumType
Return members in definition order.
__len__() from enum.EnumType
Return the number of members (no aliases)

Readonly properties inherited from enum.EnumType:
__members__
Returns a mapping of member name->value.
 
This mapping lists all enum members, including aliases. Note that this
is a read-only view of the internal mapping.

 
class IndentedFileWriter(builtins.object)
    IndentedFileWriter(stream: &lt;class 'TextIO'&gt;, space: str = ' ', per_indent: int = 1, prefix: str = '', suffix: str = '', linesep: str = '\n') -&gt; None
 
A class for writing lines to a file and tracking indentation.
 
  Methods defined here:
__init__(self, stream: <class 'TextIO'>, space: str = ' ', per_indent: int = 1, prefix: str = '', suffix: str = '', linesep: str = '\n') -> None
Initialize this instance.
c_comment(self, data: str) -> int
A helper for writing C-style comments.
cpp_comment(self, data: str) -> int
A helper for writing C++-style comments.
dedent(self, amount: int = 1) -> None
Decrease the current indent depth (if not zero).
empty(self, count: int = 1) -> int
Add some number of empty lines.
ends(self, prefix: str = '', suffix: str = '') -> Iterator[NoneType]
Adds a temporary prefix and suffix to lines.
indent(self, amount: int = 1) -> None
Increase the current indent depth.
indented(self, amount: int = 1) -> Iterator[NoneType]
Increase the current indent depth and decrease upon exit.
javadoc(self, opener: str = '/**', closer: str = ' */', prefix: str = ' * ') -> Iterator[NoneType]
A helper for writing javadoc-style comments.
join(self, *lines: str, joiner=',') -> None
Join lines with some joiner (appended to end), except after the last
line.
padding(self, count: int = 1) -> Iterator[NoneType]
Add padding lines as a managed context.
prefix(self, prefix: str) -> Iterator[NoneType]
Set a new line prefix as a managed context.
scope(self, opener: str = '{', closer: str = '}', prefix: str = '', suffix: str = '', indent: int = 1) -> Iterator[NoneType]
A helper for common programming syntax scoping.
suffix(self, suffix: str) -> Iterator[NoneType]
Set a new line suffix as a managed context.
trailing_comment_lines(self, style: vcorelib.io.file_writer.CommentStyle = <CommentStyle.C: 1>, pad: str = ' ', min_pad: int = 1) -> Iterator[List[Tuple[str, Optional[str]]]]
Align indentations for trailing comments.
write(self, data: str) -> int
method taking the str data for a new line of text to write
to the file: first writes the indent (some number of
e.g. space characters), then writes the str data (function parameter),
then writes a newline character (os.linesep).

Static methods defined here:
from_path(path: pathlib.Path, space: str = ' ', per_indent: int = 1, **kwargs) -> Iterator[ForwardRef('IndentedFileWriter')]
Create an instance from a path as a managed context.
string(space: str = ' ', per_indent: int = 1) -> Iterator[ForwardRef('IndentedFileWriter')]
Create an instance for a string.
temporary(space: str = ' ', per_indent: int = 1, **kwargs) -> Iterator[ForwardRef('IndentedFileWriter')]
Create an instance from a temporary file as a managed context.

Data descriptors defined here:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
Data
        DEFAULT_ENCODING = 'utf-8'
Iterator = typing.Iterator
LineWithComment = typing.Tuple[str, typing.Optional[str]]
LinesWithComments = typing.List[typing.Tuple[str, typing.Optional[str]]]
List = typing.List
Optional = typing.Optional
Tuple = typing.Tuple