def __call__(self, value): if value is None: return None value = six.text_type(value) if self.pattern.match(value) is None: raise ValueError('Expected {}, not {}'.format(self.name, json_encode_string(value))) return value
def __call__(self, value): if value is None: return None try: value = float(value) except ValueError: raise ValueError('Expected float/integer value not {}'.format( json_encode_string(value))) return value
def __call__(self, value): if value is None: return None try: value = long(value) except ValueError: raise ValueError("Expected integer value, not {}".format(json_encode_string(value))) self.check_range(value) return value
def __call__(self, value): if value is None: return None try: value = float(value) except ValueError: raise ValueError('Expected float value, not {}'.format( json_encode_string(value))) self.check_range(value) return value
def __call__(self, value): if value is None: return None try: if six.PY2: value = long(value) else: value = int(value) except ValueError: raise ValueError('Expected integer value, not {}'.format(json_encode_string(value))) self.check_range(value) return value
def parse_options(args, valid_options, ignore_unknown=False): valid_options = set(valid_options) options = {} for a in args: i = a.find("=") if i >= 0: name = a[:i] value = a[i + 1:] if name not in valid_options and not ignore_unknown: raise ValueError('Unrecognized command option: {}={}'.format( name, json_encode_string(value))) options[name] = unquote(value) # | compute <mathod> using <algorithm> in <environment> for <target_field> from <feature_fields> as <renamed_target_field> return options
def parse(cls, command, argv): """ Splits an argument list into an options dictionary and a fieldname list. The argument list, `argv`, must be of the form:: *[option]... *[<field-name>] Options are validated and assigned to items in `command.options`. Field names are validated and stored in the list of `command.fieldnames`. #Arguments: :param command: Search command instance. :type command: ``SearchCommand`` :param argv: List of search command arguments. :type argv: ``list`` :return: ``None`` #Exceptions: ``SyntaxError``: Argument list is incorrectly formed. ``ValueError``: Unrecognized option/field name, or an illegal field value. """ debug = environment.splunklib_logger.debug command_class = type(command).__name__ # Prepare debug('Parsing %s command line: %r', command_class, argv) command.fieldnames = None command.options.reset() argv = ' '.join(argv) command_args = cls._arguments_re.match(argv) if command_args is None: raise SyntaxError('Syntax error: {}'.format(argv)) # Parse options for option in cls._options_re.finditer(command_args.group('options')): name, value = option.group('name'), option.group('value') if name not in command.options: raise ValueError( 'Unrecognized {} command option: {}={}'.format( command.name, name, json_encode_string(value))) command.options[name].value = cls.unquote(value) missing = command.options.get_missing() if missing is not None: if len(missing) > 1: raise ValueError( 'Values for these {} command options are required: {}'. format(command.name, ', '.join(missing))) raise ValueError( 'A value for {} command option {} is required'.format( command.name, missing[0])) # Parse field names fieldnames = command_args.group('fieldnames') if fieldnames is None: command.fieldnames = [] else: command.fieldnames = [ cls.unquote(value.group(0)) for value in cls._fieldnames_re.finditer(fieldnames) ] debug(' %s: %s', command_class, command)
def parse(cls, command, argv): """ Splits an argument list into an options dictionary and a fieldname list. The argument list, `argv`, must be of the form:: *[option]... *[<field-name>] Options are validated and assigned to items in `command.options`. Field names are validated and stored in the list of `command.fieldnames`. #Arguments: :param command: Search command instance. :type command: ``SearchCommand`` :param argv: List of search command arguments. :type argv: ``list`` :return: ``None`` #Exceptions: ``SyntaxError``: Argument list is incorrectly formed. ``ValueError``: Unrecognized option/field name, or an illegal field value. """ debug = environment.splunklib_logger.debug command_class = type(command).__name__ # Prepare debug('Parsing %s command line: %r', command_class, argv) command.fieldnames = None command.options.reset() argv = ' '.join(argv) command_args = cls._arguments_re.match(argv) if command_args is None: raise SyntaxError('Syntax error: {}'.format(argv)) # Parse options for option in cls._options_re.finditer(command_args.group('options')): name, value = option.group('name'), option.group('value') if name not in command.options: raise ValueError( 'Unrecognized {} command option: {}={}'.format(command.name, name, json_encode_string(value))) command.options[name].value = cls.unquote(value) missing = command.options.get_missing() if missing is not None: if len(missing) > 1: raise ValueError( 'Values for these {} command options are required: {}'.format(command.name, ', '.join(missing))) raise ValueError('A value for {} command option {} is required'.format(command.name, missing[0])) # Parse field names fieldnames = command_args.group('fieldnames') if fieldnames is None: command.fieldnames = [] else: command.fieldnames = [cls.unquote(value.group(0)) for value in cls._fieldnames_re.finditer(fieldnames)] debug(' %s: %s', command_class, command)