def parse_args(config, method_name, args, kw, lib): """ Parse API method arguments. Look up the method in the API, get its list of arguments and its argument parser, and go forth and load them. Load positional arguments in order, and then load keyword arguments in lexical order by argument name. Accumulate ancillary data from the parsing process as well, i.e. to be used for subsequent processing. Return (parsed argument list, parsed keyword dictionary, ancillary data dictionary) Raise an exception if we failed somehow. """ import syndicate.ms.api as api method = api.get_method(method_name) if method is None: raise ValueError("No such method '%s'" % method_name) try: if method.parse_args: args, kw, extras = method.parse_args(config, method_name, method.argspec, args, kw, lib) return args, kw, extras else: return args, kw, {} except Exception, e: log.exception(e) log.error("Failed to parse method arguments for '%s'" % method_name) raise
def parse_args( config, method_name, args, kw, lib ): """ Parse API method arguments. Look up the method in the API, get its list of arguments and its argument parser, and go forth and load them. Load positional arguments in order, and then load keyword arguments in lexical order by argument name. Accumulate ancillary data from the parsing process as well, i.e. to be used for subsequent processing. Return (parsed argument list, parsed keyword dictionary, ancillary data dictionary) Raise an exception if we failed somehow. """ import syndicate.ms.api as api method = api.get_method( method_name ) try: if method.parse_args: args, kw, extras = method.parse_args( config, method_name, method.argspec, args, kw, lib ) return args, kw, extras else: return args, kw, {} except Exception, e: log.exception(e) log.error("Failed to parse method arguments for '%s'" % method_name) raise
def validate_args( method_name, args, kw ): """ Validate an API method's arguments. * verify that we got the right number of positional arguments. Return True if valid Raise an exception on error """ import syndicate.ms.api as api method = api.get_method( method_name ) arg_len = len(method.argspec.args) def_len = 0 if method.argspec.defaults is not None: def_len = len(method.argspec.defaults) if len(args) != arg_len - def_len: raise Exception("Method '%s' expects %s arguments; got %s (%s)" % (method_name, arg_len - def_len, len(args), args)) return True
def validate_args(method_name, args, kw): """ Validate an API method's arguments. * verify that we got the right number of positional arguments. Return True if valid Raise an exception on error """ import syndicate.ms.api as api method = api.get_method(method_name) arg_len = len(method.argspec.args) def_len = 0 if method.argspec.defaults is not None: def_len = len(method.argspec.defaults) if len(args) != arg_len - def_len: raise Exception("Method '%s' expects %s arguments; got %s (%s)" % (method_name, arg_len - def_len, len(args), args)) return True