Exemplo n.º 1
0
    def sanitize_optionals(self, data, schema, tree):
        schema_key_map = {}
        try:
            for number, value in schema.items():
                schema_key_map[number] = getattr(value[0], '_object', value[0])
        except AttributeError:  # maybe not a dict?
            self.length_equality(data, schema, 0, tree)

        optional_keys = {}
        for k, v in schema.items():
            try:
                key = getattr(v[0], '_object')
                if key:
                    optional_keys[k] = key
            except AttributeError:
                pass

        data_keys = [v[0] for k, v in data.items()]

        for number, value in optional_keys.items():
            if value not in data_keys:
                del schema[number]
        if not schema and is_not_empty(data):
            msg = "unexpected extra items"
            raise Invalid(schema, tree, reason=msg)
        return re_sort(schema)
Exemplo n.º 2
0
    def sanitize_optionals(self, data, schema, tree):
        schema_key_map = {}
        try:
            for number, value in schema.items():
                schema_key_map[number] = getattr(value[0], '_object', value[0])
        except AttributeError:  # maybe not a dict?
            self.length_equality(data, schema, 0, tree)

        optional_keys = {}
        for k, v in schema.items():
            try:
                key = getattr(v[0], '_object')
                if key:
                    optional_keys[k] = key
            except AttributeError:
                pass

        data_keys = [v[0] for k, v in data.items()]

        for number, value in optional_keys.items():
            if value not in data_keys:
                del schema[number]
        if not schema and is_not_empty(data):
            msg = "unexpected extra items"
            raise Invalid(schema, tree, reason=msg)
        return re_sort(schema)
Exemplo n.º 3
0
 def test_keys_will_reset_to_zero(self):
     data = {16: ('a', 1), 4: ('b', 1), 3: ('a', 1)}
     result = utils.re_sort(data)
     assert result == {0: ('a', 1), 1: ('b', 1), 2: ('a', 1)}
Exemplo n.º 4
0
 def test_keys_will_reset_to_zero(self):
     data = {16: ("a", 1), 4: ("b", 1), 3: ("a", 1)}
     result = utils.re_sort(data)
     assert result == {0: ("a", 1), 1: ("b", 1), 2: ("a", 1)}