jk_prettyprintobj 0.2024.2.18__py3-none-any.whl → 0.2024.6.7__py3-none-any.whl

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.
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
  __author__ = "Jürgen Knauth"
5
- __version__ = "0.2024.2.18"
5
+ __version__ = "0.2024.6.7"
6
6
 
7
7
 
8
8
 
@@ -12,35 +12,6 @@ from ._Bits import _Bits
12
12
 
13
13
 
14
14
 
15
- ################################################################################################################################
16
- ################################################################################################################################
17
- ##
18
- ## Dumpable objects should use the following import:
19
- ##
20
- ## import jk_prettyprintobj
21
- ##
22
- ## Dumpable objects should then be defined like this:
23
- ##
24
- ## class FooBar(SomeBaseClassA,SomeMixinB,jk_prettyprintobj.DumpMixin)
25
- ## ....
26
- ## #
27
- ##
28
- ## Dumpable objects should then implement one of these two methods:
29
- ##
30
- ## def _dump(self, ctx:jk_prettyprintobj.DumpCtx):
31
- ## ctx.dumpVar(...)
32
- ## #
33
- ##
34
- ## or:
35
- ##
36
- ## def _dumpVarNames(self) -> typing.List[str]:
37
- ## return [
38
- ## "....",
39
- ## ]
40
- ## #
41
- ##
42
- ################################################################################################################################
43
- ################################################################################################################################
44
15
 
45
16
 
46
17
 
