File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -103,6 +103,14 @@ def id(self, value):
103103 def merge_message (self , data ):
104104 self .bus_name = self .bus_name or data .get ('bus' , None )
105105
106+ message_attributes = dir (self )
107+ message_attributes = [a .replace ('bus_name' , 'bus' ) for a in message_attributes ]
108+ data_attributes = list (data .keys ())
109+ extra_attributes = set (data_attributes ) - set (message_attributes )
110+
111+ if extra_attributes :
112+ fatal_error ('ERROR: Message %s has unrecognized attributes: %s' % (data .get ('id' ), ', ' .join (extra_attributes )))
113+
106114 if getattr (self , 'message_set' ):
107115 self .bus = self .message_set .lookup_bus (name = self .bus_name )
108116 if not self .bus .valid ():
Original file line number Diff line number Diff line change @@ -90,10 +90,20 @@ def find_file(filename, search_paths):
9090 filename , search_paths ))
9191
9292
93+ def dict_raise_on_duplicates (ordered_pairs ):
94+ """Reject duplicate keys."""
95+ d = {}
96+ for k , v in ordered_pairs :
97+ if k in d :
98+ raise ValueError ("duplicate key: %r" % (k ,))
99+ else :
100+ d [k ] = v
101+ return d
102+
93103def load_json_from_search_path (filename , search_paths ):
94104 with open (find_file (filename , search_paths )) as json_file :
95105 try :
96- data = json .load (json_file )
106+ data = json .load (json_file , object_pairs_hook = dict_raise_on_duplicates )
97107 except ValueError as e :
98108 fatal_error ("%s does not contain valid JSON: \n %s\n " %
99109 (filename , e ))
You can’t perform that action at this time.
0 commit comments