devana.code_generation.printers

Subpackages

devana.code_generation.printers.codeprinter

class CodePrinter(configuration=None, is_fallback_allowed=False)[source]

Bases: ICodePrinter

Collection of low-level printers for many types. CodePrinter will match correct printer to source object type.

property configuration: PrinterConfiguration
Return type

PrinterConfiguration

property is_fallback_allowed: bool

Determines whether in the absence of a printer for a given type, it is possible to use a printer of its base type.

Return type

bool

print(source, config=None, context=None)[source]

Prints code from a given source dynamically looking for suitable printers.

register(cls_printer, source_type, context=None)[source]

Add a new printer to the collection of the given type.

class PrinterGroup[source]

Bases: ICodePrinter

Collection of low-level printers for one type. Helps you find the right printer for context requirements.

append(printer)[source]
print(source, config=None, context=None)[source]
class PrinterRecord(printer, context=None)[source]

Bases: object

Light abstraction layer for a printer that does not implement the full set of functionalities.

context: Optional = None
print(source, config=None, context=None)[source]
printer: ICodePrinter

devana.code_generation.printers.configuration

class AttributeFilter(values, is_forbidden=False)[source]

Bases: object

Filter for possible and forbidden attributes.

is_forbidden: bool = False
values: List[str]
class AttributesCriteria(names=<factory>, namespaces=<factory>)[source]

Bases: object

More specific attribute admissibility criteria.

filter(attributes)[source]
Return type

List[AttributeDeclaration]

names: Optional[AttributeFilter]

List of allowed or forbidden attribute names.

namespaces: Optional[AttributeFilter]

List of allowed or forbidden attribute namespaces.

class Indent(character=IndentCharacter.SPACE, value=4, count=0)[source]

Bases: object

Indent configuration. Value is the indent sign (space or tab) multiplier. For example value 2 mean indent 2 spaces. Count mean how many separated indent we have, for example count 3 mean 3 * value * character.

character: IndentCharacter = 1
count: int = 0
decrease()[source]
increase()[source]
print()[source]
reset()[source]
value: int = 4
class IndentCharacter(value)[source]

Bases: Enum

Indent character to configure.

SPACE = 1
TAB = 2
property character: str
Return type

str

print()[source]
class LineEndings(value)[source]

Bases: Enum

Kind of used line endings.

CR = 3
CR_LF = 2
LF = 1
LINUX = 1
MAC_OS = 3
WINDOWS = 2
property character: str
Return type

str

static default()[source]
static detect()[source]
print()[source]
class PrinterConfiguration(line_ending=LineEndings.LF, indent=<factory>, attributes=<factory>)[source]

Bases: object

Data structure that stores standard code printing settings e.g. newline format.

attributes: AttributesCriteria
format_line(text)[source]
Return type

str

indent: Indent
line_ending: LineEndings = 1

devana.code_generation.printers.dispatcherinjectable

class DispatcherInjectable(printer_dispatcher=None)[source]

Bases: object

Mixin class for provide injectable ICodePrinter as internal printer for all types.

property printer_dispatcher: ICodePrinter
Return type

ICodePrinter

devana.code_generation.printers.formatter

class Formatter(config)[source]

Bases: object

A class that helps create text strings based on a known configuration.

accumulate_line()[source]

Append current processing line to text without formatting.

clear()[source]

Clear formatter state.

property indent: Indent
Return type

Indent

property line: str

Current processing line.

Return type

str

next_line()[source]

Format current processing line indent and newline character, next append it to text.

print_line(text)[source]

Format next part of text and accumulate this to text.

property text: str

Result text.

Return type

str

devana.code_generation.printers.icodeprinter

class ICodePrinter[source]

Bases: ABC

Common interface for all printers.

property is_fallback_handler: bool
Return type

bool

abstract print(source, config=None, context=None)[source]

Printers module provides functionality to transform python representation of code to useful strings.