def decorator(fn):
if async:
if inspect.isgeneratorfunction(fn):
wrapper = run_in_broker(defer.inlineCallbacks(fn))
else:
wrapper = run_in_broker(fn)
else:
if inspect.isgeneratorfunction(fn):
raise StandardError("Do not use the 'yield' keyword in a parlay command without 'parlay_command(async=True)' ")
wrapper = run_in_thread(fn)
wrapper._parlay_command = True
wrapper._parlay_fn = fn # in case it gets wrapped again, this is the actual function so we can pull kwarg names
wrapper._parlay_arg_conversions = {} # if type casting desired, this dict from param_types to converting funcs
wrapper._parlay_arg_discovery = {}
if auto_type_cast and fn.__doc__ is not None:
for line in fn.__doc__.split("\n"):
m = re.search(r"[@:]type\s+(\w+)\s*[ :]\s*(\w+\[?\w*\]?)", line)
if m is not None:
arg_name, arg_type = m.groups()
if arg_type in INPUT_TYPE_CONVERTER_LOOKUP: # if we know how to convert it
wrapper._parlay_arg_conversions[arg_name] = INPUT_TYPE_CONVERTER_LOOKUP[arg_type] # add to convert list
wrapper._parlay_arg_discovery[arg_name] = INPUT_TYPE_DISCOVERY_LOOKUP.get(arg_type, INPUT_TYPES.STRING)
return wrapper
评论列表
文章目录