# example2.py from decorators import decorator from example1 import do_nothing, identity, name class B(object): "This is a regular class" B = decorator(B) or B # return the original B class C(B): "[Decorated]" do_nothing = do_nothing identity = identity class Inner: # old style class "[Decorated]" # required docstring name = name C = decorator(C) # regenerate the class converting methods in decorators c = C()
def deferred(nsec): def inner_deferred(func, *args, **kw): return threading.Timer(nsec, func, args, kw).start() return decorator(inner_deferred)
# example1.py import decorators def do_nothing(self): "No magic docstring here" dec_do_nothing=decorators.decorator(do_nothing) def identity(x): "[staticmethod]" return x dec_identity=decorators.decorator(identity) def name(cls): "[classmethod]" return cls.__name__ dec_name=decorators.decorator(name) class OldStyle: do_nothing=dec_do_nothing identity=dec_identity class NewStyle(object): name=dec_name o=OldStyle() # creates an old style instance n=NewStyle() # creates a new style instance
# example2.py from decorators import decorator from example1 import do_nothing,identity,name class B(object): "This is a regular class" B=decorator(B) or B # return the original B class C(B): "[Decorated]" do_nothing=do_nothing identity=identity class Inner: # old style class "[Decorated]" # required docstring name=name C=decorator(C) # regenerate the class converting methods in decorators c=C()
# example1.py import decorators def do_nothing(self): "No magic docstring here" dec_do_nothing = decorators.decorator(do_nothing) def identity(x): "[staticmethod]" return x dec_identity = decorators.decorator(identity) def name(cls): "[classmethod]" return cls.__name__ dec_name = decorators.decorator(name) class OldStyle: do_nothing = dec_do_nothing identity = dec_identity
def deferred(nsec): def call_later(func, *args, **kw): return threading.Timer(nsec, func, args, kw).start() return decorator(call_later)