-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New matching and event reporting module
- Loading branch information
Showing
6 changed files
with
1,092 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import enum | ||
import logging | ||
from typing import Protocol | ||
|
||
|
||
class LoggingSeverity(enum.IntEnum): | ||
"""To improve type checking. There isn't an enum to import from the logging module.""" | ||
|
||
DEBUG = logging.DEBUG | ||
INFO = logging.INFO | ||
WARNING = logging.WARNING | ||
ERROR = logging.ERROR | ||
|
||
|
||
class ReccmpEvent(enum.Enum): | ||
NO_MATCH = enum.auto() | ||
|
||
# Symbol (or designated unique attribute) was found not to be unique | ||
NON_UNIQUE_SYMBOL = enum.auto() | ||
|
||
# Match by name/type not unique | ||
AMBIGUOUS_MATCH = enum.auto() | ||
|
||
|
||
def event_to_severity(event: ReccmpEvent) -> LoggingSeverity: | ||
return { | ||
ReccmpEvent.NO_MATCH: LoggingSeverity.ERROR, | ||
ReccmpEvent.NON_UNIQUE_SYMBOL: LoggingSeverity.WARNING, | ||
ReccmpEvent.AMBIGUOUS_MATCH: LoggingSeverity.WARNING, | ||
}.get(event, LoggingSeverity.INFO) | ||
|
||
|
||
class ReccmpReportProtocol(Protocol): | ||
def __call__(self, event: ReccmpEvent, orig_addr: int, /, msg: str = ""): | ||
... | ||
|
||
|
||
def reccmp_report_nop(*_, **__): | ||
"""Reporting no-op function""" | ||
|
||
|
||
def create_logging_wrapper(logger: logging.Logger) -> ReccmpReportProtocol: | ||
"""Return a function to use when you just want to redirect events to the given logger""" | ||
|
||
def wrap(event: ReccmpEvent, _: int, msg: str = ""): | ||
logger.log(event_to_severity(event), msg) | ||
|
||
return wrap |
Oops, something went wrong.