def create_with_class_name(clazz, origin, text, node, value_class_name): check.check_value_origin(origin) check.check_string(text) check.check_node(node) check.check_string(value_class_name) value_class = clazz.get_class(value_class_name) return value_class.parse(origin, text, node)
def make_value(clazz, origin, text, node, value_class_name): if origin: check.check_value_origin(origin) check.check_node(node) check.check_string(value_class_name) return value_factory.create_with_class_name(origin, text, node, value_class_name)
def __init__(self, origin, properties=None): if origin: check.check_value_origin(origin) self.origin = origin properties = properties or key_value_list() check.check_key_value_list(properties) self._properties = properties self._substitutions = {}
def _caca_parse_mask_and_value(clazz, origin, text, node, class_name): check.check_value_origin(origin) check.check_string(text) check.check_node(node) check.check_string(class_name) mask, value = recipe_parser_util.split_mask_and_value(text) value = recipe_parser_util.make_value(origin, value, node, class_name) return masked_value(mask, value, origin)
def parse(clazz, origin, text, node): if origin: check.check_value_origin(origin) check.check_node(node) if not text: values = string_list() else: values = string_list.parse(text, options = string_list.KEEP_QUOTES) return clazz(origin = origin, values = values)
def parse(clazz, origin, text, node): if origin: check.check_value_origin(origin) check.check_node(node) if not text: values = requirement_list() else: values = requirement_list.parse(text) return clazz(origin=origin, values=values)
def parse(clazz, origin, value, node): if origin: check.check_value_origin(origin) check.check_node(node) hook_name, _, rest = string_util.partition_by_white_space(value) hook_class = hook_registry.get(hook_name) if not hook_class: raise TypeError('%s: hook class not found: %s' % (origin, hook_name)) properties = clazz.parse_properties(rest) hook_instance = hook_class(origin=origin, properties=properties) return hook_instance
def parse(clazz, origin, text, node): if origin: check.check_value_origin(origin) check.check_node(node) parts = string_util.split_by_white_space(text) if len(parts) < 1: raise ValueError('%s: expected filename instead of: %s' % (origin, text)) where = parts[0] rest = string_util.replace(text, {where: ''}) properties = clazz.parse_properties(rest) return clazz(origin=origin, where=where, properties=properties)
def parse_key_value(clazz, origin, text): check.check_value_origin(origin) check.check_string(text) key, delimiter, value = text.partition(':') key = key.strip() if not key: raise clazz.raise_error( origin, '%s: invalid step value key: \"%s\"' % (origin, text)) if not delimiter: return clazz.parsed_value(None, key, None) value_text = value.strip() or None return clazz.parsed_value(None, key, value_text)
def parse(clazz, origin, text, node): if origin: check.check_value_origin(origin) check.check_node(node) base = path.dirname(origin.filename) filename, _, rest = string_util.partition_by_white_space(text) if filename.startswith('$'): filename_abs = filename else: filename_abs = path.abspath(path.join(base, filename)) if not path.isfile(filename_abs): raise RuntimeError('%s: file not found: %s' % (origin, filename_abs)) properties = clazz.parse_properties(rest) return value_file(origin=origin, filename=filename_abs, properties=properties)
def parse(clazz, origin, text, node): if origin: check.check_value_origin(origin) check.check_node(node) parts = string_util.split_by_white_space(text) if len(parts) < 2: raise ValueError( '%s: expected filename and dst_filename instead of: %s' % (origin, text)) filename = parts[0] dst_filename = parts[1] rest = text.replace(filename, '') rest = rest.replace(dst_filename, '') properties = clazz.parse_properties(rest) return clazz(origin=origin, filename=filename, dst_filename=dst_filename, properties=properties)
def make_key_value(clazz, origin, text, node, value_class_name): check.check_value_origin(origin) check.check_string(text) check.check_node(node) check.check_string(value_class_name) text = comments.strip_line(text) key, delimiter, value = text.partition(':') key = key.strip() if not key: raise ValueError('%s: invalid step value key: \"%s\"' % (origin, text)) if not delimiter: return key_value(key, None) value_text = value.strip() or None if not value_text: return key_value(key, None) value = value_factory.create_with_class_name(origin, value_text, node, value_class_name) return key_value(key, value)
def __new__(clazz, mask, value, origin=None): if not check.is_value_base(value): if check.is_bool(value): value = value_bool(origin=origin, value=value) elif check.is_int(value): value = value_int(origin=origin, value=value) elif check.is_string(value): value = value_string(origin=origin, value=value) elif check.is_string_list(value) or check.is_string_seq(value): value = value_string_list(origin=origin, values=value) elif check.is_key_value_list(value): value = value_key_values(origin=origin, values=value) if not check.is_value_base(value): raise TypeError('value should be subclass of value_base: %s - %s' % (str(value), type(value))) if origin: check.check_value_origin(origin) return clazz.__bases__[0].__new__(clazz, mask, value)
def parse(clazz, origin, text, node): if origin: check.check_value_origin(origin) check.check_node(node) strings = string_list.parse(text, options = string_list.KEEP_QUOTES) string_values, properties_text = clazz._split_values_and_properties(strings) values = [] if False: print('VLB.parse() origin: _%s_' % (str(origin))) print('VLB.parse() text: _%s_' % (text)) print('VLB.parse() value_type: %s' % (clazz.value_type())) print('VLB.parse() strings: %s' % (strings)) print('VLB.parse() string_values: %s' % (string_values)) print('VLB.parse() properties_text: %s' % (properties_text)) print('') for string_value in string_values: value_text = string_value + ' ' + properties_text value = clazz.value_type().parse(origin, value_text, node) values.append(value) return clazz(origin = origin, values = values)
def parse(clazz, origin, text, node): if origin: check.check_value_origin(origin) check.check_node(node) return clazz(origin = origin, value = text)
def parse(clazz, origin, value, node): if origin: check.check_value_origin(origin) check.check_node(node) values = key_value_list.parse(value, options = key_value_list.KEEP_QUOTES) return clazz(origin = origin, values = values)
def parse(clazz, origin, text, node): if origin: check.check_value_origin(origin) check.check_node(node) value = bool_util.parse_bool(text) return clazz(origin=origin, value=value)
def raise_error(clazz, origin, msg, starting_line_number=None): starting_line_number = starting_line_number or 0 check.check_value_origin(origin) check.check_string(msg) raise value_error(msg, origin.filename, origin.line_number + starting_line_number)
def parse_mask_and_value(clazz, origin, key, text): check.check_value_origin(origin) check.check_string(key) check.check_string(text) mask, value = clazz.split_mask_and_value(text) return clazz.parsed_value(mask, key, value)