Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.__validate_attr("align", Align)
self.__font_size = normalize_enum(kwargs.pop("font_size", FontSize.NONE), FontSize)
self.__validate_attr("font_size", FontSize)
self.__font_style = normalize_enum(kwargs.pop("font_style", FontStyle.NORMAL), FontStyle)
self.__validate_attr("font_style", FontStyle)
self.__font_weight = normalize_enum(
kwargs.pop("font_weight", FontWeight.NORMAL), FontWeight
)
self.__validate_attr("font_weight", FontWeight)
self.__thousand_separator = self.__normalie_thousand_separator(
normalize_enum(
kwargs.pop("thousand_separator", ThousandSeparator.NONE), ThousandSeparator
)
)
self.__validate_attr("thousand_separator", ThousandSeparator)
def __normalie_thousand_separator(value):
if isinstance(value, ThousandSeparator):
return value
norm_value = _s_to_ts.get(value)
if norm_value is None:
return value
return norm_value
def __repr__(self):
items = []
if self.align:
items.append("align={}".format(self.align.align_string))
if self.font_size is not FontSize.NONE:
items.append("font_size={}".format(self.font_size.value))
if self.font_style:
items.append("font_style={}".format(self.font_style.value))
if self.font_weight:
items.append("font_weight={}".format(self.font_weight.value))
if self.thousand_separator is not ThousandSeparator.NONE:
items.append("thousand_separator={}".format(self.thousand_separator.value))
return "({})".format(", ".join(items))
def additional_char_width(self):
from ..writer import RstCsvTableWriter
width = 0
if self._style.font_weight == FontWeight.BOLD:
width += 4
elif self._style.font_style == FontStyle.ITALIC:
width += 2
if (
self._style.thousand_separator == ThousandSeparator.COMMA
and self._writer.format_name == RstCsvTableWriter.FORMAT_NAME
):
width += 2
return width
from enum import Enum, unique
from dataproperty import Align
from .._function import normalize_enum
from ._font import FontSize, FontStyle, FontWeight
@unique
class ThousandSeparator(Enum):
NONE = "none"
COMMA = "comma"
SPACE = "space"
_s_to_ts = {"": ThousandSeparator.NONE, ",": ThousandSeparator.COMMA, " ": ThousandSeparator.SPACE}
class Style(object):
"""Style specifier class for table elements.
Args:
align (str / pytablewriter.Align):
Text alignment specification for cells in a column.
This can be only applied for text format writer classes.
Possible values are:
- ``"auto"``/``pytablewriter.Align.AUTO``
- Detect data type for each column and set alignment that appropriate
for the type automatically
- ``"left"``/``pytablewriter.Align.LEFT``
- ``"right"``/``pytablewriter.Align.RIGHT``
def apply(self, value):
if value and self._style.thousand_separator == ThousandSeparator.SPACE:
value = value.replace(",", " ")
return value
self.__validate_attr("font_size", FontSize)
self.__font_style = normalize_enum(kwargs.pop("font_style", FontStyle.NORMAL), FontStyle)
self.__validate_attr("font_style", FontStyle)
self.__font_weight = normalize_enum(
kwargs.pop("font_weight", FontWeight.NORMAL), FontWeight
)
self.__validate_attr("font_weight", FontWeight)
self.__thousand_separator = self.__normalie_thousand_separator(
normalize_enum(
kwargs.pop("thousand_separator", ThousandSeparator.NONE), ThousandSeparator
)
)
self.__validate_attr("thousand_separator", ThousandSeparator)