zstdlib 0.0.6__tar.gz → 0.0.7__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.6 → zstdlib-0.0.7}/PKG-INFO +1 -1
  2. {zstdlib-0.0.6 → zstdlib-0.0.7}/tests/log/test_cute.py +17 -8
  3. {zstdlib-0.0.6 → zstdlib-0.0.7}/zstdlib/__init__.py +1 -1
  4. {zstdlib-0.0.6 → zstdlib-0.0.7}/zstdlib/log/cute.py +23 -19
  5. {zstdlib-0.0.6 → zstdlib-0.0.7}/zstdlib.egg-info/PKG-INFO +1 -1
  6. {zstdlib-0.0.6 → zstdlib-0.0.7}/LICENSE +0 -0
  7. {zstdlib-0.0.6 → zstdlib-0.0.7}/README.md +0 -0
  8. {zstdlib-0.0.6 → zstdlib-0.0.7}/pyproject.toml +0 -0
  9. {zstdlib-0.0.6 → zstdlib-0.0.7}/setup.cfg +0 -0
  10. {zstdlib-0.0.6 → zstdlib-0.0.7}/tests/__init__.py +0 -0
  11. {zstdlib-0.0.6 → zstdlib-0.0.7}/tests/log/__init__.py +0 -0
  12. {zstdlib-0.0.6 → zstdlib-0.0.7}/tests/log/base.py +0 -0
  13. {zstdlib-0.0.6 → zstdlib-0.0.7}/tests/log/test_trace.py +0 -0
  14. {zstdlib-0.0.6 → zstdlib-0.0.7}/tests/not_set.py +0 -0
  15. {zstdlib-0.0.6 → zstdlib-0.0.7}/tests/test_ansi.py +0 -0
  16. {zstdlib-0.0.6 → zstdlib-0.0.7}/tests/test_enum.py +0 -0
  17. {zstdlib-0.0.6 → zstdlib-0.0.7}/tests/test_frozen.py +0 -0
  18. {zstdlib-0.0.6 → zstdlib-0.0.7}/tests/test_singleton.py +0 -0
  19. {zstdlib-0.0.6 → zstdlib-0.0.7}/zstdlib/ansi.py +0 -0
  20. {zstdlib-0.0.6 → zstdlib-0.0.7}/zstdlib/enum.py +0 -0
  21. {zstdlib-0.0.6 → zstdlib-0.0.7}/zstdlib/frozen.py +0 -0
  22. {zstdlib-0.0.6 → zstdlib-0.0.7}/zstdlib/log/__init__.py +0 -0
  23. {zstdlib-0.0.6 → zstdlib-0.0.7}/zstdlib/log/trace.py +0 -0
  24. {zstdlib-0.0.6 → zstdlib-0.0.7}/zstdlib/not_set.py +0 -0
  25. {zstdlib-0.0.6 → zstdlib-0.0.7}/zstdlib/py.typed +0 -0
  26. {zstdlib-0.0.6 → zstdlib-0.0.7}/zstdlib/singleton.py +0 -0
  27. {zstdlib-0.0.6 → zstdlib-0.0.7}/zstdlib.egg-info/SOURCES.txt +0 -0
  28. {zstdlib-0.0.6 → zstdlib-0.0.7}/zstdlib.egg-info/dependency_links.txt +0 -0
  29. {zstdlib-0.0.6 → zstdlib-0.0.7}/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.6
3
+ Version: 0.0.7
4
4
  Summary: A set of useful python utilities
5
5
  License: GPLv3
6
6
  Project-URL: Homepage, https://github.com/zwimer/zstdlib
@@ -17,16 +17,25 @@ class TestCuteFormatter(LeftBase, unittest.TestCase):
17
17
  msg = self.messages[log][0].rsplit("|", 1)[-1]
18
18
  self.assertEqual(f" {color.code}test{Color.RESET}", msg)
19
19
 
20
- def test_name_width(self) -> None:
21
- width = 123
20
+ def test_width(self) -> None:
22
21
  color = Color.red
23
- name = "TestCuteFormatter.name_width"
24
- with self.hijack(name, fmt=CuteFormatter(colors={name: color}, name_width=width)) as log:
22
+ name = "TestCuteFormatter.test_width"
23
+ cw = {
24
+ "cute_levelname": 300,
25
+ "cute_asctime": 200,
26
+ "cute_name": 100,
27
+ "cute_message": 400,
28
+ }
29
+ fmt = CuteFormatter(fmt="|".join(f"%({i})s" for i in cw), colors={name: color}, cute_widths=cw)
30
+ with self.hijack(name, fmt=fmt) as log:
25
31
  log.debug("test")
26
- lvl, _, nam, msg = self.messages[log][0].split("|")
27
- self.assertEqual("DEBUG", lvl.strip())
28
- self.assertEqual(f" {color(name.ljust(width))} ", nam)
29
- self.assertEqual(f" {color('test')}", msg)
32
+ lvl, date, nam, msg = self.messages[log][0].split("|")
33
+ self.assertEqual("DEBUG".ljust(cw["cute_levelname"]), lvl)
34
+ self.assertEqual(cw["cute_asctime"], len(date))
35
+ self.assertEqual(f"{color(name.ljust(cw['cute_name']))}", nam)
36
+ self.assertEqual(f"{color('test'.ljust(cw['cute_message']))}", msg)
37
+ with self.assertRaises(ValueError):
38
+ CuteFormatter(cute_widths={"name": 123})
30
39
 
31
40
  def test_no_color(self) -> None:
