CadasterSchemaNode   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 44
rs 10
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validator() 0 13 4
A preparer() 0 5 3
1
# -*- coding: utf-8 -*-
2
"""
3
Validates cadaster parcel in Flanders
4
"""
5
6
import re
7
8
import colander
9
from colander import null
10
11
12
class CadasterSchemaNode(colander.MappingSchema):
13
14
    afdeling = colander.SchemaNode(
15
        colander.String(50),
16
        validator=colander.Length(1, 50),
17
        missing=None
18
    )
19
20
    sectie = colander.SchemaNode(
21
        colander.String(50),
22
        validator=colander.Length(1, 50),
23
        missing=None
24
    )
25
26
    perceel = colander.SchemaNode(
27
        colander.String(50),
28
        validator=colander.Length(1, 50),
29
        missing=None
30
    )
31
32
    capakey = colander.SchemaNode(
33
        colander.String(50),
34
        validator=colander.Length(1, 50)
35
    )
36
37
    @staticmethod
38
    def preparer(parcel):
39
        if parcel is None or not parcel:
40
            return null  # pragma: no cover
41
        return parcel
42
43
    @staticmethod
44
    def validator(node, parcel):
45
        capakey = parcel.get('capakey', None)
46
        match = False
47
        if capakey:
48
            match = re.match(
49
                r"^[0-9]{5}[A-Z]{1}([0-9]{4})\/([0-9]{2})([A-Z\_]{1})([0-9]{3})$",
50
                capakey
51
            )
52
        if not capakey or not match:
53
            raise colander.Invalid(
54
                    node,
55
                    'Ongeldige capakey'
56
            )
57