import functools
def sensitive_variables(*variables):
"""
Indicates which variables used in the decorated function are sensitive, so
that those variables can later be treated in a special way, for example
by hiding them when logging unhandled exceptions.
Two forms are accepted:
* with specified variable names:
@sensitive_variables('user', 'password', 'credit_card')
def my_function(user):
password = user.pass_word
credit_card = user.credit_card_number
...
* without any specified variable names, in which case it is assumed that
all variables are considered sensitive:
@sensitive_variables()
def my_function()
...
"""
def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
if variables:
wrapper.sensitive_variables = variables
else:
wrapper.sensitive_variables = '__ALL__'
return func(*args, **kwargs)
return wrapper
return decorator
我只要把敏感信息装饰器复制到本地装饰工.py归档,然后使用它。在
用法:
^{pr2}$需要函数工具.py另外,默认情况下python2.4不会附带这个文件(我猜)——您可能需要单独包含该文件。在
相关问题 更多 >
编程相关推荐