Code Duplication    Length = 13-14 lines in 3 locations

ppp_datamodel/communication/traceitem.py 1 location

@@ 18-31 (lines=14) @@
15
    __slots__ = ()
16
    _possible_attributes = ('module', 'tree', 'measures', 'times')
17
18
    def _check_attributes(self, attributes, extra=None):
19
        super(TraceItem, self)._check_attributes(attributes)
20
        # Allow missing 'time' attribute for now (transitioning)
21
        missing_attributes = {'module', 'tree', 'measures'} - set(attributes.keys())
22
        if missing_attributes:
23
            raise AttributeNotProvided('Missing attributes: %s' % ', '.join(missing_attributes))
24
        if not isinstance(attributes['module'], basestring):
25
            raise TypeError('"module" attribute is not a string.')
26
        if not isinstance(attributes['tree'], AbstractNode):
27
            raise TypeError('"tree" attribute is not an AbstractNode.')
28
        if not isinstance(attributes['measures'], dict):
29
            raise TypeError('"measures" attribute is not a dict.')
30
        if 'times' in attributes and not isinstance(attributes['times'], dict):
31
            raise TypeError('"times" attribute is not a dict.')
32
33
    def _parse_attributes(self, attributes):
34
        # Allow missing 'time' attribute for now (transitioning)

ppp_datamodel/communication/response.py 1 location

@@ 20-32 (lines=13) @@
17
    _possible_attributes = ('language', 'tree', 'measures', 'trace')
18
19
20
    def _check_attributes(self, attributes, extra=None):
21
        super(Response, self)._check_attributes(attributes)
22
        missing_attributes = {'language', 'tree', 'measures', 'trace'} - set(attributes.keys())
23
        if missing_attributes:
24
            raise AttributeNotProvided('Missing attributes: %s' % ', '.join(missing_attributes))
25
        if not isinstance(attributes['language'], basestring):
26
            raise TypeError('"language" attribute is not a string.')
27
        if not isinstance(attributes['tree'], AbstractNode):
28
            raise TypeError('"tree" attribute is not an AbstractNode.')
29
        if not isinstance(attributes['measures'], dict):
30
            raise TypeError('"measures" attribute is not a dict.')
31
        if not isinstance(attributes['trace'], list):
32
            raise TypeError('"trace" attribute is not a list.')
33
34
    def _parse_attributes(self, attributes):
35
        tree = attributes['tree']

ppp_datamodel/communication/request.py 1 location

@@ 20-32 (lines=13) @@
17
    __slots__ = ()
18
    _possible_attributes = ('id', 'language', 'tree', 'measures', 'trace')
19
20
    def _check_attributes(self, attributes, extra=None):
21
        super(Request, self)._check_attributes(attributes)
22
        missing_attributes = {'id', 'language', 'tree'} - set(attributes.keys())
23
        if missing_attributes:
24
            raise AttributeNotProvided('Missing attributes: %s' % ', '.join(missing_attributes))
25
        if not isinstance(attributes['language'], basestring):
26
            raise TypeError('"language" attribute is not a string.')
27
        if not isinstance(attributes['tree'], AbstractNode):
28
            raise TypeError('"tree" attribute is not an AbstractNode.')
29
        if not isinstance(attributes['measures'], dict):
30
            raise TypeError('"measures" attribute is not a dict.')
31
        if not isinstance(attributes['trace'], list):
32
            raise TypeError('"trace" attribute is not a list.')
33
34
    def _parse_attributes(self, attributes):
35
        attributes['measures'] = attributes.get('measures', {})