Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/botocore/history.py: 63%
27 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-08 06:51 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-08 06:51 +0000
1# Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"). You
4# may not use this file except in compliance with the License. A copy of
5# the License is located at
6#
7# http://aws.amazon.com/apache2.0/
8#
9# or in the "license" file accompanying this file. This file is
10# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11# ANY KIND, either express or implied. See the License for the specific
12# language governing permissions and limitations under the License.
13import logging
15HISTORY_RECORDER = None
16logger = logging.getLogger(__name__)
19class BaseHistoryHandler:
20 def emit(self, event_type, payload, source):
21 raise NotImplementedError('emit()')
24class HistoryRecorder:
25 def __init__(self):
26 self._enabled = False
27 self._handlers = []
29 def enable(self):
30 self._enabled = True
32 def disable(self):
33 self._enabled = False
35 def add_handler(self, handler):
36 self._handlers.append(handler)
38 def record(self, event_type, payload, source='BOTOCORE'):
39 if self._enabled and self._handlers:
40 for handler in self._handlers:
41 try:
42 handler.emit(event_type, payload, source)
43 except Exception:
44 # Never let the process die because we had a failure in
45 # a record collection handler.
46 logger.debug(
47 "Exception raised in %s.", handler, exc_info=True
48 )
51def get_global_history_recorder():
52 global HISTORY_RECORDER
53 if HISTORY_RECORDER is None:
54 HISTORY_RECORDER = HistoryRecorder()
55 return HISTORY_RECORDER