zstdlib 0.0.7__tar.gz → 0.0.9__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. {zstdlib-0.0.7 → zstdlib-0.0.9}/PKG-INFO +1 -1
  2. {zstdlib-0.0.7 → zstdlib-0.0.9}/tests/log/test_cute.py +22 -0
  3. {zstdlib-0.0.7 → zstdlib-0.0.9}/zstdlib/__init__.py +1 -1
  4. {zstdlib-0.0.7 → zstdlib-0.0.9}/zstdlib/ansi.py +6 -0
  5. {zstdlib-0.0.7 → zstdlib-0.0.9}/zstdlib/log/cute.py +33 -25
  6. {zstdlib-0.0.7 → zstdlib-0.0.9}/zstdlib.egg-info/PKG-INFO +1 -1
  7. {zstdlib-0.0.7 → zstdlib-0.0.9}/LICENSE +0 -0
  8. {zstdlib-0.0.7 → zstdlib-0.0.9}/README.md +0 -0
  9. {zstdlib-0.0.7 → zstdlib-0.0.9}/pyproject.toml +0 -0
  10. {zstdlib-0.0.7 → zstdlib-0.0.9}/setup.cfg +0 -0
  11. {zstdlib-0.0.7 → zstdlib-0.0.9}/tests/__init__.py +0 -0
  12. {zstdlib-0.0.7 → zstdlib-0.0.9}/tests/log/__init__.py +0 -0
  13. {zstdlib-0.0.7 → zstdlib-0.0.9}/tests/log/base.py +0 -0
  14. {zstdlib-0.0.7 → zstdlib-0.0.9}/tests/log/test_trace.py +0 -0
  15. {zstdlib-0.0.7 → zstdlib-0.0.9}/tests/not_set.py +0 -0
  16. {zstdlib-0.0.7 → zstdlib-0.0.9}/tests/test_ansi.py +0 -0
  17. {zstdlib-0.0.7 → zstdlib-0.0.9}/tests/test_enum.py +0 -0
  18. {zstdlib-0.0.7 → zstdlib-0.0.9}/tests/test_frozen.py +0 -0
  19. {zstdlib-0.0.7 → zstdlib-0.0.9}/tests/test_singleton.py +0 -0
  20. {zstdlib-0.0.7 → zstdlib-0.0.9}/zstdlib/enum.py +0 -0
  21. {zstdlib-0.0.7 → zstdlib-0.0.9}/zstdlib/frozen.py +0 -0
  22. {zstdlib-0.0.7 → zstdlib-0.0.9}/zstdlib/log/__init__.py +0 -0
  23. {zstdlib-0.0.7 → zstdlib-0.0.9}/zstdlib/log/trace.py +0 -0
  24. {zstdlib-0.0.7 → zstdlib-0.0.9}/zstdlib/not_set.py +0 -0
  25. {zstdlib-0.0.7 → zstdlib-0.0.9}/zstdlib/py.typed +0 -0
  26. {zstdlib-0.0.7 → zstdlib-0.0.9}/zstdlib/singleton.py +0 -0
  27. {zstdlib-0.0.7 → zstdlib-0.0.9}/zstdlib.egg-info/SOURCES.txt +0 -0
  28. {zstdlib-0.0.7 → zstdlib-0.0.9}/zstdlib.egg-info/dependency_links.txt +0 -0
  29. {zstdlib-0.0.7 → zstdlib-0.0.9}/zstdlib.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: zstdlib
3
- Version: 0.0.7
3
+ Version: 0.0.9
4
4
  Summary: A set of useful python utilities
5
5
  License: GPLv3
6
6
  Project-URL: Homepage, https://github.com/zwimer/zstdlib
@@ -78,6 +78,28 @@ class TestCuteFormatter(LeftBase, unittest.TestCase):
78
78
  self.assertEqual(Color.bright_red_bg_yellow("CRITICAL".ljust(8)), l_name(5))
79
79
  self.assertEqual(Color.bright_red_bg_yellow("Level 60".ljust(8)), l_name(6))
80
80
 
