def __init__(self, to=sys.stdout, only=(), *args, **kwargs):
super(DebugStream, self).__init__(*args, **kwargs)
def safe_str(chunk):
if isinstance(chunk, bytes):
chunk = chunk.decode("utf-8")
elif not isinstance(chunk, str):
chunk = str(chunk)
return chunk
class Bugger(object):
__before__ = __after__ = lambda *args: None
def __getattr__(self, event):
def inner(*args, **kwargs):
to.write(event.upper() + " ")
to.write("; ".join(map(safe_str, args)))
to.write(" ")
to.write(", ".join("{0}: {1}".format(k, safe_str(v))
for k, v in kwargs.items()))
to.write(os.linesep)
return inner
self.attach(Bugger(), only=only)
评论列表
文章目录