Coverage for d7a/sp/configuration.py: 96%

24 statements  

« prev     ^ index     » next       coverage.py v7.5.0, created at 2024-05-24 08:03 +0200

1# 

2# Copyright (c) 2015-2021 University of Antwerp, Aloxy NV. 

3# 

4# This file is part of pyd7a. 

5# See https://github.com/Sub-IoT/pyd7a for further info. 

6# 

7# Licensed under the Apache License, Version 2.0 (the "License"); 

8# you may not use this file except in compliance with the License. 

9# You may obtain a copy of the License at 

10# 

11# http://www.apache.org/licenses/LICENSE-2.0 

12# 

13# Unless required by applicable law or agreed to in writing, software 

14# distributed under the License is distributed on an "AS IS" BASIS, 

15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

16# See the License for the specific language governing permissions and 

17# limitations under the License. 

18# 

19 

20# author: Christophe VG <contact@christophe.vg> 

21# class implementation of (FIFO) configuration 

22 

23from d7a.support.schema import Validatable, Types 

24 

25from d7a.types.ct import CT 

26 

27from d7a.sp.qos import QoS 

28from d7a.sp.session import States 

29 

30from d7a.d7anp.addressee import Addressee 

31 

32class Configuration(Validatable): 

33 

34 SCHEMA = [{ 

35 "qos" : Types.OBJECT(QoS), 

36 "dorm_to" : Types.OBJECT(CT), 

37 "addressee" : Types.OBJECT(Addressee) 

38 }] 

39 

40 def __init__(self, qos=QoS(), dorm_to=CT(), addressee=Addressee()): 

41 self.qos = qos 

42 self.dorm_to = dorm_to 

43 self.addressee = addressee 

44 super(Configuration, self).__init__() 

45 

46 def __iter__(self): 

47 for byte in self.qos: yield byte 

48 for byte in self.dorm_to: yield byte 

49 for byte in self.addressee: yield byte 

50 

51 def __str__(self): 

52 return str(self.as_dict()) 

53 

54 @staticmethod 

55 def parse(s): 

56 qos = QoS.parse(s) 

57 dorm_to = CT.parse(s) 

58 addressee = Addressee.parse(s) 

59 return Configuration(qos=qos, dorm_to=dorm_to, addressee=addressee)