def capitalize_argument(func):
"""
Wraps a function that returns a string, adding the 'capitalize' argument.
>>> capsified_fn = capitalize_argument(lambda *args, **kwargs: "what in the beeswax is this?")
>>> capsified_fn()
'what in the beeswax is this?'
>>> capsified_fn(capitalize=True)
'What In The Beeswax Is This?'
"""
@six.wraps(func)
def wrapped(*args, **kwargs):
if "capitalize" in kwargs and kwargs['capitalize']:
return func(*args, **kwargs).title()
else:
return func(*args, **kwargs)
return wrapped
评论列表
文章目录