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
def _add_properties_to_discovery(self): """ Add properties to discovery """ # clear properties self._properties = {} for member_name in [x for x in dir(self.__class__) if not x.startswith("__")]: member = self.__class__.__dict__.get(member_name, None) if isinstance(member, ParlayProperty): self.add_property(member_name, member_name, # lookup type name based on type func (e.g. int()) INPUT_TYPE_DISCOVERY_LOOKUP.get(member._val_type.__name__, "STRING"), read_only=member._read_only, write_only=member._write_only)
def decorator(fn): if async: if inspect.isgeneratorfunction(fn): wrapper = run_in_broker(defer.inlineCallbacks(fn)) else: wrapper = run_in_broker(fn) else: 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