Advertisement
mrlantan

Untitled

Oct 31st, 2016
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. import sys
  2.  
  3.  
  4. class supresser(object):
  5.     def __init__(self, *types):
  6.         self.types = types
  7.     def __enter__(self):
  8.         pass
  9.     def __exit__(self, *args):
  10.         if args[0] in self.types:
  11.             return True
  12.         else:
  13.             return False
  14.  
  15. class retyper(object):
  16.     def __init__(self, type_from, type_to):
  17.         self.type_from = type_from
  18.         self.type_to = type_to
  19.     def __enter__(self):
  20.         pass
  21.     def __exit__(self, *args):
  22.         if args[0] == self.type_from:
  23.             exc = self.type_to()
  24.             exc.args = args[1].args
  25.             # print(exc.args == ('lalala', 1))
  26.             raise exc.with_traceback(args[2])
  27.  
  28. class dumper(object):
  29.     def __init__(self, stream):
  30.         self.stream = stream
  31.     def __enter__(self):
  32.         pass
  33.     def __exit__(self, *args):
  34.         string = repr(args[0].__name__)[1:-1] + ': ' + str(args[1]) + '\n'
  35.         self.stream.write(string)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement