+ def _dict_from_multiple_values_options_callback(
+ option, opt_str, value, parser, allowed_keys=r'[\w-]+', delimiter=':', default_key=None, process=None):
+
+ out_dict = getattr(parser.values, option.dest)
+ mobj = re.match(r'(?i)(?P<key>%s)%s(?P<val>.*)$' % (allowed_keys, delimiter), value)
+ if mobj is not None:
+ key, val = mobj.group('key').lower(), mobj.group('val')
+ elif default_key is not None:
+ key, val = default_key, value
+ else:
+ raise optparse.OptionValueError(
+ 'wrong %s formatting; it should be %s, not "%s"' % (opt_str, option.metavar, value))
+ out_dict[key] = process(val) if callable(process) else val
+