diff options
author | martinko | 2012-12-04 10:21:03 +0000 |
---|---|---|
committer | martinko | 2012-12-04 10:21:03 +0000 |
commit | 6d293e6a536a7529a83ff377efa188d31d1e3ef9 (patch) | |
tree | 1e0315e1d749a60af7ada1f46e4a1a0f79291807 /python | |
parent | 431f9a642500fc79a4561c1887e5d9e68c5bd354 (diff) |
londiste handlers' arg names are checked now
Diffstat (limited to 'python')
-rw-r--r-- | python/londiste/handler.py | 30 | ||||
-rw-r--r-- | python/londiste/handlers/multimaster.py | 3 |
2 files changed, 33 insertions, 0 deletions
diff --git a/python/londiste/handler.py b/python/londiste/handler.py index 42187158..76c47f8d 100644 --- a/python/londiste/handler.py +++ b/python/londiste/handler.py @@ -77,6 +77,36 @@ class BaseHandler: self.fq_table_name = skytools.quote_fqident(self.table_name) self.fq_dest_table = skytools.quote_fqident(self.dest_table) self.args = args + self._check_args (args) + + def _parse_args_from_doc (self): + doc = self.__doc__ or "" + params_descr = [] + params_found = False + for line in doc.splitlines(): + ln = line.strip() + if params_found: + if ln == "": + break + descr = ln.split (None, 1) + name, sep, rest = descr[0].partition('=') + if sep: + expr = descr[0].rstrip(":") + text = descr[1].lstrip(":- \t") + else: + name, expr, text = params_descr.pop() + text += "\n" + ln + params_descr.append ((name, expr, text)) + elif ln == "Parameters:": + params_found = True + return params_descr + + def _check_args (self, args): + passed_arg_names = args.keys() if args else [] + self.valid_arg_names = list(zip(*self._parse_args_from_doc())[0]) + invalid = set(passed_arg_names) - set(self.valid_arg_names) + if invalid: + raise ValueError ("Invalid handler argument: %s" % list(invalid)) def add(self, trigger_arg_list): """Called when table is added. diff --git a/python/londiste/handlers/multimaster.py b/python/londiste/handlers/multimaster.py index f28535e8..aa1d4e51 100644 --- a/python/londiste/handlers/multimaster.py +++ b/python/londiste/handlers/multimaster.py @@ -30,6 +30,9 @@ class MultimasterHandler(ApplyFuncHandler): args = update(args, {'func_name': 'merge_on_time', 'func_conf': conf}) ApplyFuncHandler.__init__(self, table_name, args, dest_table) + def _check_args (self, args): + pass # any arg can be passed + def add(self, trigger_arg_list): """Create SKIP and BEFORE INSERT trigger""" trigger_arg_list.append('no_merge') |