export.py : rtype and function doc (part)
This commit is contained in:
parent
e64c6d7f41
commit
43db9f7a09
|
|
@ -5,7 +5,6 @@
|
||||||
# rsp = ExportResponse("start_string", "end_string")
|
# rsp = ExportResponse("start_string", "end_string")
|
||||||
# em = ExportManager(config_file, template_file)
|
# em = ExportManager(config_file, template_file)
|
||||||
# em(ExportRequest()) -> ExportResponse()
|
# em(ExportRequest()) -> ExportResponse()
|
||||||
# import rich
|
|
||||||
import rich
|
import rich
|
||||||
|
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
|
|
@ -47,7 +46,14 @@ class ExportManager:
|
||||||
"""
|
"""
|
||||||
Transforms ExportRequest tuples to ExportResponse tuples with the config-provided appropriate markup.
|
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.config = cnoifg
|
||||||
self.templates = templates
|
self.templates = templates
|
||||||
self.advanced_export = {
|
self.advanced_export = {
|
||||||
|
|
@ -61,6 +67,12 @@ class ExportManager:
|
||||||
}
|
}
|
||||||
|
|
||||||
def __call__(self, export_request):
|
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)
|
return self.transform(export_request)
|
||||||
|
|
||||||
def transform(self, export_request):
|
def transform(self, export_request):
|
||||||
|
|
@ -151,6 +163,7 @@ class ExportManager:
|
||||||
"""
|
"""
|
||||||
Specific template for display.
|
Specific template for display.
|
||||||
:type export_request: ExportRequest
|
:type export_request: ExportRequest
|
||||||
|
:rtype: ExportResponse
|
||||||
"""
|
"""
|
||||||
start, end, optionals = self._get_template(export_request)
|
start, end, optionals = self._get_template(export_request)
|
||||||
start = start.format(optionals=optionals, display_level=export_request.others["display_level"])
|
start = start.format(optionals=optionals, display_level=export_request.others["display_level"])
|
||||||
|
|
@ -160,6 +173,7 @@ class ExportManager:
|
||||||
"""
|
"""
|
||||||
Specific template for link.
|
Specific template for link.
|
||||||
:type export_request: ExportRequest
|
:type export_request: ExportRequest
|
||||||
|
:rtype: ExportResponse
|
||||||
"""
|
"""
|
||||||
start, end, _ = self._get_template(export_request)
|
start, end, _ = self._get_template(export_request)
|
||||||
start = start.format(url=export_request.others["url"])
|
start = start.format(url=export_request.others["url"])
|
||||||
|
|
@ -169,6 +183,7 @@ class ExportManager:
|
||||||
"""
|
"""
|
||||||
Specific template for table content.
|
Specific template for table content.
|
||||||
:type export_request: ExportRequest
|
:type export_request: ExportRequest
|
||||||
|
:rtype: ExportResponse
|
||||||
"""
|
"""
|
||||||
start, end, _ = self._get_template(export_request)
|
start, end, _ = self._get_template(export_request)
|
||||||
start = start.format(col_span=export_request.others["col_span"])
|
start = start.format(col_span=export_request.others["col_span"])
|
||||||
|
|
@ -178,6 +193,7 @@ class ExportManager:
|
||||||
"""
|
"""
|
||||||
Specific template for images.
|
Specific template for images.
|
||||||
:type export_request: ExportRequest
|
:type export_request: ExportRequest
|
||||||
|
:rtype: ExportResponse
|
||||||
"""
|
"""
|
||||||
start, end, optionals = self._get_template(export_request)
|
start, end, optionals = self._get_template(export_request)
|
||||||
end = end.format(optionals=optionals)
|
end = end.format(optionals=optionals)
|
||||||
|
|
@ -197,6 +213,8 @@ class ContextConverter:
|
||||||
pile output from the context manager.
|
pile output from the context manager.
|
||||||
exporter : ExportManager
|
exporter : ExportManager
|
||||||
Our ExportManager
|
Our ExportManager
|
||||||
|
destination : str
|
||||||
|
Destination of the output file.
|
||||||
"""
|
"""
|
||||||
self.io_output = StringIO()
|
self.io_output = StringIO()
|
||||||
self.pile = pile
|
self.pile = pile
|
||||||
|
|
@ -206,7 +224,8 @@ class ContextConverter:
|
||||||
|
|
||||||
def process_pile(self):
|
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:
|
for container in self.pile:
|
||||||
self.io_output.write(container.export(self.exporter))
|
self.io_output.write(container.export(self.exporter))
|
||||||
|
|
@ -224,6 +243,7 @@ class ContextConverter:
|
||||||
def readlines(self):
|
def readlines(self):
|
||||||
"""
|
"""
|
||||||
Yields the converted pile line after line
|
Yields the converted pile line after line
|
||||||
|
:rtype: list[str]
|
||||||
"""
|
"""
|
||||||
return self.io_output.readlines()
|
return self.io_output.readlines()
|
||||||
|
|
||||||
|
|
@ -232,6 +252,9 @@ class ContextConverter:
|
||||||
f"Status: {'initialized' if self.io_initialized else 'uninitialized'}"
|
f"Status: {'initialized' if self.io_initialized else 'uninitialized'}"
|
||||||
|
|
||||||
def print_all(self):
|
def print_all(self):
|
||||||
|
"""
|
||||||
|
Prints the entirety of the converted pile
|
||||||
|
"""
|
||||||
print(self)
|
print(self)
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue