|
|
@@ -54,20 +54,23 @@ class StrMixin:
|
|
|
def str(self):
|
|
|
return self._to_str()
|
|
|
|
|
|
- def _to_str(self):
|
|
|
- return str(self)
|
|
|
+ def _to_str(self, data, json_format=False, indent=4, ensure_ascii=False):
|
|
|
+ if json_format:
|
|
|
+ return json.dumps(data.json, indent=indent, ensure_ascii=ensure_ascii)
|
|
|
+ else:
|
|
|
+ return str(data)
|
|
|
|
|
|
def print(self, json_format=False, indent=4, ensure_ascii=False):
|
|
|
- str_ = self._to_str()
|
|
|
- if json_format:
|
|
|
- str_ = json.dumps(str_, indent=indent, ensure_ascii=ensure_ascii)
|
|
|
+ str_ = self._to_str(
|
|
|
+ self, json_format=json_format, indent=indent, ensure_ascii=ensure_ascii
|
|
|
+ )
|
|
|
logging.info(str_)
|
|
|
|
|
|
|
|
|
class JsonMixin:
|
|
|
def __init__(self):
|
|
|
self._json_writer = JsonWriter()
|
|
|
- self._show_func_register()(self.save_to_json)
|
|
|
+ self._show_funcs.append(self.save_to_json)
|
|
|
|
|
|
def _to_json(self):
|
|
|
def _format_data(obj):
|
|
|
@@ -109,7 +112,7 @@ class JsonMixin:
|
|
|
class Base64Mixin:
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
self._base64_writer = TextWriter(*args, **kwargs)
|
|
|
- self._show_func_register()(self.save_to_base64)
|
|
|
+ self._show_funcs.append(self.save_to_base64)
|
|
|
|
|
|
@abstractmethod
|
|
|
def _to_base64(self):
|
|
|
@@ -131,7 +134,7 @@ class Base64Mixin:
|
|
|
class ImgMixin:
|
|
|
def __init__(self, backend="pillow", *args, **kwargs):
|
|
|
self._img_writer = ImageWriter(backend=backend, *args, **kwargs)
|
|
|
- self._show_func_register()(self.save_to_img)
|
|
|
+ self._show_funcs.append(self.save_to_img)
|
|
|
|
|
|
@abstractmethod
|
|
|
def _to_img(self):
|
|
|
@@ -155,7 +158,7 @@ class ImgMixin:
|
|
|
class CSVMixin:
|
|
|
def __init__(self, backend="pandas", *args, **kwargs):
|
|
|
self._csv_writer = CSVWriter(backend=backend, *args, **kwargs)
|
|
|
- self._show_func_register()(self.save_to_csv)
|
|
|
+ self._show_funcs.append(self.save_to_csv)
|
|
|
|
|
|
@abstractmethod
|
|
|
def _to_csv(self):
|
|
|
@@ -172,7 +175,7 @@ class CSVMixin:
|
|
|
class HtmlMixin:
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
self._html_writer = HtmlWriter(*args, **kwargs)
|
|
|
- self._show_func_register()(self.save_to_html)
|
|
|
+ self._show_funcs.append(self.save_to_html)
|
|
|
|
|
|
@property
|
|
|
def html(self):
|
|
|
@@ -190,7 +193,7 @@ class HtmlMixin:
|
|
|
class XlsxMixin:
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
self._xlsx_writer = XlsxWriter(*args, **kwargs)
|
|
|
- self._show_func_register()(self.save_to_xlsx)
|
|
|
+ self._show_funcs.append(self.save_to_xlsx)
|
|
|
|
|
|
def _to_xlsx(self):
|
|
|
return self["html"]
|