81
+ def test_custom_dim_level(self) -> None:
82
+ name = "TestCuteFormatter.test_dim_level"
83
+ msg = "test"
84
+ with self.hijack(name, fmt=CuteFormatter(dim_level=5)) as log:
85
+ log.log(4, msg)
86
+ log.log(5, msg)
87
+ self.assertEqual(2, len(self.messages[log]))
88
+ l_name = lambda idx: self.messages[log][idx].split("|")[0].strip()
89
+ self.assertEqual(Color.dim("Level 4".ljust(8)), l_name(0))
90
+ self.assertEqual("Level 5", l_name(1))
91
+
92
+ def test_custom_level_color(self) -> None:
93
+ name = "TestCuteFormatter.test_custom_level_color"
94
+ msg = "test"
95
+ with self.hijack(name, fmt=CuteFormatter(level_colors={15: Color.bright_red_bg_yellow})) as log:
96
+ log.log(14, msg)
97
+ log.log(15, msg)
98
+ self.assertEqual(2, len(self.messages[log]))
99
+ l_name = lambda idx: self.messages[log][idx].split("|")[0].strip()
100
+ self.assertEqual("Level 14".ljust(8), l_name(0))
101
+ self.assertEqual(Color.bright_red_bg_yellow("Level 15".ljust(8)), l_name(1))
102
+
81
103
  def test_exception(self) -> None:
82
104
  name = "TestCuteFormatter.test_exception"
83
105
  with self.hijack(name, fmt=CuteFormatter()) as log:
@@ -1,4 +1,4 @@
1
- __version__ = "0.0.7"
1
+ __version__ = "0.0.9"
2
2
 
3
3
  from .not_set import NotSetType, NotSet
4
4
  from .frozen import Freezable, frozen
@@ -107,6 +107,12 @@ class Color(metaclass=_ColorMeta):
107
107
  raise TypeError("Cannot add non-Color to Color")
108
108
  return type(self)(code=f"{self.code[:-1]};{other.code[len(_PREFIX):]}")
109
109
 
110
+ def __eq__(self, other: object) -> bool:
111
+ """
112
+ :return: Whether the two colors are equal
113
+ """
114
+ return isinstance(other, type(self)) and self.code == other.code
115
+
110
116
  def __repr__(self) -> str:
111
117
  """
112
118
  :return: The ansi color code this object represents
@@ -16,17 +16,25 @@ class CuteFormatter(Formatter):
16
16
  A log formatter that can print log messages with colors.
17
17
  """
18
18
 
19
- DEFAULT_CUTE_WIDTHS = {"cute_levelname": 8, "cute_time": 23, "cute_name": 12}
20
- __slots__ = ("colored", "_color", "_cmap", "_name_width")
19
+ __slots__ = ("colored", "_color", "_cmap", "_lvl_cmap", "_dim_level", "_name_width")
20
+ DEFAULT_CUTE_WIDTHS: dict[str, int] = {"cute_levelname": 8, "cute_time": 23, "cute_name": 12}
21
+ DEFAULT_LEVEL_COLORS: dict[int, Color] = {
22
+ INFO: Color.blue,
23
+ WARNING: Color.yellow,
24
+ ERROR: Color.red,
25
+ CRITICAL: Color.bright_red_bg_yellow,
26
+ }
21
27
 
22
- # pylint: disable=dangerous-default-value
28
+ # pylint: disable=dangerous-default-value,keyword-arg-before-vararg,too-many-arguments
23
29
  def __init__(
24
30
  self,
25
- colors: dict[str, Color] | None = None,
26
- *,
31
+ fmt="%(cute_levelname)s | %(cute_asctime)s | %(cute_name)s | %(cute_message)s",
32
+ *args,
27
33
  colored: bool = True,
34
+ dim_level: int = DEBUG,
35
+ colors: dict[str, Color] = {},
36
+ level_colors: dict[int, Color] = {},
28
37
  cute_widths: dict[str, int] = {},
29
- fmt="%(cute_levelname)s | %(cute_asctime)s | %(cute_name)s | %(cute_message)s",
30
38
  **kwargs,
31
39
  ):
