def request(method="GET", path="", data=None):
def wrapper(func):
func.routed = True
func.method = method
func.path = path
func.data = data
return func
return wrapper
def response(fmt="%s", contentType="text/plain"):
def wrapper(func):
func.format = fmt
func.contentType = contentType
return func
return wrapper
@request("GET", "%(channel)d/value")
@response("%d")
def digitalRead(self, channel):
self.checkDigitalChannel(channel)
return self.__digitalRead__(channel)
从上次讨论开始,我们讨论了 @A @B类 定义函数:
会变成func=A()(B()func()),所以从上面看,@request和@response是包装器,那么新的digitalRead函数会是什么样子呢
该函数将具有添加到decorators中的包装器中给定的属性
相关问题 更多 >
编程相关推荐