xlwings-utils 0.0.7.post1__py3-none-any.whl → 0.0.7.post3__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.

Potentially problematic release.


This version of xlwings-utils might be problematic. Click here for more details.

@@ -13,7 +13,7 @@ from pathlib import Path
13
13
  import os
14
14
  import sys
15
15
 
16
- _org_stdout = sys.stdout
16
+ _buffer=[]
17
17
 
18
18
  dbx = None
19
19
  Pythonista = sys.platform == "ios"
@@ -420,64 +420,48 @@ def captured_stdout_as_value(clear=True):
420
420
  return [[line] for line in captured_stdout_as_str(clear).splitlines()]
421
421
 
422
422
 
423
- class handle_capture_stdout:
424
- def __init__(self):
425
- pass
426
423
 
427
- def isatty(self):
428
- return False
429
424
 
430
- def write(self, data):
431
- if _do_capture:
432
- _buffer.append(data)
433
- if _do_print:
434
- _org_stdout.write(data)
435
-
436
- def flush(self):
437
- if _do_print:
438
- _org_stdout.flush()
439
- if _do_capture:
440
- _buffer.append("\n")
441
-
442
-
443
- def reset():
444
- global _buffer
445
- global _do_print
446
- global _do_capture
447
- _buffer = []
448
- _do_print = True
449
- _do_capture = False
450
-
451
- sys.stdout = handle_capture_stdout()
452
- reset()
453
-
454
- def capture_stdout(do_print=True, do_capture=True, clear=True):
455
- global _do_print
456
- global _do_capture
425
+ class capture_stdout:
457
426
  """
458
- start capture stdout
427
+ specifies how to capture stdout
459
428
 
460
429
  Parameters
461
430
  ----------
462
- do_print : bool
463
- if True (default), the output is (also) printed out as normal
431
+ include_print : bool
432
+ if True (default), the output is also printed out as normal
464
433
 
465
434
  if False, no output is printed
466
435
 
467
- do_capture : bool
468
- if True (default), the output is (also) captured to a buffer
469
-
470
- if False, no output is captured
436
+ Note
437
+ ----
438
+ Use this function as a context manager, like ::
471
439
 
472
- clear : bool
473
- if True (default), the capture buffer is emptied
440
+ with capture_stdout():
441
+ ...
474
442
  """
475
- if not (do_print or do_capture):
476
- raise ValueError("at least one of do_print and do_capture should be True")
477
- clear_captured_stdout(clear)
478
- _do_print = do_print
479
- _do_capture = do_capture
480
443
 
444
+ def __init__(self, include_print: bool = True, clear=True):
445
+ self.stdout = sys.stdout
446
+ self.include_print = include_print
447
+ if clear:
448
+ _buffer.clear()
449
+
450
+ def __enter__(self):
451
+ sys.stdout = self
452
+
453
+ def __exit__(self, exc_type, exc_value, tb):
454
+ sys.stdout = self.stdout
455
+
456
+ def write(self, data):
457
+ _buffer.append(data)
458
+ if self.include_print:
459
+ self.stdout.write(data)
460
+
461
+ def flush(self):
462
+ if self.include_print:
463
+ self.stdout.flush()
464
+ _buffer.append("\n")
481
465
 
482
466
  if __name__ == "__main__":
483
467
  ...
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xlwings_utils
3
- Version: 0.0.7.post1
3
+ Version: 0.0.7.post3
4
4
  Summary: xlwings_utils
5
5
  Author-email: Ruud van der Ham <rt.van.der.ham@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/salabim/xlwings_utils
@@ -0,0 +1,6 @@
1
+ xlwings_utils/__init__.py,sha256=FdaRztevSu5akGL7KBUBRzqwLMRTdvVUuS2Kfp2f1Uc,68
2
+ xlwings_utils/xlwings_utils.py,sha256=8eVnPAY7ZzRt_beOq8uyBG2mY7Hu7uiyriYRLOK9DoU,12839
3
+ xlwings_utils-0.0.7.post3.dist-info/METADATA,sha256=GDhsqh9Vu0ZCfe9_FGERX07Xxvrb874BWel3x55-1V4,5695
4
+ xlwings_utils-0.0.7.post3.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
5
+ xlwings_utils-0.0.7.post3.dist-info/top_level.txt,sha256=kf5SEv0gZiRObPhUoYcc1O_iX_wwTOPeUIYvzyYeAM4,14
6
+ xlwings_utils-0.0.7.post3.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- xlwings_utils/__init__.py,sha256=FdaRztevSu5akGL7KBUBRzqwLMRTdvVUuS2Kfp2f1Uc,68
2
- xlwings_utils/xlwings_utils.py,sha256=YF4CEQBmFZ8vN1yfyQ2jmkku1cbEffJKNa63fk3CWt4,13233
3
- xlwings_utils-0.0.7.post1.dist-info/METADATA,sha256=u9JQEHDrnIHbDxhkHP1YiKuU5NaF4JPhIF3kkI_UcFo,5695
4
- xlwings_utils-0.0.7.post1.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
5
- xlwings_utils-0.0.7.post1.dist-info/top_level.txt,sha256=kf5SEv0gZiRObPhUoYcc1O_iX_wwTOPeUIYvzyYeAM4,14
6
- xlwings_utils-0.0.7.post1.dist-info/RECORD,,