Download lib/python3.9/test/support/logging_helper.py from camenduru/slahmr-test: direct link, hf CLI and curl.
- Browser
- Download file 916 Bytes
-
https://huggingface.co/camenduru/slahmr-test/resolve/main/lib/python3.9/test/support/logging_helper.py
- Command line
-
hf download hf://camenduru/slahmr-test/lib/python3.9/test/support/logging_helper.py
-
curl -L -o logging_helper.py https://huggingface.co/camenduru/slahmr-test/resolve/main/lib/python3.9/test/support/logging_helper.py
916 Bytes
| import logging.handlers | |
| class TestHandler(logging.handlers.BufferingHandler): | |
| def __init__(self, matcher): | |
| # BufferingHandler takes a "capacity" argument | |
| # so as to know when to flush. As we're overriding | |
| # shouldFlush anyway, we can set a capacity of zero. | |
| # You can call flush() manually to clear out the | |
| # buffer. | |
| logging.handlers.BufferingHandler.__init__(self, 0) | |
| self.matcher = matcher | |
| def shouldFlush(self): | |
| return False | |
| def emit(self, record): | |
| self.format(record) | |
| self.buffer.append(record.__dict__) | |
| def matches(self, **kwargs): | |
| """ | |
| Look for a saved dict whose keys/values match the supplied arguments. | |
| """ | |
| result = False | |
| for d in self.buffer: | |
| if self.matcher.matches(d, **kwargs): | |
| result = True | |
| break | |
| return result | |