Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from functools import wraps
- from time import perf_counter
- import types
- class debug(object):
- def __init__(self, Time=False, Parameters=False, Doc=False, Value=False):
- self.t = Time
- self.p = Parameters
- self.d = Doc
- self.v = Value
- def __call__(self, func):
- @wraps(func)
- def run(*args, **kwargs):
- @wraps(func)
- def gen(g):
- print("\tDebug Generator: '{}'".format(func.__name__))
- step = 0
- while True:
- try:
- if self.t:
- gt1 = perf_counter()
- genval = next(g)
- if self.t:
- gt2 = perf_counter()
- print("\tGenerator Time: {:.3e} seconds".format(gt2 - gt1))
- print("\tGenerator Step #{}: {}".format(step, genval if self.v else type(genval).__name__))
- step += 1
- yield genval
- except GeneratorExit:
- break
- print("\tGeneratpr {} is finsihed.".format(func.__name__))
- params = ""
- if self.p:
- params = ", ".join(["{}".format(arg) for arg in args] + ["{}={}".format(k, v) for k, v in kwargs.items()])
- print("\n\tDebug output for '{}({})'".format(func.__name__, params))
- if self.d:
- print('\tDocstring: "{}"'.format(func.__doc__))
- if self.t:
- t1 = perf_counter()
- val = func(*args, **kwargs)
- if self.t:
- t2 = perf_counter()
- print("\tTime Taken: {:.3e} seconds".format(t2 - t1))
- print("\tReturn: '{}'\n".format(val if self.v else type(val).__name__))
- return gen(val) if isinstance(val, types.GeneratorType) else run
- return run
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement