|
1 |
| -__version__ = r"1.1.0" |
| 1 | +__version__ = r"1.0.0" |
2 | 2 |
|
3 |
| -from typing import Any, Dict, Iterable, List, Union, TextIO |
4 |
| -from io import TextIOWrapper |
| 3 | +from typing import Any, Iterable |
5 | 4 |
|
6 |
| -import sys |
7 |
| -from pathlib import Path |
8 | 5 | from .scope_adapter import ScopeAdapter
|
9 | 6 |
|
10 | 7 | class ScopeInspectionAdapter( ScopeAdapter ):
|
11 |
| - def __init__( self, **kwargs: Dict[ str, Any ] ): |
12 |
| - """ |
13 |
| - Creates a ScopeInspectionAdapter. |
14 |
| - |
15 |
| - Keyword Arguments: |
16 |
| - `output_targets`: iterable of output targets. |
17 |
| - `open_file_mode`: file mode output targets will be opened with; defaults to write ("w"). |
18 |
| - `output_console`: boolean which controls if stdout should be written to; defaults to True, indicating stdout will be written to. |
19 |
| - `output_error`: boolean which controls if stderr should be written to; defaults to False, indicating stderr will not be written to. |
20 |
| - """ |
21 |
| - |
| 8 | + def __init__( self ): |
22 | 9 | super().__init__()
|
23 | 10 |
|
24 |
| - output_targets: Iterable[ str, Path, TextIO ] = kwargs.get( "output_targets", None ) |
25 |
| - if output_targets is None: |
26 |
| - output_targets = [] |
27 |
| - |
28 |
| - open_file_mode = kwargs.get( "open_file_mode", None ) |
29 |
| - if open_file_mode is None: |
30 |
| - open_file_mode: str = "w" |
31 |
| - |
32 |
| - output_console: bool = bool( kwargs.get( "output_console", True ) ) |
33 |
| - output_error: bool = bool( kwargs.get( "output_error", False ) ) |
34 |
| - |
35 |
| - self._output_targets: List[ TextIO ] = [] |
36 |
| - |
37 |
| - if output_console: |
38 |
| - self._output_targets.append( sys.stdout ) |
39 |
| - |
40 |
| - if output_error: |
41 |
| - self._output_targets.append( sys.stderr ) |
42 |
| - |
43 |
| - for target in output_targets: |
44 |
| - if isinstance( target, str ): |
45 |
| - target = Path( target ) |
46 |
| - |
47 |
| - if isinstance( target, Path ): |
48 |
| - target = open( target, open_file_mode ) |
49 |
| - |
50 |
| - if not isinstance( target, ( TextIO, TextIOWrapper ) ): |
51 |
| - raise ValueError( "Invalid scope inspection target: target must be a string, path, or text stream." ) |
52 |
| - else: |
53 |
| - self._output_targets.append( target ) |
54 |
| - |
55 |
| - def _output_message( self, message: str ) -> None: |
56 |
| - for target in self._output_targets: |
57 |
| - print( message, file = target ) |
58 |
| - target.flush() |
| 11 | + self._output_message = lambda message: print( message ) |
59 | 12 |
|
60 | 13 | def _print_message( self, name, *values: Iterable[ Any ] ) -> None:
|
61 | 14 | if len( values ) > 0:
|
|
0 commit comments