export.py : rtype and function doc (part)

This commit is contained in:
Maximilien Rigaut 2022-06-09 15:21:56 +02:00
parent e64c6d7f41
commit 43db9f7a09
No known key found for this signature in database
GPG Key ID: 4F14B23709ADA5B1
1 changed files with 26 additions and 3 deletions

View File

@ -5,7 +5,6 @@
# rsp = ExportResponse("start_string", "end_string")
# em = ExportManager(config_file, template_file)
# em(ExportRequest()) -> ExportResponse()
# import rich
import rich
from io import StringIO
@ -47,7 +46,14 @@ class ExportManager:
"""
Transforms ExportRequest tuples to ExportResponse tuples with the config-provided appropriate markup.
"""
def __init__(self, cnoifg, templates): # noqa
def __init__(self, cnoifg, templates):
"""
Initialization function for the ExportManager.
:param cnoifg: Config file
:type cnoifg: config.ConfigLoader
:param templates: Templates file
:type templates: config.ConfigLoader
"""
self.config = cnoifg
self.templates = templates
self.advanced_export = {
@ -61,6 +67,12 @@ class ExportManager:
}
def __call__(self, export_request):
"""
Callable function for ExportManager, transforming ExportRequest tuples into ExportResponse tuples.
:param export_request: ExportRequest tuples
:type export_request: ExportRequest
:return: ExportResponse tuples
"""
return self.transform(export_request)
def transform(self, export_request):
@ -151,6 +163,7 @@ class ExportManager:
"""
Specific template for display.
:type export_request: ExportRequest
:rtype: ExportResponse
"""
start, end, optionals = self._get_template(export_request)
start = start.format(optionals=optionals, display_level=export_request.others["display_level"])
@ -160,6 +173,7 @@ class ExportManager:
"""
Specific template for link.
:type export_request: ExportRequest
:rtype: ExportResponse
"""
start, end, _ = self._get_template(export_request)
start = start.format(url=export_request.others["url"])
@ -169,6 +183,7 @@ class ExportManager:
"""
Specific template for table content.
:type export_request: ExportRequest
:rtype: ExportResponse
"""
start, end, _ = self._get_template(export_request)
start = start.format(col_span=export_request.others["col_span"])
@ -178,6 +193,7 @@ class ExportManager:
"""
Specific template for images.
:type export_request: ExportRequest
:rtype: ExportResponse
"""
start, end, optionals = self._get_template(export_request)
end = end.format(optionals=optionals)
@ -197,6 +213,8 @@ class ContextConverter:
pile output from the context manager.
exporter : ExportManager
Our ExportManager
destination : str
Destination of the output file.
"""
self.io_output = StringIO()
self.pile = pile
@ -206,7 +224,8 @@ class ContextConverter:
def process_pile(self):
"""
Main method processing the given pile.
Processes the pile and writes the output to the io_output object.
:rtype: StringIO
"""
for container in self.pile:
self.io_output.write(container.export(self.exporter))
@ -224,6 +243,7 @@ class ContextConverter:
def readlines(self):
"""
Yields the converted pile line after line
:rtype: list[str]
"""
return self.io_output.readlines()
@ -232,6 +252,9 @@ class ContextConverter:
f"Status: {'initialized' if self.io_initialized else 'uninitialized'}"
def print_all(self):
"""
Prints the entirety of the converted pile
"""
print(self)
def __eq__(self, other):