xlwings-utils 0.0.7.post2__tar.gz → 0.0.7.post3__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.

Potentially problematic release.


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

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xlwings_utils
3
- Version: 0.0.7.post2
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
@@ -10,7 +10,7 @@ authors = [
10
10
  { name = "Ruud van der Ham", email = "rt.van.der.ham@gmail.com" },
11
11
  ]
12
12
  description = "xlwings_utils"
13
- version = "0.0.7.post2"
13
+ version = "0.0.7.post3"
14
14
  readme = "README.md"
15
15
  requires-python = ">=3.9"
16
16
  dependencies = [
@@ -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,60 +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
- _buffer.append(data)
432
- if _do_print:
433
- _org_stdout.write(data)
434
-
435
- def flush(self):
436
- if _do_print:
437
- _org_stdout.flush()
438
- _buffer.append("\n")
425
+ class capture_stdout:
426
+ """
427
+ specifies how to capture stdout
439
428
 
429
+ Parameters
430
+ ----------
431
+ include_print : bool
432
+ if True (default), the output is also printed out as normal
440
433
 
441
- def reset():
442
- global _buffer
443
- sys.stdout=_org_stdout
444
- _buffer=[]
434
+ if False, no output is printed
445
435
 
446
- reset()
436
+ Note
437
+ ----
438
+ Use this function as a context manager, like ::
447
439
 
448
- def capture_stdout(do_print=True, do_capture=True, clear=True):
449
- global _do_print
440
+ with capture_stdout():
441
+ ...
450
442
  """
451
- start capture stdout
452
443
 
453
- Parameters
454
- ----------
455
- do_print : bool
456
- if True (default), the output is (also) printed out as normal
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()
457
449
 
458
- if False, no output is printed
450
+ def __enter__(self):
451
+ sys.stdout = self
459
452
 
460
- do_capture : bool
461
- if True (default), the output is (also) captured to a buffer
453
+ def __exit__(self, exc_type, exc_value, tb):
454
+ sys.stdout = self.stdout
462
455
 
463
- if False, no output is captured
456
+ def write(self, data):
457
+ _buffer.append(data)
458
+ if self.include_print:
459
+ self.stdout.write(data)
464
460
 
465
- clear : bool
466
- if True (default), the capture buffer is emptied
467
- """
468
- if not (do_print or do_capture):
469
- raise ValueError("at least one of do_print and do_capture should be True")
470
-
471
- if do_capture:
472
- if sys.stdout is _org_stdout:
473
- sys.stdout = handle_capture_stdout()
474
- _do_print=do_print
475
- else:
476
- sys.stdout=_org_stdout
461
+ def flush(self):
462
+ if self.include_print:
463
+ self.stdout.flush()
464
+ _buffer.append("\n")
477
465
 
478
466
  if __name__ == "__main__":
479
467
  ...
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xlwings_utils
3
- Version: 0.0.7.post2
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