32
40
  """
@@ -34,16 +42,20 @@ class CuteFormatter(Formatter):
34
42
  Do not modify cute_ parameters in the fmt string; they might have special formatting that is not visible
35
43
  Ex. %(cute_name)-8s should be done via cute_widths["cute_name"] = 8
36
44
  This is because cute_widths takes into account 0-width color codes when padding
37
- :param colors: The colors to use for the given loggers, automatic for non-specified loggers
38
- :param colored: If False, no colors will be used regardless of the colors parameter
45
+ Level colors used are: DEFAULT_LEVEL_COLORS | level_colors
46
+ Dimming of log messages is done for levels < dim_level
39
47
  :param fmt: The format string to use for the log message; do not modify cute_ parameters
48
+ :param args: Passed to logging.Formatter
49
+ :param colored: If False, no colors will be used regardless of the colors parameter
50
+ :param colors: The colors to use for the given loggers, automatic for non-specified loggers
51
+ :param level_colors: The colors to use >= the given levels, automatic for non-specified loggers
40
52
  :param cute_widths: The widths of the cute_ columns in the log message
41
53
  :param kwargs: Passed to logging.Formatter
42
54
  """
43
- super().__init__(fmt=fmt, **kwargs)
44
- self._cmap: dict[str, Color] = {}
45
- if colors is not None:
46
- self.update(colors)
55
+ super().__init__(fmt, *args, **kwargs)
56
+ self._dim_level: int = dim_level
57
+ self._cmap: dict[str, Color] = dict(colors)
58
+ self._lvl_cmap: dict[int, Color] = self.DEFAULT_LEVEL_COLORS | level_colors
47
59
  self._widths = defaultdict(int, self.DEFAULT_CUTE_WIDTHS | cute_widths)
48
60
  if any(not i.startswith("cute_") for i in self._widths):
49
61
  raise ValueError("cute_widths must only contain cute_ parameters")
@@ -53,7 +65,7 @@ class CuteFormatter(Formatter):
53
65
  """
54
66
  Set the colors for all loggers; enables colors if disabled
55
67
  """
56
- self._cmap.update(colors)
68
+ self._cmap |= colors
57
69
 
58
70
  def format(self, record: LogRecord) -> str:
59
71
  levelname: str = record.levelname.ljust(self._widths["cute_levelname"])
@@ -62,26 +74,22 @@ class CuteFormatter(Formatter):
62
74
  message: str = record.getMessage().ljust(self._widths["cute_message"])
63
75
  if self.colored:
64
76
  # Color level
65
- if record.levelno >= CRITICAL:
66
- levelname = Color.bright_red_bg_yellow(levelname)
67
- elif record.levelno >= ERROR:
68
- levelname = Color.red(levelname)
69
- elif record.levelno >= WARNING:
70
- levelname = Color.yellow(levelname)
71
- elif record.levelno >= INFO:
72
- levelname = Color.blue(levelname)
73
- elif record.levelno < DEBUG:
74
- levelname = Color.dim(levelname)
77
+ opts = tuple(i for i in self._lvl_cmap if i <= record.levelno)
78
+ col: Color | None = self._lvl_cmap[max(opts)] if opts else None
79
+ if record.levelno < self._dim_level:
80
+ col = Color.dim if col is None else (col + Color.dim)
81
+ if col is not None:
82
+ levelname = col(levelname)
75
83
  # Color text
76
84
  if (col := self._cmap.get(record.name, None)) is None:
77
85
  c: int = adler32(record.name.encode()) % 7
78
86
  col = Color(RawColor(PureColor.black.value + c)) if c != 0 else Color.default
79
- if record.levelno < DEBUG:
87
+ if record.levelno < self._dim_level:
80
88
  col += Color.dim
81
89
  message = col(message)
82
90
  name = col(name)
83
91
  # Color timestamp
84
- if record.levelno < DEBUG:
92
+ if record.levelno < self._dim_level:
85
93
  asctime = Color.dim(asctime)
86
94
  # Create an updated record then format that
87
95
  new = copy(record)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: zstdlib
3
- Version: 0.0.7
3
+ Version: 0.0.9
4
4
  Summary: A set of useful python utilities
5
5
  License: GPLv3
6
6
  Project-URL: Homepage, https://github.com/zwimer/zstdlib
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes