@@ -54,9 +54,9 @@ def get_devices(self):
5454 valid_devices = [node .text for node in device_node .iterfind (self ._VALID_DEVICE )]
5555 devices = identifiers
5656 if len (invalid_devices ):
57- devices = [ did for did in devices if did .string not in invalid_devices ]
57+ devices = ( did for did in devices if did .string not in invalid_devices )
5858 if len (valid_devices ):
59- devices = [ did for did in devices if did .string in valid_devices ]
59+ devices = ( did for did in devices if did .string in valid_devices )
6060 return [build_device (did , self ) for did in devices ]
6161
6262 @staticmethod
@@ -68,9 +68,10 @@ def is_valid(node, identifier: DeviceIdentifier):
6868 Returns:
6969 True if the selectors match, False otherwise.
7070 """
71- device_keys = filter (lambda k : k .startswith (DeviceFile ._PREFIX_ATTRIBUTE_DEVICE ), node .attrib .keys ())
72- properties = {k .replace (DeviceFile ._PREFIX_ATTRIBUTE_DEVICE , '' ):node .attrib [k ].split ("|" ) for k in device_keys }
73- return not any (identifier [key ] not in value for key , value in properties .items ())
71+ device_keys = (k for k in node .attrib .keys () if k .startswith (DeviceFile ._PREFIX_ATTRIBUTE_DEVICE ))
72+ properties = ((k .replace (DeviceFile ._PREFIX_ATTRIBUTE_DEVICE , '' ), node .attrib [k ].split ("|" ))
73+ for k in device_keys )
74+ return all (identifier [key ] in value for key , value in properties )
7475
7576 def get_properties (self , identifier : DeviceIdentifier ):
7677 class Converter :
@@ -86,9 +87,9 @@ def is_valid(self, node):
8687 return DeviceFile .is_valid (node , self .identifier )
8788
8889 def strip_attrib (self , node ):
89- stripped_keys = filter ( lambda k : not k .startswith (DeviceFile ._PREFIX_ATTRIBUTE_DEVICE ), node . attrib . keys ( ))
90+ stripped_keys = ( k for k in node . attrib . keys () if not k .startswith (DeviceFile ._PREFIX_ATTRIBUTE_DEVICE ))
9091 if node .getparent ().getparent () is None and node .tag == 'device' :
91- stripped_keys = filter ( lambda k : k not in self .identifier .keys (), stripped_keys )
92+ stripped_keys = ( k for k in stripped_keys if k not in self .identifier .keys ())
9293 return {k :node .attrib [k ] for k in stripped_keys }
9394
9495 def to_dict (self , t ):
@@ -97,14 +98,13 @@ def to_dict(self, t):
9798 return {}
9899 attrib = self .strip_attrib (t )
99100 d = {t .tag : {} if len (attrib ) else None }
100- children = []
101- for c in t :
102- if self .is_valid (c ):
103- children .append (c )
101+ children = filter (self .is_valid , t )
104102 if children :
105103 dd = defaultdict (list )
106104 for dc in map (self .to_dict , children ):
105+ # print(dc)
107106 for k , v in dc .items ():
107+ if k == "signal" and v .get ("name" ) == "seg40" : print (v )
108108 dd [k ].append (v )
109109 dk = {}
110110 for k , v in dd .items ():
@@ -120,8 +120,11 @@ def to_dict(self, t):
120120 elif len (attrib ):
121121 if any (k in d [t .tag ] for k in attrib .keys ()):
122122 raise ParserException ("Node children are overwriting attribute '{}'!" .format (k ))
123+ # print(attrib.items())
123124 d [t .tag ].update (attrib .items ())
124125 return read_only ({k :read_only (v ) for k ,v in d .items ()})
125126
126127 properties = Converter (identifier ).to_dict (self .rootnode .find ("device" ))
128+ # print(properties)
129+ # exit(1)
127130 return properties ["device" ]
0 commit comments