Ejemplo n.º 1
0
 def _replace_rec(value):
     if is_string(value):
         return _replace_scalar(value)
     elif is_arrayish(value):
         return tuple(_replace_rec(subitem) for subitem in value)
     elif is_dictish(value):
         return {key: _replace_rec(value) for key, value in value.items()}
     else:
         return value
Ejemplo n.º 2
0
def parse_qcolor(color_spec):
    try:
        if is_string(color_spec):
            return _parse_qcolor_string(color_spec)
        elif is_arrayish(color_spec):
            return _parse_qcolor_arrayish(color_spec)
        elif is_dictish(color_spec):
            return _parse_qcolor_dictish(color_spec)

        raise ValueError('Unsupported format')
    except Exception as e:
        message = 'Invalid QColor spec "{0}" - {1}'.format(color_spec, e)

        raise ValueError(message) from None
Ejemplo n.º 3
0
    def from_json_representation(json_repr):
        if not is_dictish(json_repr):
            raise ValueError("JSON representation of plan should be a dictionary")

        if 'steps' not in json_repr:
            raise ValueError("Missing top-level field 'steps'")
        steps_repr = json_repr['steps']
        if not is_arrayish(steps_repr):
            raise ValueError("Expected vector for 'steps' field")
        steps = [RenamePlanAction.from_json_representation(action_repr) for action_repr in steps_repr]

        comment = None
        if 'comment' in json_repr:
            if not is_string(json_repr['comment']):
                raise ValueError("Expected string for 'comment' field")
            comment = json_repr['comment']

        return RenamePlan(steps, comment)