32
41
  name = "TestCuteFormatter.test_no_color"
@@ -1,4 +1,4 @@
1
- __version__ = "0.0.6"
1
+ __version__ = "0.0.7"
2
2
 
3
3
  from .not_set import NotSetType, NotSet
4
4
  from .frozen import Freezable, frozen
@@ -1,6 +1,6 @@
1
1
  from __future__ import annotations
2
2
  from logging import CRITICAL, ERROR, WARNING, INFO, DEBUG, Formatter
3
- from traceback import format_exception
3
+ from collections import defaultdict
4
4
  from typing import TYPE_CHECKING
5
5
  from zlib import adler32
6
6
  from copy import copy
@@ -16,32 +16,37 @@ 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}
19
20
  __slots__ = ("colored", "_color", "_cmap", "_name_width")
20
21
 
22
+ # pylint: disable=dangerous-default-value
21
23
  def __init__(
22
24
  self,
23
25
  colors: dict[str, Color] | None = None,
24
26
  *,
25
27
  colored: bool = True,
26
- name_width: int = 12,
27
- fmt="%(cute_levelname)s | %(cute_time)s | %(cute_name)s | %(cute_message)s%(cute_exc)s",
28
+ cute_widths: dict[str, int] = {},
29
+ fmt="%(cute_levelname)s | %(cute_asctime)s | %(cute_name)s | %(cute_message)s",
28
30
  **kwargs,
29
31
  ):
30
32
  """
31
33
  log_colors may be overridden, for example, trace logs are printed dimly
32
34
  Do not modify cute_ parameters in the fmt string; they might have special formatting that is not visible
33
- Ex. %(cute_name)-8s should be done via name_width, that takes into account 0-width color codes
35
+ Ex. %(cute_name)-8s should be done via cute_widths["cute_name"] = 8
36
+ This is because cute_widths takes into account 0-width color codes when padding
34
37
  :param colors: The colors to use for the given loggers, automatic for non-specified loggers
35
38
  :param colored: If False, no colors will be used regardless of the colors parameter
36
39
  :param fmt: The format string to use for the log message; do not modify cute_ parameters
37
- :param name_width: How wide the column containing the logger name should be (minus padding)
40
+ :param cute_widths: The widths of the cute_ columns in the log message
38
41
  :param kwargs: Passed to logging.Formatter
39
42
  """
40
43
  super().__init__(fmt=fmt, **kwargs)
41
44
  self._cmap: dict[str, Color] = {}
42
45
  if colors is not None:
43
46
  self.update(colors)
44
- self._name_width = name_width
47
+ self._widths = defaultdict(int, self.DEFAULT_CUTE_WIDTHS | cute_widths)
48
+ if any(not i.startswith("cute_") for i in self._widths):
49
+ raise ValueError("cute_widths must only contain cute_ parameters")
45
50
  self.colored: bool = colored
46
51
 
47
52
  def update(self, colors: dict[str, Color]):
@@ -51,22 +56,22 @@ class CuteFormatter(Formatter):
51
56
  self._cmap.update(colors)
52
57
 
53
58
  def format(self, record: LogRecord) -> str:
54
- level: str = record.levelname.ljust(8)
55
- when = self.formatTime(record, self.datefmt).ljust(23)
56
- name: str = record.name.ljust(self._name_width)
57
- message: str = record.getMessage()
59
+ levelname: str = record.levelname.ljust(self._widths["cute_levelname"])
60
+ asctime = self.formatTime(record, self.datefmt).ljust(self._widths["cute_asctime"])
61
+ name: str = record.name.ljust(self._widths["cute_name"])
62
+ message: str = record.getMessage().ljust(self._widths["cute_message"])
58
63
  if self.colored:
59
64
  # Color level
60
65
  if record.levelno >= CRITICAL:
61
- level = Color.bright_red_bg_yellow(level)
66
+ levelname = Color.bright_red_bg_yellow(levelname)
62
67
  elif record.levelno >= ERROR:
63
- level = Color.red(level)
68
+ levelname = Color.red(levelname)
64
69
  elif record.levelno >= WARNING:
65
- level = Color.yellow(level)
70
+ levelname = Color.yellow(levelname)
66
71
  elif record.levelno >= INFO:
67
- level = Color.blue(level)
72
+ levelname = Color.blue(levelname)
68
73
  elif record.levelno < DEBUG:
69
- level = Color.dim(level)
74
+ levelname = Color.dim(levelname)
70
75
  # Color text
71
76
  if (col := self._cmap.get(record.name, None)) is None:
72
77
  c: int = adler32(record.name.encode()) % 7
@@ -77,16 +82,15 @@ class CuteFormatter(Formatter):
77
82
  name = col(name)
78
83
  # Color timestamp
79
84
  if record.levelno < DEBUG:
80
- when = Color.dim(when)
85
+ asctime = Color.dim(asctime)
81
86
  # Create an updated record then format that
82
87
  new = copy(record)
83
88
  new.__dict__.update(
84
89
  {
85
- "cute_levelname": level,
86
- "cute_time": when,
90
+ "cute_levelname": levelname,
91
+ "cute_asctime": asctime,
87
92
  "cute_name": name,
88
93
  "cute_message": message,
89
- "cute_exc": ("\n" + "".join(format_exception(*new.exc_info))[:-1]) if new.exc_info else "",
90
94
  }
91
95
  )
92
96
  return super().format(new)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: zstdlib
3
- Version: 0.0.6
3
+ Version: 0.0.7
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
File without changes