| Total Complexity | 5 |
| Total Lines | 20 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | """ |
||
| 41 | class UaJSONDecoder(JSONDecoder): |
||
| 42 | """ |
||
| 43 | JSON decoder utility which is extended to handle opc ua objects |
||
| 44 | """ |
||
| 45 | def __init__(self): |
||
| 46 | JSONDecoder.__init__(self, object_hook=self.dict_to_object) |
||
| 47 | |||
| 48 | def dict_to_object(self, d): |
||
| 49 | if '__type__' not in d: |
||
| 50 | return d |
||
| 51 | |||
| 52 | type = d.pop('__type__') |
||
| 53 | if type == 'datetime': |
||
| 54 | return datetime(**d) |
||
| 55 | elif type == 'NodeId': |
||
| 56 | return ua.NodeId(**d) |
||
| 57 | else: |
||
| 58 | # decoder subclass can't handle this object type; put it back in the dict so super throws TypeError |
||
| 59 | d['__type__'] = type |
||
| 60 | return d |
||
| 61 |