根据不同配置文件调用不同的验证函数检查输入。可以根据需求更改验证函数的逻辑。
复制代码 代码如下:
def VerifyData(func):
def VerifyInt(data):
assert(int(data) > 0)
def VerifyString(data):
assert(len(data) > 10)
def inner(*args, **kvargs):
print args
print kvargs
assert(len(args) > 1)
if args[1] == "int.txt":
VerifyInt(args[0])
elif args[1] == "string.txt":
VerifyString(args[0])
func(*args, **kvargs)
return inner
@VerifyData
def WriteData(text, filepath):
print "WriteData"
print text
print filepath
WriteData("1234567890", "int.txt")
Copyright© 2013-2020
All Rights Reserved 京ICP备2023019179号-8