Coverage for src/ezplog/types/protocols/printer_protocol.py: 100.00%

5 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-10-16 19:04 +0000

1# /////////////////////////////////////////////////////////////// 

2# EZPL - Printer Protocol 

3# Project: ezpl 

4# /////////////////////////////////////////////////////////////// 

5 

6""" 

7Printer Protocol for Ezpl logging framework. 

8 

9This module defines the Protocol (abstract interface) that all printer 

10implementations must follow. It provides type checking and ensures 

11consistent API across different printer implementations. 

12""" 

13 

14from __future__ import annotations 

15 

16# /////////////////////////////////////////////////////////////// 

17# IMPORTS 

18# /////////////////////////////////////////////////////////////// 

19# Standard library imports 

20from contextlib import AbstractContextManager 

21from typing import Any, Protocol, runtime_checkable 

22 

23# Local imports 

24from ..enums import Pattern 

25 

26# /////////////////////////////////////////////////////////////// 

27# PROTOCOLS 

28# /////////////////////////////////////////////////////////////// 

29 

30 

31@runtime_checkable 

32class PrinterProtocol(Protocol): 

33 """ 

34 Protocol defining the interface for printer implementations. 

35 

36 All printer implementations must conform to this protocol to ensure 

37 consistent API and type safety. 

38 

39 **Required Methods:** 

40 - Logging methods: info(), debug(), success(), warning(), error(), critical() 

41 - Pattern methods: tip(), system(), install(), detect(), config(), deps() 

42 - Enhanced methods: print_pattern(), print_json() 

43 - Utility methods: set_level(), log() 

44 - Indentation methods: add_indent(), del_indent(), reset_indent(), manage_indent() 

45 

46 **Required Properties:** 

47 - wizard: Access to RichWizard instance for advanced features 

48 """ 

49 

50 # /////////////////////////////////////////////////////////////// 

51 # CORE LOGGING METHODS 

52 # /////////////////////////////////////////////////////////////// 

53 

54 def trace(self, message: Any, *args: Any, **kwargs: Any) -> None: 

55 """Log a trace message.""" 

56 ... 

57 

58 def info(self, message: Any, *args: Any, **kwargs: Any) -> None: 

59 """Log an informational message.""" 

60 ... 

61 

62 def debug(self, message: Any, *args: Any, **kwargs: Any) -> None: 

63 """Log a debug message.""" 

64 ... 

65 

66 def success(self, message: Any, *args: Any, **kwargs: Any) -> None: 

67 """Log a success message.""" 

68 ... 

69 

70 def warning(self, message: Any, *args: Any, **kwargs: Any) -> None: 

71 """Log a warning message.""" 

72 ... 

73 

74 def error( 

75 self, message: Any, *args: Any, exc_info: bool = False, **kwargs: Any 

76 ) -> None: 

77 """Log an error message, optionally with the active traceback.""" 

78 ... 

79 

80 def critical( 

81 self, message: Any, *args: Any, exc_info: bool = False, **kwargs: Any 

82 ) -> None: 

83 """Log a critical message, optionally with the active traceback.""" 

84 ... 

85 

86 def exception(self, message: Any, *args: Any, **kwargs: Any) -> None: 

87 """Log an error message followed by the active exception traceback.""" 

88 ... 

89 

90 # /////////////////////////////////////////////////////////////// 

91 # PATTERN METHODS 

92 # /////////////////////////////////////////////////////////////// 

93 

94 def tip(self, message: Any) -> None: 

95 """Display a tip message.""" 

96 ... 

97 

98 def system(self, message: Any) -> None: 

99 """Display a system message.""" 

100 ... 

101 

102 def install(self, message: Any) -> None: 

103 """Display an installation message.""" 

104 ... 

105 

106 def detect(self, message: Any) -> None: 

107 """Display a detection message.""" 

108 ... 

109 

110 def config(self, message: Any) -> None: 

111 """Display a configuration message.""" 

112 ... 

113 

114 def deps(self, message: Any) -> None: 

115 """Display a dependencies message.""" 

116 ... 

117 

118 # /////////////////////////////////////////////////////////////// 

119 # ENHANCED METHODS 

120 # /////////////////////////////////////////////////////////////// 

121 

122 def print_pattern( 

123 self, pattern: str | Pattern, message: Any, level: str = "INFO" 

124 ) -> None: 

125 """Display a message with pattern format.""" 

126 ... 

127 

128 def print_json( 

129 self, 

130 data: str | dict | list, 

131 title: str | None = None, 

132 indent: int | None = None, 

133 highlight: bool = True, 

134 ) -> None: 

135 """Display JSON data in formatted way.""" 

136 ... 

137 

138 # /////////////////////////////////////////////////////////////// 

139 # UTILITY METHODS 

140 # /////////////////////////////////////////////////////////////// 

141 

142 @property 

143 def level(self) -> str: 

144 """Get the current logging level.""" 

145 ... 

146 

147 def set_level(self, level: str) -> None: 

148 """Set the logging level.""" 

149 ... 

150 

151 def log(self, level: str, message: Any, *args: Any, **kwargs: Any) -> None: 

152 """Log a message at the given level.""" 

153 ... 

154 

155 # /////////////////////////////////////////////////////////////// 

156 # INDENTATION METHODS 

157 # /////////////////////////////////////////////////////////////// 

158 

159 def add_indent(self) -> None: 

160 """Increase indentation level.""" 

161 ... 

162 

163 def del_indent(self) -> None: 

164 """Decrease indentation level.""" 

165 ... 

166 

167 def reset_indent(self) -> None: 

168 """Reset indentation to zero.""" 

169 ... 

170 

171 def manage_indent(self) -> AbstractContextManager[None]: 

172 """Context manager for temporary indentation.""" 

173 ... 

174 

175 # /////////////////////////////////////////////////////////////// 

176 # PROPERTIES 

177 # /////////////////////////////////////////////////////////////// 

178 

179 @property 

180 def wizard(self) -> Any: 

181 """Get RichWizard instance for advanced features.""" 

182 ... 

183 

184 

185# /////////////////////////////////////////////////////////////// 

186# PUBLIC API 

187# /////////////////////////////////////////////////////////////// 

188 

189__all__ = [ 

190 "PrinterProtocol", 

191]