Coverage for sources / ictr / reporters.py: 100%

19 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2025-12-12 01:33 +0000

1# vim: set filetype=python fileencoding=utf-8: 

2# -*- coding: utf-8 -*- 

3 

4#============================================================================# 

5# # 

6# Licensed under the Apache License, Version 2.0 (the "License"); # 

7# you may not use this file except in compliance with the License. # 

8# You may obtain a copy of the License at # 

9# # 

10# http://www.apache.org/licenses/LICENSE-2.0 # 

11# # 

12# Unless required by applicable law or agreed to in writing, software # 

13# distributed under the License is distributed on an "AS IS" BASIS, # 

14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 

15# See the License for the specific language governing permissions and # 

16# limitations under the License. # 

17# # 

18#============================================================================# 

19 

20 

21''' Message reporters. ''' 

22 

23 

24from . import __ 

25from . import flavors as _flavors 

26from . import printers as _printers 

27from . import records as _records 

28from . import textualizers as _texts 

29 

30 

31class Reporter( __.immut.DataclassObject ): 

32 ''' Formats and prints messages to targets. ''' 

33 

34 active: bool # TODO? Also accept predicate function to decide if active. 

35 address: str 

36 flavor: _flavors.Flavor 

37 compositor: _texts.Compositor 

38 printers: _printers.Printers 

39 

40 def __call__( 

41 self, 

42 summary: _records.MessageSummary, /, 

43 *details: _records.MessageDetail, 

44 ) -> None: 

45 # TODO? Return record. 

46 ''' Prepares record and prints it. ''' 

47 if not self.active: return 

48 content = _records.MessageContent( 

49 summary = summary, details = details ) 

50 record = _records.Record( 

51 address = self.address, content = content, flavor = self.flavor ) 

52 for printer in self.printers: 

53 tcontrol = printer.provide_textualization_control( ) 

54 if tcontrol is None: printer( record ) 

55 else: printer( self.compositor( tcontrol, record ) ) 

56 

57 # TODO: inscribe (same as __call__) 

58 # TODO: inscribe_async 

59 # TODO? inspect 

60 # TODO? Ability to print stack traces either from current frame or from 

61 # supplied traceback. Maybe various modes, such as compact or 

62 # detailed (showing names and values of locals).