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
def context_entering_decorator(context_manager): | |
""" | |
Creates a context-entering decorator that does not fail to do its job | |
if the underlying function is actually a generator function. | |
""" | |
def decorator(func): | |
if inspect.isgeneratorfunction(func): | |
@functools.wraps(func) | |
def wrapped(*args, **kwargs): |
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
class universal_decorator: | |
wrappers = [] | |
def __init__(self, method): | |
self.original_method = method | |
self.method = self.original_method | |
self.apply_decorators() | |
def apply_decorators(self): | |
for wrapper in self.wrappers: |
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
""" | |
Gets list of functions in a module, preserve declaration order. | |
This cannot be done with inspect.getmembers() or dir() because they lose the order. | |
Have to construct AST with ast. | |
""" | |
import ast | |
import importlib | |
import os.path |
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
import re | |
class _ValueNotSet(object): | |
pass | |
ValueNotSet = _ValueNotSet() | |
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
""" | |
API request logger: | |
One record per each API request received | |
1) Logs to a file in logstash format. | |
App logger: | |
Your usual logger that just writes down what the code is doing. | |
Mostly quiet on production except when errors happen. | |
Includes stack traces. |
NewerOlder