Example #1
0
 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)
Example #2
0
 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)
Example #3
0
 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 = {}
Example #4
0
 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)
Example #5
0
 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)
Example #7
0
 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
Example #8
0
 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)
Example #9
0
 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)
Example #10
0
 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)
Example #11
0
 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)
Example #12
0
 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)
Example #13
0
    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)
Example #14
0
  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)
Example #15
0
 def parse(clazz, origin, text, node):
   if origin:
     check.check_value_origin(origin)
   check.check_node(node)
   return clazz(origin = origin, value = text)
Example #16
0
 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)
Example #17
0
 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)
Example #18
0
 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)
Example #19
0
 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)