Beispiel #1
0
def parse_field_type_dependency(raw_value, meta=None):
    if '|' in raw_value:
        raw_value = utils.split_string(raw_value, separator='|', strip=True)
        alternatives = []
        for dependency in raw_value:
            match = re.match(DEPENDENCY_PATTERN, dependency)
            if match:
                parsed = match.groupdict()
                alternatives.append(_build_dependency_class(
                    parsed=parsed,
                    raw_value=raw_value,
                    meta=meta
                ))
            else:
                log.warning('Dependency parse error on %s', dependency)
                # TODO: add some UnparsedVersion object
        return classes.DependencyAlternative(
            _raw=raw_value,
            alternatives=alternatives
        )
    else:
        match = re.match(DEPENDENCY_PATTERN, raw_value)
        if match is None:
            return
        else:
            parsed = match.groupdict()
            return _build_dependency_class(
                parsed=parsed,
                raw_value=raw_value,
                meta=meta,
            )
Beispiel #2
0
def parse_field_value(raw_value, meta=None):
    if meta and meta.format == 'list':
        if ',' in raw_value:
            separator = ','
        else:
            separator = '\n'
        list_items = utils.split_string(
            raw_value, separator=separator, strip=True, skip_blank=True)
        return classes.ListField(
            [parse_typed_field_value(li, meta) for li in list_items],
            _raw=raw_value,
        )
    else:
        return parse_typed_field_value(raw_value, meta)