Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +1 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/__pycache__/__init__.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/__pycache__/__version__.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/__pycache__/_converter.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/__pycache__/_factory.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/__pycache__/_function.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/__pycache__/_table_format.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/__pycache__/_typing.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/__pycache__/error.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/_logger/__init__.py +4 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/_logger/__pycache__/__init__.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/_logger/__pycache__/_logger.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/_logger/__pycache__/_null_logger.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/_logger/_logger.py +117 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/_logger/_null_logger.py +44 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/typehint/__init__.py +38 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/typehint/__pycache__/__init__.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/__init__.py +74 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/_common.py +12 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/_elasticsearch.py +204 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/_interface.py +84 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/_null.py +61 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__init__.py +44 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/__init__.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_asciidoc.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_borderless.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_common.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_css.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_csv.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_html.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_interface.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_json.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_jsonlines.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_latex.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_ltsv.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_markdown.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_mediawiki.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_rst.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_spacealigned.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_text_writer.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_toml.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_tsv.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_unicode.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_yaml.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/_asciidoc.py +146 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/_borderless.py +41 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/_common.py +26 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/_css.py +157 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/_csv.py +63 -0
- llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/_html.py +194 -0
.gitattributes
CHANGED
@@ -64,3 +64,4 @@ llmeval-env/lib/python3.10/site-packages/scipy/optimize/_highs/_highs_wrapper.cp
|
|
64 |
llmeval-env/lib/python3.10/site-packages/scipy/sparse/_sparsetools.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
65 |
llmeval-env/lib/python3.10/site-packages/scipy/spatial/_ckdtree.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
66 |
llmeval-env/lib/python3.10/site-packages/scipy/spatial/_qhull.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
|
|
|
64 |
llmeval-env/lib/python3.10/site-packages/scipy/sparse/_sparsetools.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
65 |
llmeval-env/lib/python3.10/site-packages/scipy/spatial/_ckdtree.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
66 |
llmeval-env/lib/python3.10/site-packages/scipy/spatial/_qhull.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
67 |
+
llmeval-env/lib/python3.10/site-packages/scipy/misc/face.dat filter=lfs diff=lfs merge=lfs -text
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (2.4 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/__pycache__/__version__.cpython-310.pyc
ADDED
Binary file (392 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/__pycache__/_converter.cpython-310.pyc
ADDED
Binary file (519 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/__pycache__/_factory.cpython-310.pyc
ADDED
Binary file (10.8 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/__pycache__/_function.cpython-310.pyc
ADDED
Binary file (2.81 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/__pycache__/_table_format.cpython-310.pyc
ADDED
Binary file (6.74 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/__pycache__/_typing.cpython-310.pyc
ADDED
Binary file (79.4 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/__pycache__/error.cpython-310.pyc
ADDED
Binary file (1.43 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/_logger/__init__.py
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from ._logger import WriterLogger, logger, set_logger
|
2 |
+
|
3 |
+
|
4 |
+
__all__ = ("WriterLogger", "logger", "set_logger")
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/_logger/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (291 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/_logger/__pycache__/_logger.cpython-310.pyc
ADDED
Binary file (4.1 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/_logger/__pycache__/_null_logger.cpython-310.pyc
ADDED
Binary file (1.93 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/_logger/_logger.py
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
.. codeauthor:: Tsuyoshi Hombashi <[email protected]>
|
3 |
+
"""
|
4 |
+
|
5 |
+
from typing import TYPE_CHECKING, List
|
6 |
+
|
7 |
+
import dataproperty
|
8 |
+
from mbstrdecoder import MultiByteStrDecoder
|
9 |
+
|
10 |
+
from ._null_logger import NullLogger # type: ignore
|
11 |
+
|
12 |
+
|
13 |
+
if TYPE_CHECKING:
|
14 |
+
from ..writer import AbstractTableWriter
|
15 |
+
|
16 |
+
MODULE_NAME = "pytablewriter"
|
17 |
+
|
18 |
+
try:
|
19 |
+
from loguru import logger
|
20 |
+
|
21 |
+
logger.disable(MODULE_NAME)
|
22 |
+
except ImportError:
|
23 |
+
logger = NullLogger()
|
24 |
+
|
25 |
+
|
26 |
+
def set_logger(is_enable: bool, propagation_depth: int = 1) -> None:
|
27 |
+
if is_enable:
|
28 |
+
logger.enable(MODULE_NAME)
|
29 |
+
else:
|
30 |
+
logger.disable(MODULE_NAME)
|
31 |
+
|
32 |
+
if propagation_depth <= 0:
|
33 |
+
return
|
34 |
+
|
35 |
+
dataproperty.set_logger(is_enable, propagation_depth - 1)
|
36 |
+
|
37 |
+
try:
|
38 |
+
import simplesqlite
|
39 |
+
|
40 |
+
simplesqlite.set_logger(is_enable, propagation_depth - 1)
|
41 |
+
except ImportError:
|
42 |
+
pass
|
43 |
+
|
44 |
+
try:
|
45 |
+
import pytablereader
|
46 |
+
|
47 |
+
pytablereader.set_logger(is_enable, propagation_depth - 1)
|
48 |
+
except ImportError:
|
49 |
+
pass
|
50 |
+
|
51 |
+
|
52 |
+
class WriterLogger:
|
53 |
+
@property
|
54 |
+
def logger(self): # type: ignore
|
55 |
+
return self.__logger
|
56 |
+
|
57 |
+
def __init__(self, writer: "AbstractTableWriter") -> None:
|
58 |
+
self.__writer = writer
|
59 |
+
self.__logger = logger
|
60 |
+
|
61 |
+
self.logger.debug(f"created WriterLogger: format={writer.format_name}")
|
62 |
+
|
63 |
+
def __enter__(self) -> "WriterLogger":
|
64 |
+
self.logging_start_write()
|
65 |
+
return self
|
66 |
+
|
67 |
+
def __exit__(self, *exc): # type: ignore
|
68 |
+
self.logging_complete_write()
|
69 |
+
return False
|
70 |
+
|
71 |
+
def logging_start_write(self) -> None:
|
72 |
+
log_entry_list = [
|
73 |
+
self.__get_format_name_message(),
|
74 |
+
self.__get_table_name_message(),
|
75 |
+
f"headers={self.__writer.headers}",
|
76 |
+
]
|
77 |
+
|
78 |
+
try:
|
79 |
+
log_entry_list.append(f"rows={len(self.__writer.value_matrix)}")
|
80 |
+
except (TypeError, AttributeError):
|
81 |
+
log_entry_list.append("rows=NaN")
|
82 |
+
|
83 |
+
log_entry_list.append(self.__get_typehint_message())
|
84 |
+
log_entry_list.extend(self.__get_extra_log_entry_list())
|
85 |
+
|
86 |
+
self.logger.debug("start write table: {}".format(", ".join(log_entry_list)))
|
87 |
+
|
88 |
+
def logging_complete_write(self) -> None:
|
89 |
+
log_entry_list = [self.__get_format_name_message(), self.__get_table_name_message()]
|
90 |
+
log_entry_list.extend(self.__get_extra_log_entry_list())
|
91 |
+
|
92 |
+
self.logger.debug("complete write table: {}".format(", ".join(log_entry_list)))
|
93 |
+
|
94 |
+
def __get_format_name_message(self) -> str:
|
95 |
+
return f"format={self.__writer.format_name:s}"
|
96 |
+
|
97 |
+
def __get_table_name_message(self) -> str:
|
98 |
+
if self.__writer.table_name:
|
99 |
+
table_name = MultiByteStrDecoder(self.__writer.table_name).unicode_str
|
100 |
+
else:
|
101 |
+
table_name = ""
|
102 |
+
|
103 |
+
return f"table-name='{table_name}'"
|
104 |
+
|
105 |
+
def __get_extra_log_entry_list(self) -> List[str]:
|
106 |
+
if self.__writer._iter_count is None:
|
107 |
+
return []
|
108 |
+
|
109 |
+
return [f"iteration={self.__writer._iter_count}/{self.__writer.iteration_length}"]
|
110 |
+
|
111 |
+
def __get_typehint_message(self) -> str:
|
112 |
+
try:
|
113 |
+
return "type-hints={}".format(
|
114 |
+
[type_hint(None).typename for type_hint in self.__writer.type_hints]
|
115 |
+
)
|
116 |
+
except (TypeError, AttributeError):
|
117 |
+
return "type-hints=[]"
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/_logger/_null_logger.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# type: ignore
|
2 |
+
|
3 |
+
|
4 |
+
class NullLogger:
|
5 |
+
level_name = None
|
6 |
+
|
7 |
+
def remove(self, handler_id=None): # pragma: no cover
|
8 |
+
pass
|
9 |
+
|
10 |
+
def add(self, sink, **kwargs): # pragma: no cover
|
11 |
+
pass
|
12 |
+
|
13 |
+
def disable(self, name): # pragma: no cover
|
14 |
+
pass
|
15 |
+
|
16 |
+
def enable(self, name): # pragma: no cover
|
17 |
+
pass
|
18 |
+
|
19 |
+
def critical(self, __message, *args, **kwargs): # pragma: no cover
|
20 |
+
pass
|
21 |
+
|
22 |
+
def debug(self, __message, *args, **kwargs): # pragma: no cover
|
23 |
+
pass
|
24 |
+
|
25 |
+
def error(self, __message, *args, **kwargs): # pragma: no cover
|
26 |
+
pass
|
27 |
+
|
28 |
+
def exception(self, __message, *args, **kwargs): # pragma: no cover
|
29 |
+
pass
|
30 |
+
|
31 |
+
def info(self, __message, *args, **kwargs): # pragma: no cover
|
32 |
+
pass
|
33 |
+
|
34 |
+
def log(self, __level, __message, *args, **kwargs): # pragma: no cover
|
35 |
+
pass
|
36 |
+
|
37 |
+
def success(self, __message, *args, **kwargs): # pragma: no cover
|
38 |
+
pass
|
39 |
+
|
40 |
+
def trace(self, __message, *args, **kwargs): # pragma: no cover
|
41 |
+
pass
|
42 |
+
|
43 |
+
def warning(self, __message, *args, **kwargs): # pragma: no cover
|
44 |
+
pass
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/typehint/__init__.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from dataproperty.typing import TypeHint
|
2 |
+
from typepy import (
|
3 |
+
Binary,
|
4 |
+
Bool,
|
5 |
+
Bytes,
|
6 |
+
DateTime,
|
7 |
+
Dictionary,
|
8 |
+
Infinity,
|
9 |
+
Integer,
|
10 |
+
IpAddress,
|
11 |
+
List,
|
12 |
+
Nan,
|
13 |
+
NoneType,
|
14 |
+
NullString,
|
15 |
+
RealNumber,
|
16 |
+
String,
|
17 |
+
)
|
18 |
+
from typepy.type import AbstractType
|
19 |
+
|
20 |
+
|
21 |
+
__all__ = (
|
22 |
+
"Binary",
|
23 |
+
"Bool",
|
24 |
+
"Bytes",
|
25 |
+
"DateTime",
|
26 |
+
"Dictionary",
|
27 |
+
"Infinity",
|
28 |
+
"Integer",
|
29 |
+
"IpAddress",
|
30 |
+
"List",
|
31 |
+
"Nan",
|
32 |
+
"NoneType",
|
33 |
+
"NullString",
|
34 |
+
"RealNumber",
|
35 |
+
"String",
|
36 |
+
"TypeHint",
|
37 |
+
"AbstractType",
|
38 |
+
)
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/typehint/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (664 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/__init__.py
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from ._elasticsearch import ElasticsearchWriter
|
2 |
+
from ._null import NullTableWriter
|
3 |
+
from ._table_writer import AbstractTableWriter
|
4 |
+
from .binary import (
|
5 |
+
ExcelXlsTableWriter,
|
6 |
+
ExcelXlsxTableWriter,
|
7 |
+
PandasDataFramePickleWriter,
|
8 |
+
SqliteTableWriter,
|
9 |
+
)
|
10 |
+
from .text import (
|
11 |
+
AsciiDocTableWriter,
|
12 |
+
BoldUnicodeTableWriter,
|
13 |
+
BorderlessTableWriter,
|
14 |
+
CssTableWriter,
|
15 |
+
CsvTableWriter,
|
16 |
+
HtmlTableWriter,
|
17 |
+
JsonLinesTableWriter,
|
18 |
+
JsonTableWriter,
|
19 |
+
LatexMatrixWriter,
|
20 |
+
LatexTableWriter,
|
21 |
+
LtsvTableWriter,
|
22 |
+
MarkdownTableWriter,
|
23 |
+
MediaWikiTableWriter,
|
24 |
+
RstCsvTableWriter,
|
25 |
+
RstGridTableWriter,
|
26 |
+
RstSimpleTableWriter,
|
27 |
+
SpaceAlignedTableWriter,
|
28 |
+
TomlTableWriter,
|
29 |
+
TsvTableWriter,
|
30 |
+
UnicodeTableWriter,
|
31 |
+
YamlTableWriter,
|
32 |
+
)
|
33 |
+
from .text.sourcecode import (
|
34 |
+
JavaScriptTableWriter,
|
35 |
+
NumpyTableWriter,
|
36 |
+
PandasDataFrameWriter,
|
37 |
+
PythonCodeTableWriter,
|
38 |
+
)
|
39 |
+
|
40 |
+
|
41 |
+
__all__ = (
|
42 |
+
"AbstractTableWriter",
|
43 |
+
"AsciiDocTableWriter",
|
44 |
+
"BoldUnicodeTableWriter",
|
45 |
+
"BorderlessTableWriter",
|
46 |
+
"CssTableWriter",
|
47 |
+
"CsvTableWriter",
|
48 |
+
"ElasticsearchWriter",
|
49 |
+
"ExcelXlsTableWriter",
|
50 |
+
"ExcelXlsxTableWriter",
|
51 |
+
"HtmlTableWriter",
|
52 |
+
"JavaScriptTableWriter",
|
53 |
+
"JsonLinesTableWriter",
|
54 |
+
"JsonTableWriter",
|
55 |
+
"LatexMatrixWriter",
|
56 |
+
"LatexTableWriter",
|
57 |
+
"LtsvTableWriter",
|
58 |
+
"MarkdownTableWriter",
|
59 |
+
"MediaWikiTableWriter",
|
60 |
+
"NullTableWriter",
|
61 |
+
"NumpyTableWriter",
|
62 |
+
"PandasDataFramePickleWriter",
|
63 |
+
"PandasDataFrameWriter",
|
64 |
+
"PythonCodeTableWriter",
|
65 |
+
"RstCsvTableWriter",
|
66 |
+
"RstGridTableWriter",
|
67 |
+
"RstSimpleTableWriter",
|
68 |
+
"SpaceAlignedTableWriter",
|
69 |
+
"SqliteTableWriter",
|
70 |
+
"TomlTableWriter",
|
71 |
+
"TsvTableWriter",
|
72 |
+
"UnicodeTableWriter",
|
73 |
+
"YamlTableWriter",
|
74 |
+
)
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/_common.py
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from textwrap import dedent
|
2 |
+
|
3 |
+
|
4 |
+
HEADER_ROW = -1
|
5 |
+
|
6 |
+
|
7 |
+
import_error_msg_template = dedent(
|
8 |
+
"""\
|
9 |
+
dependency packages for {0} not found.
|
10 |
+
you can install the dependencies with 'pip install pytablewriter[{0}]'
|
11 |
+
"""
|
12 |
+
)
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/_elasticsearch.py
ADDED
@@ -0,0 +1,204 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
.. codeauthor:: Tsuyoshi Hombashi <[email protected]>
|
3 |
+
"""
|
4 |
+
|
5 |
+
|
6 |
+
import copy
|
7 |
+
from typing import Any, Dict, Generator
|
8 |
+
|
9 |
+
import dataproperty
|
10 |
+
from dataproperty import ColumnDataProperty
|
11 |
+
from typepy import Typecode
|
12 |
+
|
13 |
+
from ..error import EmptyValueError
|
14 |
+
from ._msgfy import to_error_message
|
15 |
+
from ._table_writer import AbstractTableWriter
|
16 |
+
|
17 |
+
|
18 |
+
DataType = Dict[str, str]
|
19 |
+
Properties = Dict[str, DataType]
|
20 |
+
|
21 |
+
|
22 |
+
def _get_es_datatype(column_dp: ColumnDataProperty) -> DataType:
|
23 |
+
if column_dp.typecode in (
|
24 |
+
Typecode.NONE,
|
25 |
+
Typecode.NULL_STRING,
|
26 |
+
Typecode.INFINITY,
|
27 |
+
Typecode.NAN,
|
28 |
+
):
|
29 |
+
return {"type": "keyword"}
|
30 |
+
|
31 |
+
if column_dp.typecode == Typecode.STRING:
|
32 |
+
return {"type": "text"}
|
33 |
+
|
34 |
+
if column_dp.typecode == Typecode.DATETIME:
|
35 |
+
return {"type": "date", "format": "date_optional_time"}
|
36 |
+
|
37 |
+
if column_dp.typecode == Typecode.REAL_NUMBER:
|
38 |
+
return {"type": "double"}
|
39 |
+
|
40 |
+
if column_dp.typecode == Typecode.BOOL:
|
41 |
+
return {"type": "boolean"}
|
42 |
+
|
43 |
+
if column_dp.typecode == Typecode.IP_ADDRESS:
|
44 |
+
return {"type": "ip"}
|
45 |
+
|
46 |
+
if column_dp.typecode == Typecode.INTEGER:
|
47 |
+
assert column_dp.bit_length is not None
|
48 |
+
|
49 |
+
if column_dp.bit_length <= 8:
|
50 |
+
return {"type": "byte"}
|
51 |
+
elif column_dp.bit_length <= 16:
|
52 |
+
return {"type": "short"}
|
53 |
+
elif column_dp.bit_length <= 32:
|
54 |
+
return {"type": "integer"}
|
55 |
+
elif column_dp.bit_length <= 64:
|
56 |
+
return {"type": "long"}
|
57 |
+
|
58 |
+
raise ValueError(
|
59 |
+
f"too large integer bits: expected<=64bits, actual={column_dp.bit_length:d}bits"
|
60 |
+
)
|
61 |
+
|
62 |
+
raise ValueError(f"unknown typecode: {column_dp.typecode}")
|
63 |
+
|
64 |
+
|
65 |
+
class ElasticsearchWriter(AbstractTableWriter):
|
66 |
+
"""
|
67 |
+
A table writer class for Elasticsearch.
|
68 |
+
|
69 |
+
:Dependency Packages:
|
70 |
+
- `elasticsearch-py <https://github.com/elastic/elasticsearch-py>`__
|
71 |
+
|
72 |
+
.. py:attribute:: index_name
|
73 |
+
:type: str
|
74 |
+
|
75 |
+
Alias attribute for |table_name|.
|
76 |
+
|
77 |
+
.. py:attribute:: document_type
|
78 |
+
:type: str
|
79 |
+
:value: "table"
|
80 |
+
|
81 |
+
Specify document type for indices.
|
82 |
+
|
83 |
+
.. py:method:: write_table()
|
84 |
+
|
85 |
+
Create an index and put documents for each row to Elasticsearch.
|
86 |
+
|
87 |
+
You need to pass an
|
88 |
+
`elasticsearch.Elasticsearch <https://elasticsearch-py.rtfd.io/en/master/api.html#elasticsearch>`__
|
89 |
+
instance to |stream| before calling this method.
|
90 |
+
|table_name|/:py:attr:`~pytablewriter.ElasticsearchWriter.index_name`
|
91 |
+
used as the creating index name,
|
92 |
+
invalid characters in the name are replaced with underscores (``'_'``).
|
93 |
+
Document data types for documents are automatically detected from the data.
|
94 |
+
|
95 |
+
:raises ValueError:
|
96 |
+
If the |stream| has not elasticsearch.Elasticsearch instance.
|
97 |
+
:Example:
|
98 |
+
:ref:`example-elasticsearch-table-writer`
|
99 |
+
"""
|
100 |
+
|
101 |
+
FORMAT_NAME = "elasticsearch"
|
102 |
+
|
103 |
+
@property
|
104 |
+
def format_name(self) -> str:
|
105 |
+
return self.FORMAT_NAME
|
106 |
+
|
107 |
+
@property
|
108 |
+
def support_split_write(self) -> bool:
|
109 |
+
return True
|
110 |
+
|
111 |
+
@property
|
112 |
+
def table_name(self) -> str:
|
113 |
+
return super().table_name
|
114 |
+
|
115 |
+
@table_name.setter
|
116 |
+
def table_name(self, value: str) -> None:
|
117 |
+
from pathvalidate import ErrorReason, ValidationError
|
118 |
+
|
119 |
+
from ..sanitizer import ElasticsearchIndexNameSanitizer
|
120 |
+
|
121 |
+
try:
|
122 |
+
self._table_name = ElasticsearchIndexNameSanitizer(value).sanitize(replacement_text="_")
|
123 |
+
except ValidationError as e:
|
124 |
+
if e.reason is ErrorReason.NULL_NAME:
|
125 |
+
self._table_name = ""
|
126 |
+
else:
|
127 |
+
raise
|
128 |
+
|
129 |
+
@property
|
130 |
+
def index_name(self) -> str:
|
131 |
+
return self.table_name
|
132 |
+
|
133 |
+
@index_name.setter
|
134 |
+
def index_name(self, value: str) -> None:
|
135 |
+
self.table_name = value
|
136 |
+
|
137 |
+
def __init__(self, **kwargs: Any) -> None:
|
138 |
+
super().__init__(**kwargs)
|
139 |
+
|
140 |
+
self.stream = None
|
141 |
+
self.is_padding = False
|
142 |
+
self.is_formatting_float = False
|
143 |
+
self._is_require_table_name = True
|
144 |
+
self._quoting_flags = copy.deepcopy(dataproperty.NOT_QUOTING_FLAGS)
|
145 |
+
self._dp_extractor.type_value_map = copy.deepcopy(dataproperty.DefaultValue.TYPE_VALUE_MAP)
|
146 |
+
|
147 |
+
self.document_type = "table"
|
148 |
+
|
149 |
+
def write_null_line(self) -> None:
|
150 |
+
pass
|
151 |
+
|
152 |
+
def _get_mappings(self) -> Dict[str, Dict[str, Dict[str, Properties]]]:
|
153 |
+
properties: Properties = {}
|
154 |
+
|
155 |
+
for header, column_dp in zip(self.headers, self._column_dp_list):
|
156 |
+
properties[header] = _get_es_datatype(column_dp)
|
157 |
+
|
158 |
+
return {"mappings": {self.document_type: {"properties": properties}}}
|
159 |
+
|
160 |
+
def _get_body(self) -> Generator:
|
161 |
+
str_datatype = (Typecode.DATETIME, Typecode.IP_ADDRESS, Typecode.INFINITY, Typecode.NAN)
|
162 |
+
|
163 |
+
for value_dp_list in self._table_value_dp_matrix:
|
164 |
+
values = [
|
165 |
+
value_dp.data if value_dp.typecode not in str_datatype else value_dp.to_str()
|
166 |
+
for value_dp in value_dp_list
|
167 |
+
]
|
168 |
+
|
169 |
+
yield dict(zip(self.headers, values))
|
170 |
+
|
171 |
+
def _write_table(self, **kwargs: Any) -> None:
|
172 |
+
import elasticsearch as es
|
173 |
+
|
174 |
+
if not isinstance(self.stream, es.Elasticsearch):
|
175 |
+
raise ValueError("stream must be an elasticsearch.Elasticsearch instance")
|
176 |
+
|
177 |
+
try:
|
178 |
+
self._verify_value_matrix()
|
179 |
+
except EmptyValueError:
|
180 |
+
self._logger.logger.debug("no tabular data found")
|
181 |
+
return
|
182 |
+
|
183 |
+
self._preprocess()
|
184 |
+
|
185 |
+
mappings = self._get_mappings()
|
186 |
+
|
187 |
+
try:
|
188 |
+
result = self.stream.indices.create(index=self.index_name, body=mappings)
|
189 |
+
self._logger.logger.debug(result)
|
190 |
+
except es.TransportError as e:
|
191 |
+
if e.error == "index_already_exists_exception":
|
192 |
+
# ignore already existing index
|
193 |
+
self._logger.logger.debug(to_error_message(e))
|
194 |
+
else:
|
195 |
+
raise
|
196 |
+
|
197 |
+
for body in self._get_body():
|
198 |
+
try:
|
199 |
+
self.stream.index(index=self.index_name, body=body, doc_type=self.document_type)
|
200 |
+
except es.exceptions.RequestError as e:
|
201 |
+
self._logger.logger.error(f"{to_error_message(e)}, body={body}")
|
202 |
+
|
203 |
+
def _write_value_row_separator(self) -> None:
|
204 |
+
pass
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/_interface.py
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
.. codeauthor:: Tsuyoshi Hombashi <[email protected]>
|
3 |
+
"""
|
4 |
+
|
5 |
+
import abc
|
6 |
+
from typing import IO, Any, Union
|
7 |
+
|
8 |
+
|
9 |
+
class TableWriterInterface(metaclass=abc.ABCMeta):
|
10 |
+
"""
|
11 |
+
Interface class for writing a table.
|
12 |
+
"""
|
13 |
+
|
14 |
+
@abc.abstractproperty
|
15 |
+
def format_name(self) -> str: # pragma: no cover
|
16 |
+
"""Format name for the writer.
|
17 |
+
|
18 |
+
Returns:
|
19 |
+
|str|
|
20 |
+
"""
|
21 |
+
|
22 |
+
@abc.abstractproperty
|
23 |
+
def support_split_write(self) -> bool: # pragma: no cover
|
24 |
+
"""Indicates whether the writer class supports iterative table writing (``write_table_iter``) method.
|
25 |
+
|
26 |
+
Returns:
|
27 |
+
bool: |True| if the writer supported iterative table writing.
|
28 |
+
"""
|
29 |
+
|
30 |
+
@abc.abstractmethod
|
31 |
+
def write_table(self, **kwargs: Any) -> None: # pragma: no cover
|
32 |
+
"""
|
33 |
+
|write_table|.
|
34 |
+
"""
|
35 |
+
|
36 |
+
def dump(
|
37 |
+
self, output: Union[str, IO], close_after_write: bool, **kwargs: Any
|
38 |
+
) -> None: # pragma: no cover
|
39 |
+
raise NotImplementedError(f"{self.format_name} writer did not support dump method")
|
40 |
+
|
41 |
+
def dumps(self) -> str: # pragma: no cover
|
42 |
+
raise NotImplementedError(f"{self.format_name} writer did not support dumps method")
|
43 |
+
|
44 |
+
def write_table_iter(self, **kwargs: Any) -> None: # pragma: no cover
|
45 |
+
"""
|
46 |
+
Write a table with iteration.
|
47 |
+
"Iteration" means that divide the table writing into multiple writes.
|
48 |
+
This method is helpful, especially for extensive data.
|
49 |
+
The following are the premises to execute this method:
|
50 |
+
|
51 |
+
- set iterator to the |value_matrix|
|
52 |
+
- set the number of iterations to the |iteration_length| attribute
|
53 |
+
|
54 |
+
Call back function (Optional):
|
55 |
+
A callback function is called when each iteration of writing a table is completed.
|
56 |
+
You can set a callback function via the |write_callback| attribute.
|
57 |
+
|
58 |
+
Raises:
|
59 |
+
pytablewriter.NotSupportedError: If the writer class does not support this method.
|
60 |
+
|
61 |
+
.. note::
|
62 |
+
The following classes do not support this method:
|
63 |
+
|
64 |
+
- |HtmlTableWriter|
|
65 |
+
- |RstGridTableWriter|
|
66 |
+
- |RstSimpleTableWriter|
|
67 |
+
|
68 |
+
``support_split_write`` attribute return |True| if the class
|
69 |
+
is supporting this method.
|
70 |
+
"""
|
71 |
+
|
72 |
+
self._write_table_iter(**kwargs)
|
73 |
+
|
74 |
+
@abc.abstractmethod
|
75 |
+
def _write_table_iter(self, **kwargs: Any) -> None: # pragma: no cover
|
76 |
+
pass
|
77 |
+
|
78 |
+
@abc.abstractmethod
|
79 |
+
def close(self) -> None: # pragma: no cover
|
80 |
+
pass
|
81 |
+
|
82 |
+
@abc.abstractmethod
|
83 |
+
def _write_value_row_separator(self) -> None: # pragma: no cover
|
84 |
+
pass
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/_null.py
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
.. codeauthor:: Tsuyoshi Hombashi <[email protected]>
|
3 |
+
"""
|
4 |
+
|
5 |
+
from typing import IO, Any, Union
|
6 |
+
|
7 |
+
from ._interface import TableWriterInterface
|
8 |
+
from .text._interface import IndentationInterface, TextWriterInterface
|
9 |
+
|
10 |
+
|
11 |
+
class NullTableWriter(IndentationInterface, TextWriterInterface, TableWriterInterface):
|
12 |
+
FORMAT_NAME = "null"
|
13 |
+
|
14 |
+
def __init__(self, **kwargs: Any) -> None:
|
15 |
+
self.table_name = kwargs.get("table_name", "")
|
16 |
+
self.value_matrix = kwargs.get("value_matrix", [])
|
17 |
+
self.is_formatting_float = kwargs.get("is_formatting_float", True)
|
18 |
+
self.headers = kwargs.get("headers", [])
|
19 |
+
self.type_hints = kwargs.get("type_hints", [])
|
20 |
+
self.max_workers = kwargs.get("max_workers", 1)
|
21 |
+
|
22 |
+
def __repr__(self) -> str:
|
23 |
+
return self.dumps()
|
24 |
+
|
25 |
+
@property
|
26 |
+
def format_name(self) -> str:
|
27 |
+
return self.FORMAT_NAME
|
28 |
+
|
29 |
+
@property
|
30 |
+
def support_split_write(self) -> bool:
|
31 |
+
return True
|
32 |
+
|
33 |
+
def set_indent_level(self, indent_level: int) -> None:
|
34 |
+
pass
|
35 |
+
|
36 |
+
def inc_indent_level(self) -> None:
|
37 |
+
pass
|
38 |
+
|
39 |
+
def dec_indent_level(self) -> None:
|
40 |
+
pass
|
41 |
+
|
42 |
+
def write_null_line(self) -> None:
|
43 |
+
pass
|
44 |
+
|
45 |
+
def write_table(self, **kwargs: Any) -> None:
|
46 |
+
pass
|
47 |
+
|
48 |
+
def dump(self, output: Union[str, IO], close_after_write: bool = True, **kwargs: Any) -> None:
|
49 |
+
pass
|
50 |
+
|
51 |
+
def dumps(self) -> str:
|
52 |
+
return ""
|
53 |
+
|
54 |
+
def _write_table_iter(self, **kwargs: Any) -> None:
|
55 |
+
pass
|
56 |
+
|
57 |
+
def close(self) -> None:
|
58 |
+
pass
|
59 |
+
|
60 |
+
def _write_value_row_separator(self) -> None:
|
61 |
+
pass
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__init__.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from ._asciidoc import AsciiDocTableWriter
|
2 |
+
from ._borderless import BorderlessTableWriter
|
3 |
+
from ._css import CssTableWriter
|
4 |
+
from ._csv import CsvTableWriter
|
5 |
+
from ._html import HtmlTableWriter
|
6 |
+
from ._json import JsonTableWriter
|
7 |
+
from ._jsonlines import JsonLinesTableWriter
|
8 |
+
from ._latex import LatexMatrixWriter, LatexTableWriter
|
9 |
+
from ._ltsv import LtsvTableWriter
|
10 |
+
from ._markdown import MarkdownFlavor, MarkdownTableWriter, normalize_md_flavor
|
11 |
+
from ._mediawiki import MediaWikiTableWriter
|
12 |
+
from ._rst import RstCsvTableWriter, RstGridTableWriter, RstSimpleTableWriter
|
13 |
+
from ._spacealigned import SpaceAlignedTableWriter
|
14 |
+
from ._toml import TomlTableWriter
|
15 |
+
from ._tsv import TsvTableWriter
|
16 |
+
from ._unicode import BoldUnicodeTableWriter, UnicodeTableWriter
|
17 |
+
from ._yaml import YamlTableWriter
|
18 |
+
|
19 |
+
|
20 |
+
__all__ = (
|
21 |
+
"AsciiDocTableWriter",
|
22 |
+
"BoldUnicodeTableWriter",
|
23 |
+
"BorderlessTableWriter",
|
24 |
+
"CssTableWriter",
|
25 |
+
"CsvTableWriter",
|
26 |
+
"HtmlTableWriter",
|
27 |
+
"JsonTableWriter",
|
28 |
+
"JsonLinesTableWriter",
|
29 |
+
"LatexMatrixWriter",
|
30 |
+
"LatexTableWriter",
|
31 |
+
"LtsvTableWriter",
|
32 |
+
"MarkdownFlavor",
|
33 |
+
"MarkdownTableWriter",
|
34 |
+
"normalize_md_flavor",
|
35 |
+
"MediaWikiTableWriter",
|
36 |
+
"RstCsvTableWriter",
|
37 |
+
"RstGridTableWriter",
|
38 |
+
"RstSimpleTableWriter",
|
39 |
+
"SpaceAlignedTableWriter",
|
40 |
+
"TomlTableWriter",
|
41 |
+
"TsvTableWriter",
|
42 |
+
"UnicodeTableWriter",
|
43 |
+
"YamlTableWriter",
|
44 |
+
)
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (1.34 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_asciidoc.cpython-310.pyc
ADDED
Binary file (5.63 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_borderless.cpython-310.pyc
ADDED
Binary file (1.58 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_common.cpython-310.pyc
ADDED
Binary file (827 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_css.cpython-310.pyc
ADDED
Binary file (5.15 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_csv.cpython-310.pyc
ADDED
Binary file (2.51 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_html.cpython-310.pyc
ADDED
Binary file (5.79 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_interface.cpython-310.pyc
ADDED
Binary file (1.38 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_json.cpython-310.pyc
ADDED
Binary file (6.07 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_jsonlines.cpython-310.pyc
ADDED
Binary file (1.87 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_latex.cpython-310.pyc
ADDED
Binary file (7.85 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_ltsv.cpython-310.pyc
ADDED
Binary file (2.23 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_markdown.cpython-310.pyc
ADDED
Binary file (7.17 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_mediawiki.cpython-310.pyc
ADDED
Binary file (4.49 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_rst.cpython-310.pyc
ADDED
Binary file (8.35 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_spacealigned.cpython-310.pyc
ADDED
Binary file (1.44 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_text_writer.cpython-310.pyc
ADDED
Binary file (20.5 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_toml.cpython-310.pyc
ADDED
Binary file (3.07 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_tsv.cpython-310.pyc
ADDED
Binary file (1.03 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_unicode.cpython-310.pyc
ADDED
Binary file (3.41 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/__pycache__/_yaml.cpython-310.pyc
ADDED
Binary file (2.79 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/_asciidoc.py
ADDED
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import copy
|
2 |
+
from typing import Any, List, Sequence
|
3 |
+
|
4 |
+
import dataproperty as dp
|
5 |
+
import typepy
|
6 |
+
from dataproperty import ColumnDataProperty, DataProperty, LineBreakHandling
|
7 |
+
from mbstrdecoder import MultiByteStrDecoder
|
8 |
+
|
9 |
+
from ...style import (
|
10 |
+
Align,
|
11 |
+
FontStyle,
|
12 |
+
FontWeight,
|
13 |
+
Style,
|
14 |
+
StylerInterface,
|
15 |
+
TextStyler,
|
16 |
+
get_align_char,
|
17 |
+
)
|
18 |
+
from .._table_writer import AbstractTableWriter
|
19 |
+
from ._text_writer import TextTableWriter
|
20 |
+
|
21 |
+
|
22 |
+
class AsciiDocStyler(TextStyler):
|
23 |
+
def apply(self, value: str, style: Style) -> str:
|
24 |
+
value = super().apply(value, style)
|
25 |
+
if not value:
|
26 |
+
return value
|
27 |
+
|
28 |
+
try:
|
29 |
+
fg_color = style.fg_color.name.lower() # type: ignore
|
30 |
+
except AttributeError:
|
31 |
+
fg_color = None
|
32 |
+
|
33 |
+
try:
|
34 |
+
bg_color = style.bg_color.name.lower() # type: ignore
|
35 |
+
except AttributeError:
|
36 |
+
bg_color = None
|
37 |
+
|
38 |
+
if fg_color and bg_color:
|
39 |
+
value = f"[{fg_color} {bg_color}-background]##{value}##"
|
40 |
+
elif fg_color:
|
41 |
+
value = f"[{fg_color}]##{value}##"
|
42 |
+
elif bg_color:
|
43 |
+
value = f"[{bg_color}-background]##{value}##"
|
44 |
+
|
45 |
+
if style.font_weight == FontWeight.BOLD:
|
46 |
+
value = f"*{value}*"
|
47 |
+
|
48 |
+
if style.font_style == FontStyle.ITALIC:
|
49 |
+
value = f"_{value}_"
|
50 |
+
|
51 |
+
return value
|
52 |
+
|
53 |
+
|
54 |
+
class AsciiDocTableWriter(TextTableWriter):
|
55 |
+
"""
|
56 |
+
A table writer class for `AsciiDoc <https://asciidoc.org/>`__ format.
|
57 |
+
"""
|
58 |
+
|
59 |
+
FORMAT_NAME = "asciidoc"
|
60 |
+
|
61 |
+
@property
|
62 |
+
def format_name(self) -> str:
|
63 |
+
return self.FORMAT_NAME
|
64 |
+
|
65 |
+
@property
|
66 |
+
def support_split_write(self) -> bool:
|
67 |
+
return True
|
68 |
+
|
69 |
+
def __init__(self, **kwargs: Any) -> None:
|
70 |
+
super().__init__(**kwargs)
|
71 |
+
|
72 |
+
self.column_delimiter = "\n"
|
73 |
+
|
74 |
+
self.is_padding = False
|
75 |
+
self.is_write_header_separator_row = True
|
76 |
+
self.is_write_value_separator_row = True
|
77 |
+
self.is_write_opening_row = True
|
78 |
+
self.is_write_closing_row = True
|
79 |
+
|
80 |
+
self.update_preprocessor(line_break_handling=LineBreakHandling.NOP)
|
81 |
+
|
82 |
+
self._quoting_flags = copy.deepcopy(dp.NOT_QUOTING_FLAGS)
|
83 |
+
|
84 |
+
def _create_styler(self, writer: AbstractTableWriter) -> StylerInterface:
|
85 |
+
return AsciiDocStyler(writer)
|
86 |
+
|
87 |
+
def _write_value_row(
|
88 |
+
self, row: int, values: Sequence[str], value_dp_list: Sequence[DataProperty]
|
89 |
+
) -> None:
|
90 |
+
self._write_row(
|
91 |
+
row,
|
92 |
+
[
|
93 |
+
self.__modify_row_element(row, col_idx, value, value_dp)
|
94 |
+
for col_idx, (value, value_dp), in enumerate(zip(values, value_dp_list))
|
95 |
+
],
|
96 |
+
)
|
97 |
+
|
98 |
+
def _get_opening_row_items(self) -> List[str]:
|
99 |
+
cols = ", ".join(
|
100 |
+
f"{get_align_char(col_dp.align)}{col_dp.ascii_char_width}"
|
101 |
+
for col_dp in self._column_dp_list
|
102 |
+
)
|
103 |
+
rows = [f'[cols="{cols}", options="header"]']
|
104 |
+
|
105 |
+
if typepy.is_not_null_string(self.table_name):
|
106 |
+
rows.append("." + MultiByteStrDecoder(self.table_name).unicode_str)
|
107 |
+
|
108 |
+
rows.append("|===")
|
109 |
+
|
110 |
+
return ["\n".join(rows)]
|
111 |
+
|
112 |
+
def _get_header_row_separator_items(self) -> List[str]:
|
113 |
+
return [""]
|
114 |
+
|
115 |
+
def _get_value_row_separator_items(self) -> List[str]:
|
116 |
+
return self._get_header_row_separator_items()
|
117 |
+
|
118 |
+
def _get_closing_row_items(self) -> List[str]:
|
119 |
+
return ["|==="]
|
120 |
+
|
121 |
+
def __apply_align(self, value: str, style: Style) -> str:
|
122 |
+
return f"{get_align_char(Align.CENTER)}|{value}"
|
123 |
+
|
124 |
+
def _apply_style_to_header_item(
|
125 |
+
self, col_dp: ColumnDataProperty, value_dp: DataProperty, style: Style
|
126 |
+
) -> str:
|
127 |
+
value = self._styler.apply(col_dp.dp_to_str(value_dp), style=style)
|
128 |
+
return self.__apply_align(value, style)
|
129 |
+
|
130 |
+
def __modify_row_element(
|
131 |
+
self, row_idx: int, col_idx: int, value: str, value_dp: DataProperty
|
132 |
+
) -> str:
|
133 |
+
col_dp = self._column_dp_list[col_idx]
|
134 |
+
style = self._fetch_style(row_idx, col_dp, value_dp)
|
135 |
+
align = col_dp.align
|
136 |
+
|
137 |
+
if style and style.align and style.align != align:
|
138 |
+
forma_stirng = "{0:s}|{1:s}"
|
139 |
+
align = style.align
|
140 |
+
elif value_dp.align != align:
|
141 |
+
forma_stirng = "{0:s}|{1:s}"
|
142 |
+
align = value_dp.align
|
143 |
+
else:
|
144 |
+
forma_stirng = "|{1:s}"
|
145 |
+
|
146 |
+
return forma_stirng.format(get_align_char(align), value)
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/_borderless.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import copy
|
2 |
+
from typing import Any
|
3 |
+
|
4 |
+
import dataproperty as dp
|
5 |
+
|
6 |
+
from ._text_writer import IndentationTextTableWriter
|
7 |
+
|
8 |
+
|
9 |
+
class BorderlessTableWriter(IndentationTextTableWriter):
|
10 |
+
"""
|
11 |
+
A table writer class for borderless table.
|
12 |
+
"""
|
13 |
+
|
14 |
+
FORMAT_NAME = "borderless"
|
15 |
+
|
16 |
+
@property
|
17 |
+
def format_name(self) -> str:
|
18 |
+
return self.FORMAT_NAME
|
19 |
+
|
20 |
+
@property
|
21 |
+
def support_split_write(self) -> bool:
|
22 |
+
return True
|
23 |
+
|
24 |
+
def __init__(self, **kwargs: Any) -> None:
|
25 |
+
super().__init__(**kwargs)
|
26 |
+
|
27 |
+
self.table_name = ""
|
28 |
+
|
29 |
+
self.column_delimiter = ""
|
30 |
+
self.char_left_side_row = ""
|
31 |
+
self.char_right_side_row = ""
|
32 |
+
|
33 |
+
self.indent_string = kwargs.get("indent_string", " ")
|
34 |
+
self.is_write_header_separator_row = False
|
35 |
+
self.is_write_value_separator_row = False
|
36 |
+
self.is_write_opening_row = False
|
37 |
+
self.is_write_closing_row = False
|
38 |
+
|
39 |
+
self._quoting_flags = copy.deepcopy(dp.NOT_QUOTING_FLAGS)
|
40 |
+
|
41 |
+
self._init_cross_point_maps()
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/_common.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from decimal import Decimal
|
2 |
+
from typing import Any
|
3 |
+
|
4 |
+
from dataproperty import DataProperty
|
5 |
+
from typepy import Typecode
|
6 |
+
|
7 |
+
|
8 |
+
def bool_to_str(value: Any) -> Any:
|
9 |
+
if value is True:
|
10 |
+
return "true"
|
11 |
+
if value is False:
|
12 |
+
return "false"
|
13 |
+
|
14 |
+
return value
|
15 |
+
|
16 |
+
|
17 |
+
def serialize_dp(dp: DataProperty) -> Any:
|
18 |
+
if dp.typecode in (Typecode.REAL_NUMBER, Typecode.INFINITY, Typecode.NAN) and isinstance(
|
19 |
+
dp.data, Decimal
|
20 |
+
):
|
21 |
+
return float(dp.data)
|
22 |
+
|
23 |
+
if dp.typecode == Typecode.DATETIME:
|
24 |
+
return dp.to_str()
|
25 |
+
|
26 |
+
return dp.data
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/_css.py
ADDED
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import copy
|
2 |
+
from typing import Any, List, cast
|
3 |
+
|
4 |
+
from dataproperty import NOT_QUOTING_FLAGS, DataProperty
|
5 |
+
from pathvalidate import replace_symbol
|
6 |
+
|
7 |
+
from ...error import EmptyTableDataError
|
8 |
+
from ...style import Align, DecorationLine, FontStyle, FontWeight, Style, VerticalAlign
|
9 |
+
from .._common import HEADER_ROW
|
10 |
+
from ._text_writer import IndentationTextTableWriter
|
11 |
+
|
12 |
+
|
13 |
+
class CssTableWriter(IndentationTextTableWriter):
|
14 |
+
"""
|
15 |
+
A CSS writer class.
|
16 |
+
"""
|
17 |
+
|
18 |
+
FORMAT_NAME = "css"
|
19 |
+
MARGIN_PIXEL = 6
|
20 |
+
|
21 |
+
@property
|
22 |
+
def format_name(self) -> str:
|
23 |
+
return self.FORMAT_NAME
|
24 |
+
|
25 |
+
@property
|
26 |
+
def support_split_write(self) -> bool:
|
27 |
+
return False
|
28 |
+
|
29 |
+
def __init__(self, **kwargs: Any) -> None:
|
30 |
+
super().__init__(**kwargs)
|
31 |
+
|
32 |
+
self.is_padding = False
|
33 |
+
self.indent_string = kwargs.get("indent_string", " ")
|
34 |
+
|
35 |
+
self._dp_extractor.preprocessor.is_escape_html_tag = False
|
36 |
+
self._quoting_flags = copy.deepcopy(NOT_QUOTING_FLAGS)
|
37 |
+
|
38 |
+
def write_table(self, **kwargs: Any) -> None:
|
39 |
+
"""
|
40 |
+
|write_table| with CSS.
|
41 |
+
"""
|
42 |
+
|
43 |
+
with self._logger:
|
44 |
+
try:
|
45 |
+
self._verify_property()
|
46 |
+
except EmptyTableDataError:
|
47 |
+
self._logger.logger.debug("no tabular data found")
|
48 |
+
return
|
49 |
+
|
50 |
+
self._preprocess()
|
51 |
+
|
52 |
+
self.__write_css(
|
53 |
+
css_class=replace_symbol(self.table_name, replacement_text="-"),
|
54 |
+
write_style_tag=kwargs.get("write_style_tag", False),
|
55 |
+
)
|
56 |
+
|
57 |
+
def __extract_css_tags(self, value_dp: DataProperty, style: Style) -> List[str]:
|
58 |
+
css_tags: List[str] = []
|
59 |
+
|
60 |
+
if self._styler.get_font_size(style):
|
61 |
+
css_tags.append(cast(str, self._styler.get_font_size(style)))
|
62 |
+
if style.font_weight == FontWeight.BOLD:
|
63 |
+
css_tags.append("font-weight:bold")
|
64 |
+
if style.font_style == FontStyle.ITALIC:
|
65 |
+
css_tags.append("font-style:italic")
|
66 |
+
|
67 |
+
if style.color:
|
68 |
+
css_tags.append(f"color: {style.color.color_code}")
|
69 |
+
|
70 |
+
if style.bg_color:
|
71 |
+
css_tags.append(f"background-color: {style.bg_color.color_code}")
|
72 |
+
|
73 |
+
css_tag = self.__extract_align_tag(value_dp, style)
|
74 |
+
if css_tag:
|
75 |
+
css_tags.append(css_tag)
|
76 |
+
|
77 |
+
if style.vertical_align != VerticalAlign.BASELINE:
|
78 |
+
css_tags.append(f"vertical-align: {style.vertical_align.align_str}")
|
79 |
+
|
80 |
+
if style.decoration_line in (DecorationLine.LINE_THROUGH, DecorationLine.STRIKE):
|
81 |
+
css_tags.append("text-decoration-line: line-through")
|
82 |
+
elif style.decoration_line == DecorationLine.UNDERLINE:
|
83 |
+
css_tags.append("text-decoration-line: underline")
|
84 |
+
|
85 |
+
if self.margin > 0:
|
86 |
+
css_tags.append(f"padding: {self.margin * self.MARGIN_PIXEL}px")
|
87 |
+
|
88 |
+
return css_tags
|
89 |
+
|
90 |
+
def __extract_align_tag(self, value_dp: DataProperty, style: Style) -> str:
|
91 |
+
if style.align == Align.AUTO:
|
92 |
+
value = value_dp.align.align_string
|
93 |
+
else:
|
94 |
+
value = style.align.align_string
|
95 |
+
|
96 |
+
return f"text-align: {value}"
|
97 |
+
|
98 |
+
def __write_css_thead(self, css_class: str, base_indent_level: int) -> None:
|
99 |
+
for col_dp, header_dp in zip(self._column_dp_list, self._dp_extractor.to_header_dp_list()):
|
100 |
+
style = self._fetch_style(HEADER_ROW, col_dp, header_dp)
|
101 |
+
css_tags = self.__extract_css_tags(header_dp, style)
|
102 |
+
|
103 |
+
if not css_tags:
|
104 |
+
continue
|
105 |
+
|
106 |
+
self.set_indent_level(base_indent_level)
|
107 |
+
self._write_line(
|
108 |
+
".{css_class} thead th:nth-child({col}) {{".format(
|
109 |
+
css_class=css_class, col=col_dp.column_index + 1
|
110 |
+
)
|
111 |
+
)
|
112 |
+
|
113 |
+
self.set_indent_level(base_indent_level + 1)
|
114 |
+
for css_tag in css_tags:
|
115 |
+
self._write_line(f"{css_tag};")
|
116 |
+
|
117 |
+
self.set_indent_level(base_indent_level)
|
118 |
+
self._write_line("}")
|
119 |
+
|
120 |
+
def __write_css_tbody(self, css_class: str, base_indent_level: int) -> None:
|
121 |
+
for row_idx, (values, value_dp_list) in enumerate(
|
122 |
+
zip(self._table_value_matrix, self._table_value_dp_matrix)
|
123 |
+
):
|
124 |
+
for value, value_dp, col_dp in zip(values, value_dp_list, self._column_dp_list):
|
125 |
+
style = self._fetch_style(row_idx, col_dp, value_dp)
|
126 |
+
css_tags = self.__extract_css_tags(value_dp, style)
|
127 |
+
|
128 |
+
if not css_tags:
|
129 |
+
continue
|
130 |
+
|
131 |
+
self.set_indent_level(base_indent_level)
|
132 |
+
self._write_line(
|
133 |
+
".{css_class} tbody tr:nth-child({row}) td:nth-child({col}) {{".format(
|
134 |
+
css_class=css_class, row=row_idx + 1, col=col_dp.column_index + 1
|
135 |
+
)
|
136 |
+
)
|
137 |
+
|
138 |
+
self.set_indent_level(base_indent_level + 1)
|
139 |
+
for css_tag in css_tags:
|
140 |
+
self._write_line(f"{css_tag};")
|
141 |
+
|
142 |
+
self.set_indent_level(base_indent_level)
|
143 |
+
self._write_line("}")
|
144 |
+
|
145 |
+
def __write_css(self, css_class: str, write_style_tag: bool = False) -> None:
|
146 |
+
base_indent_level = 0
|
147 |
+
|
148 |
+
if write_style_tag:
|
149 |
+
self._write_line('<style type="text/css">')
|
150 |
+
base_indent_level = 1
|
151 |
+
|
152 |
+
self.__write_css_thead(css_class, base_indent_level)
|
153 |
+
self.__write_css_tbody(css_class, base_indent_level)
|
154 |
+
|
155 |
+
if write_style_tag:
|
156 |
+
self.set_indent_level(0)
|
157 |
+
self._write_line("</style>")
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/_csv.py
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Any, List
|
2 |
+
|
3 |
+
import typepy
|
4 |
+
|
5 |
+
from ._text_writer import TextTableWriter
|
6 |
+
|
7 |
+
|
8 |
+
class CsvTableWriter(TextTableWriter):
|
9 |
+
"""
|
10 |
+
A table writer class for character separated values format.
|
11 |
+
The default separated character is a comma (``","``).
|
12 |
+
|
13 |
+
:Example:
|
14 |
+
:ref:`example-csv-table-writer`
|
15 |
+
"""
|
16 |
+
|
17 |
+
FORMAT_NAME = "csv"
|
18 |
+
|
19 |
+
@property
|
20 |
+
def format_name(self) -> str:
|
21 |
+
return self.FORMAT_NAME
|
22 |
+
|
23 |
+
@property
|
24 |
+
def support_split_write(self) -> bool:
|
25 |
+
return True
|
26 |
+
|
27 |
+
@property
|
28 |
+
def margin(self) -> int:
|
29 |
+
return self._margin
|
30 |
+
|
31 |
+
@margin.setter
|
32 |
+
def margin(self, value: int) -> None:
|
33 |
+
# margin setting must be ignored
|
34 |
+
return
|
35 |
+
|
36 |
+
def __init__(self, **kwargs: Any) -> None:
|
37 |
+
super().__init__(**kwargs)
|
38 |
+
|
39 |
+
self._set_chars("")
|
40 |
+
self.indent_string = ""
|
41 |
+
self.column_delimiter = kwargs.get("column_delimiter", ",")
|
42 |
+
self._margin = 0
|
43 |
+
|
44 |
+
self.is_padding = False
|
45 |
+
self.is_formatting_float = False
|
46 |
+
self.is_write_header_separator_row = False
|
47 |
+
|
48 |
+
self._quoting_flags[typepy.Typecode.NULL_STRING] = False
|
49 |
+
|
50 |
+
def _write_header(self) -> None:
|
51 |
+
if typepy.is_empty_sequence(self.headers):
|
52 |
+
return
|
53 |
+
|
54 |
+
super()._write_header()
|
55 |
+
|
56 |
+
def _get_opening_row_items(self) -> List[str]:
|
57 |
+
return []
|
58 |
+
|
59 |
+
def _get_value_row_separator_items(self) -> List[str]:
|
60 |
+
return []
|
61 |
+
|
62 |
+
def _get_closing_row_items(self) -> List[str]:
|
63 |
+
return []
|
llmeval-env/lib/python3.10/site-packages/pytablewriter/writer/text/_html.py
ADDED
@@ -0,0 +1,194 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import copy
|
2 |
+
import warnings
|
3 |
+
from typing import Any, List, Optional, Tuple, cast
|
4 |
+
|
5 |
+
import dataproperty
|
6 |
+
import typepy
|
7 |
+
from mbstrdecoder import MultiByteStrDecoder
|
8 |
+
from pathvalidate import replace_symbol
|
9 |
+
|
10 |
+
from ...error import EmptyTableDataError
|
11 |
+
from ...sanitizer import sanitize_python_var_name
|
12 |
+
from ...style import Align, FontStyle, FontWeight, HtmlStyler, Style, StylerInterface, VerticalAlign
|
13 |
+
from .._common import import_error_msg_template
|
14 |
+
from .._table_writer import AbstractTableWriter
|
15 |
+
from ._css import CssTableWriter
|
16 |
+
from ._text_writer import TextTableWriter
|
17 |
+
|
18 |
+
|
19 |
+
def _get_tags_module() -> Tuple:
|
20 |
+
try:
|
21 |
+
from dominate import tags
|
22 |
+
from dominate.util import raw
|
23 |
+
|
24 |
+
return tags, raw
|
25 |
+
except ImportError:
|
26 |
+
warnings.warn(import_error_msg_template.format("html"))
|
27 |
+
raise
|
28 |
+
|
29 |
+
|
30 |
+
class HtmlTableWriter(TextTableWriter):
|
31 |
+
"""
|
32 |
+
A table writer class for HTML format.
|
33 |
+
|
34 |
+
:Example:
|
35 |
+
:ref:`example-html-table-writer`
|
36 |
+
"""
|
37 |
+
|
38 |
+
FORMAT_NAME = "html"
|
39 |
+
|
40 |
+
@property
|
41 |
+
def format_name(self) -> str:
|
42 |
+
return self.FORMAT_NAME
|
43 |
+
|
44 |
+
@property
|
45 |
+
def support_split_write(self) -> bool:
|
46 |
+
return False
|
47 |
+
|
48 |
+
def __init__(self, **kwargs: Any) -> None:
|
49 |
+
super().__init__(**kwargs)
|
50 |
+
|
51 |
+
self.is_padding = False
|
52 |
+
self.indent_string = kwargs.get("indent_string", " ")
|
53 |
+
|
54 |
+
self._dp_extractor.preprocessor.line_break_repl = "<br>"
|
55 |
+
self._dp_extractor.preprocessor.is_escape_html_tag = False
|
56 |
+
self._quoting_flags = copy.deepcopy(dataproperty.NOT_QUOTING_FLAGS)
|
57 |
+
self._table_tag: Any = None
|
58 |
+
|
59 |
+
self.enable_ansi_escape = False
|
60 |
+
|
61 |
+
def write_table(self, **kwargs: Any) -> None:
|
62 |
+
"""
|
63 |
+
|write_table| with HTML table format.
|
64 |
+
|
65 |
+
Args:
|
66 |
+
write_css (bool):
|
67 |
+
If |True|, write CSS corresponding to the specified styles,
|
68 |
+
instead of attributes of HTML tags.
|
69 |
+
|
70 |
+
Example:
|
71 |
+
:ref:`example-html-table-writer`
|
72 |
+
|
73 |
+
.. note::
|
74 |
+
- |None| values will be replaced with an empty value
|
75 |
+
"""
|
76 |
+
|
77 |
+
tags, raw = _get_tags_module()
|
78 |
+
write_css: bool = kwargs.get("write_css", False)
|
79 |
+
|
80 |
+
with self._logger:
|
81 |
+
try:
|
82 |
+
self._verify_property()
|
83 |
+
except EmptyTableDataError:
|
84 |
+
self._logger.logger.debug("no tabular data found")
|
85 |
+
return
|
86 |
+
|
87 |
+
self._preprocess()
|
88 |
+
|
89 |
+
css_class: Optional[str] = None
|
90 |
+
|
91 |
+
if write_css:
|
92 |
+
default_css_class_name = replace_symbol(self.table_name, replacement_text="-")
|
93 |
+
if default_css_class_name:
|
94 |
+
default_css_class_name += "-css"
|
95 |
+
else:
|
96 |
+
default_css_class_name = "ptw-table-css"
|
97 |
+
|
98 |
+
css_class = kwargs.get("css_class", default_css_class_name)
|
99 |
+
css_writer = CssTableWriter(
|
100 |
+
table_name=css_class,
|
101 |
+
margin=self.margin,
|
102 |
+
stream=self.stream,
|
103 |
+
)
|
104 |
+
css_writer.from_writer(self, is_overwrite_table_name=False)
|
105 |
+
css_writer.write_table(write_style_tag=True)
|
106 |
+
|
107 |
+
if typepy.is_not_null_string(self.table_name):
|
108 |
+
if css_class:
|
109 |
+
self._table_tag = tags.table(
|
110 |
+
id=sanitize_python_var_name(self.table_name), class_name=css_class
|
111 |
+
)
|
112 |
+
else:
|
113 |
+
self._table_tag = tags.table(id=sanitize_python_var_name(self.table_name))
|
114 |
+
self._table_tag += tags.caption(MultiByteStrDecoder(self.table_name).unicode_str)
|
115 |
+
else:
|
116 |
+
if css_class:
|
117 |
+
self._table_tag = tags.table(class_name=css_class)
|
118 |
+
else:
|
119 |
+
self._table_tag = tags.table()
|
120 |
+
|
121 |
+
try:
|
122 |
+
self._write_header()
|
123 |
+
except ValueError:
|
124 |
+
pass
|
125 |
+
|
126 |
+
self._write_body(not write_css)
|
127 |
+
|
128 |
+
def _write_header(self) -> None:
|
129 |
+
tags, raw = _get_tags_module()
|
130 |
+
|
131 |
+
if not self.is_write_header:
|
132 |
+
return
|
133 |
+
|
134 |
+
if typepy.is_empty_sequence(self._table_headers):
|
135 |
+
raise ValueError("headers is empty")
|
136 |
+
|
137 |
+
tr_tag = tags.tr()
|
138 |
+
for header in self._table_headers:
|
139 |
+
tr_tag += tags.th(raw(MultiByteStrDecoder(header).unicode_str))
|
140 |
+
|
141 |
+
thead_tag = tags.thead()
|
142 |
+
thead_tag += tr_tag
|
143 |
+
|
144 |
+
self._table_tag += thead_tag
|
145 |
+
|
146 |
+
def _write_body(self, write_attr: bool) -> None:
|
147 |
+
tags, raw = _get_tags_module()
|
148 |
+
tbody_tag = tags.tbody()
|
149 |
+
|
150 |
+
for row_idx, (values, value_dp_list) in enumerate(
|
151 |
+
zip(self._table_value_matrix, self._table_value_dp_matrix)
|
152 |
+
):
|
153 |
+
tr_tag = tags.tr()
|
154 |
+
for value, value_dp, column_dp in zip(values, value_dp_list, self._column_dp_list):
|
155 |
+
td_tag = tags.td(raw(MultiByteStrDecoder(value).unicode_str))
|
156 |
+
|
157 |
+
style = self._fetch_style(row_idx, column_dp, value_dp)
|
158 |
+
|
159 |
+
if write_attr:
|
160 |
+
if style.align == Align.AUTO:
|
161 |
+
td_tag["align"] = value_dp.align.align_string
|
162 |
+
else:
|
163 |
+
td_tag["align"] = style.align.align_string
|
164 |
+
|
165 |
+
if style.vertical_align != VerticalAlign.BASELINE:
|
166 |
+
td_tag["valign"] = style.vertical_align.align_str
|
167 |
+
|
168 |
+
style_tag = self.__make_style_tag(style=style)
|
169 |
+
if style_tag:
|
170 |
+
td_tag["style"] = style_tag
|
171 |
+
|
172 |
+
tr_tag += td_tag
|
173 |
+
tbody_tag += tr_tag
|
174 |
+
|
175 |
+
self._table_tag += tbody_tag
|
176 |
+
self._write_line(self._table_tag.render(indent=self.indent_string))
|
177 |
+
|
178 |
+
def __make_style_tag(self, style: Style) -> Optional[str]:
|
179 |
+
styles: List[str] = []
|
180 |
+
|
181 |
+
if self._styler.get_font_size(style):
|
182 |
+
styles.append(cast(str, self._styler.get_font_size(style)))
|
183 |
+
if style.font_weight == FontWeight.BOLD:
|
184 |
+
styles.append("font-weight:bold")
|
185 |
+
if style.font_style == FontStyle.ITALIC:
|
186 |
+
styles.append("font-style:italic")
|
187 |
+
|
188 |
+
if not styles:
|
189 |
+
return None
|
190 |
+
|
191 |
+
return "; ".join(styles)
|
192 |
+
|
193 |
+
def _create_styler(self, writer: AbstractTableWriter) -> StylerInterface:
|
194 |
+
return HtmlStyler(writer)
|