示例#1
0
# 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()
示例#2
0
def deferred(nsec):
    def inner_deferred(func, *args, **kw):
        return threading.Timer(nsec, func, args, kw).start()

    return decorator(inner_deferred)
示例#3
0
# 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


示例#4
0
# 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()


示例#5
0
# 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
示例#6
0
def deferred(nsec):
    def inner_deferred(func, *args, **kw):
        return threading.Timer(nsec, func, args, kw).start()
    return decorator(inner_deferred)
示例#7
0
def deferred(nsec):
    def call_later(func, *args, **kw):
        return threading.Timer(nsec, func, args, kw).start()
    return decorator(call_later)