@@ -226,7 +197,9 @@ def _byteChunkerWithOfs(settings:DumperSettings, data:bytes, processorName:str =
226
197
 
227
198
 
228
199
 
229
- POST_PROCESSORS = {
200
+ _PRIMITIVE_POST_PROCESSORS = {
201
+ # map associating processor name to tuple consisting of type (or type list) and callable
202
+
230
203
  "shorten": (str, _str_shortenText),
231
204
  "hex": (int, _int_toHex),
232
205
  "bit": (int, _int_toBits),
@@ -260,6 +233,7 @@ class _Omitted:
260
233
  class RawValue:
261
234
 
262
235
  def __init__(self, text:str) -> None:
236
+ assert isinstance(text, str)
263
237
  self.text = text
264
238
  #
265
239
 
@@ -294,7 +268,7 @@ class DumpCtx(object):
294
268
  #
295
269
 
296
270
  def dumpVarRaw(self, varName:str, value:RawValue) -> None:
297
- self._dumpX(varName + " = ", value.text)
271
+ self._dumpX(varName + " = ", value)
298
272
  #
299
273
 
300
274
  #
@@ -342,6 +316,10 @@ class DumpCtx(object):
342
316
  # This method outputs a value (recursively).
343
317
  # To achieve this this method analyses the data type of the specified value and invokes individual type processing methods if available.
344
318
  #
319
+ # @param str extraPrefix (required) A prefix to use
320
+ # @param any value (optional) The value to print
321
+ # @param str? processorName (optional) A value output processor
322
+ #
345
323
  def _dumpX(self, extraPrefix:str, value, processorName:str = None):
346
324
  if value is None:
347
325
  self._dumpPrimitive(extraPrefix, None, processorName)
@@ -421,6 +399,9 @@ class DumpCtx(object):
421
399
  #
422
400
  # Dump the specified dictionary.
423
401
  #
402
+ # @param str processorName (optional) The processor name. This name is passed to recursive calls of _dumpX() so that it is applied
403
+ # to every value. Additionally if "shorten" is specified the dictionary itself will be shortened.
404
+ #
424
405
  def _dumpDict(self, extraPrefix:str, value:dict, processorName:str = None):
425
406
  e = (type(value).__name__ + ":") if self.__s.showComplexStructsWithType else ""
426
407
 
@@ -428,11 +409,17 @@ class DumpCtx(object):
428
409
 
429
410
  ctx = DumpCtx(self.__s, self.outputLines, None, self.prefix + "\t")
430
411
  with ctx as ctx2:
412
+ i = 0
431
413
  for k, v in value.items():
414
+ if processorName == "shorten":
415
+ if i >= 3:
416
+ ctx2._dumpRawValue("", RawValue("..."))
417
+ break
432
418
  if processorName == "omitValues":
433
419
  v = _OMITTED
434
420
  ctx2._dumpX(self._dictKeyToStr(k) + " : ", v)
435
421
  self.outputLines[-1] += ","
422
+ i += 1
436
423
 
437
424
  self.outputLines.append(self.prefix + "}")
438
425
  #
@@ -454,20 +441,30 @@ class DumpCtx(object):
454
441
  #
455
442
  # Dump the specified list.
456
443
  #
444
+ # @param str processorName (optional) The processor name. This name is passed to recursive calls of _dumpX() so that it is applied
445
+ # to every value. Additionally if "shorten" is specified the list itself will be shortened.
446
+ #
457
447
  def _dumpList(self, extraPrefix:str, value:list, processorName:str = None):
458
448
  e = (type(value).__name__ + ":") if self.__s.showComplexStructsWithType else ""
459
449
 
460
450
  if self._canCompactSequence(value):
461
- self.outputLines.append(self.prefix + extraPrefix + e + "[ " + self._compactSequence(value, processorName) + " ]")
451
+ rawText = self._compactSequence(value, processorName)
452
+ self.outputLines.append(self.prefix + extraPrefix + e + "[ " + rawText + " ]")
462
453
 
463
454
  else:
464
455
  self.outputLines.append(self.prefix + extraPrefix + e + "[")
465
456
 
466
457
  ctx = DumpCtx(self.__s, self.outputLines, None, self.prefix + "\t")
467
458
  with ctx as ctx2:
459
+ i = 0
468
460
  for vItem in value:
461
+ if processorName == "shorten":
462
+ if i >= 3:
463
+ ctx2._dumpRawValue("", RawValue("..."))
464
+ break
469
465
  ctx2._dumpX("", vItem, processorName)
470
466
  self.outputLines[-1] += ","
467
+ i += 1
471
468
 
472
469
  self.outputLines.append(self.prefix + "]")
473
470
  #
@@ -498,20 +495,30 @@ class DumpCtx(object):
498
495
  #
499
496
  # Dump the specified tuple.
500
497
  #
498
+ # @param str processorName (optional) The processor name. This name is passed to recursive calls of _dumpX() so that it is applied
499
+ # to every value. Additionally if "shorten" is specified the list itself will be shortened.
500
+ #
501
501
  def _dumpTuple(self, extraPrefix:str, value:set, processorName:str = None):
502
502
  e = (type(value).__name__ + ":") if self.__s.showComplexStructsWithType else ""
503
503
 
504
504
  if self._canCompactSequence(value):
505
- self.outputLines.append(self.prefix + extraPrefix + e + "( " + self._compactSequence(value, processorName) + " )")
505
+ rawText = self._compactSequence(value, processorName)
506
+ self.outputLines.append(self.prefix + extraPrefix + e + "( " + rawText + " )")
506
507
 
507
508
  else:
508
509
  self.outputLines.append(self.prefix + extraPrefix + e + "(")
509
510
 
510
511
  ctx = DumpCtx(self.__s, self.outputLines, None, self.prefix + "\t")
511
512
  with ctx as ctx2:
513
+ i = 0
512
514
  for vItem in value:
515
+ if processorName == "shorten":
516
+ if i >= 3:
517
+ ctx2._dumpRawValue("", RawValue("..."))
518
+ break
513
519
  ctx2._dumpX("", vItem, processorName)
514
520
  self.outputLines[-1] += ","
521
+ i += 1
515
522
 
516
523
  self.outputLines.append(self.prefix + ")")
517
524
  #
@@ -591,6 +598,7 @@ class DumpCtx(object):
591
598
  return True
592
599
  #
593
600
 
601
+ # TODO: support "shorten" to shorten the list
594
602
  def _compactSequence(self, someSequence, processorName:str = None) -> str:
595
603
  ret = []
596
604
  for v in someSequence:
@@ -627,9 +635,9 @@ class DumpCtx(object):
627
635
  else:
628
636
  # process value before converting it to str
629
637
  if processorName:
630
- if processorName not in POST_PROCESSORS:
638
+ if processorName not in _PRIMITIVE_POST_PROCESSORS:
631
639
  raise Exception("No such postprocessor: " + repr(processorName))
632
- postProcessorTypeCompatibility, postProcessor = POST_PROCESSORS[processorName]
640
+ postProcessorTypeCompatibility, postProcessor = _PRIMITIVE_POST_PROCESSORS[processorName]
633
641
  if isinstance(value, postProcessorTypeCompatibility):
634
642
  value = postProcessor(value)
635
643
 
@@ -730,6 +738,37 @@ class Dumper(object):
730
738
 
731
739
 
732
740
 
741
+ ################################################################################################################################
742
+ ################################################################################################################################
743
+ """
744
+
745
+ Dumpable objects should be defined like this:
746
+
747
+ class FooBar(SomeBaseClassA,SomeMixinB,jk_prettyprintobj.DumpMixin)
748
+ ....
749
+ #
750
+
751
+ Dumpable objects should then implement one of these two methods:
752
+
753
+ def _dump(self, ctx:jk_prettyprintobj.DumpCtx):
754
+ ctx.dumpVar(...)
755
+ #
756
+
757
+ or:
758
+
759
+ def _dumpVarNames(self) -> typing.List[str]:
760
+ return [
761
+ "....",
762
+ ]
763
+ #
764
+
765
+ """
766
+ ################################################################################################################################
767
+ ################################################################################################################################
768
+
769
+
770
+
771
+
733
772
  class DumpMixin:
734
773
 
735
774
  __slots__ = tuple()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: jk_prettyprintobj
3
- Version: 0.2024.2.18
3
+ Version: 0.2024.6.7
4
4
  Summary: This python module provides a mixin for creating pretty debugging output for objects. This is especially useful for semi-complex data structures.
5
5
  Keywords: pretty-print,debugging,debug
6
6
  Author-email: Jürgen Knauth <pubsrc@binary-overflow.de>
@@ -0,0 +1,7 @@
1
+ jk_prettyprintobj/_Bits.py,sha256=EVAk9bMNpnuv_re8hi5vk4znK2xYHsceR07RG_0f4x0,805
2
+ jk_prettyprintobj/_Hex.py,sha256=RsqEIp8N4ms48aDCYIV1TLQxexd0TnxwRmnx91Y0MQg,515
3
+ jk_prettyprintobj/__init__.py,sha256=TgH87YHnJP-i85bgE0pgxQlfYiyL95BWv22Iae6Px9E,152
4
+ jk_prettyprintobj/dumper.py,sha256=kNaYZZF1z8j4lOROzi6rRPjjkUuLD_uEYlq2p6kddrE,22319
5
+ jk_prettyprintobj-0.2024.6.7.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
6
+ jk_prettyprintobj-0.2024.6.7.dist-info/METADATA,sha256=kEKHbH7UyioerEA9asjt37YUdnG0FIQA8jPK506rz5w,8315
7
+ jk_prettyprintobj-0.2024.6.7.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- jk_prettyprintobj/_Bits.py,sha256=EVAk9bMNpnuv_re8hi5vk4znK2xYHsceR07RG_0f4x0,805
2
- jk_prettyprintobj/_Hex.py,sha256=RsqEIp8N4ms48aDCYIV1TLQxexd0TnxwRmnx91Y0MQg,515
3
- jk_prettyprintobj/__init__.py,sha256=a0raxboYf240pXJUtBjWbnvO7NFSnIrzqBfGdU1tZxQ,153
4
- jk_prettyprintobj/dumper.py,sha256=fA-jTweGAR25gpLna7Y16R7BSsvNolNwqvyEr0Po-Q4,20909
5
- jk_prettyprintobj-0.2024.2.18.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
6
- jk_prettyprintobj-0.2024.2.18.dist-info/METADATA,sha256=8Acm9i54Kf1ipBkDXKYfBG--0i9TWUecdIsv23VNPYY,8316
7
- jk_prettyprintobj-0.2024.2.18.dist-info/RECORD,,