55class BatmanParser (BaseParser ):
66 """batman-adv parser"""
77
8- protocol = ' batman-adv'
9- version = ' 2015.0'
10- metric = 'TQ'
8+ protocol = " batman-adv"
9+ version = " 2015.0"
10+ metric = "TQ"
1111
1212 # the default expected format
13- _format = ' alfred_vis'
13+ _format = " alfred_vis"
1414
1515 def to_python (self , data ):
1616 """
@@ -25,20 +25,20 @@ def _txtinfo_to_python(self, data):
2525 """
2626 Converts txtinfo format to python
2727 """
28- self ._format = ' txtinfo'
28+ self ._format = " txtinfo"
2929 # find interesting section
30- lines = data .split (' \n ' )
30+ lines = data .split (" \n " )
3131 try :
32- start = lines .index (' Table: Topology' ) + 2
32+ start = lines .index (" Table: Topology" ) + 2
3333 except ValueError :
34- raise ParserError (' Unrecognized format' )
34+ raise ParserError (" Unrecognized format" )
3535 topology_lines = [line for line in lines [start :] if line ]
3636 # convert to python list
3737 parsed_lines = []
3838 for line in topology_lines :
39- values = line .split (' ' )
39+ values = line .split (" " )
4040 parsed_lines .append (
41- {' source' : values [0 ], ' target' : values [1 ], ' cost' : float (values [4 ])}
41+ {" source" : values [0 ], " target" : values [1 ], " cost" : float (values [4 ])}
4242 )
4343 return parsed_lines
4444
@@ -59,9 +59,9 @@ def _get_aggregated_node_list(self, data):
5959 """
6060 node_list = []
6161 for node in data :
62- local_addresses = [node [' primary' ]]
63- if ' secondary' in node :
64- local_addresses += node [' secondary' ]
62+ local_addresses = [node [" primary" ]]
63+ if " secondary" in node :
64+ local_addresses += node [" secondary" ]
6565 node_list .append (local_addresses )
6666 return node_list
6767
@@ -72,7 +72,7 @@ def parse(self, data):
7272 * alfred_vis
7373 * txtinfo
7474 """
75- method = getattr (self , ' _parse_{0}' .format (self ._format ))
75+ method = getattr (self , " _parse_{0}" .format (self ._format ))
7676 return method (data )
7777
7878 def _parse_alfred_vis (self , data ):
@@ -83,26 +83,26 @@ def _parse_alfred_vis(self, data):
8383 """
8484 # initialize graph and list of aggregated nodes
8585 graph = self ._init_graph ()
86- if ' source_version' in data :
87- self .version = data [' source_version' ]
88- if ' vis' not in data :
86+ if " source_version" in data :
87+ self .version = data [" source_version" ]
88+ if " vis" not in data :
8989 raise ParserError ('Parse error, "vis" key not found' )
90- node_list = self ._get_aggregated_node_list (data [' vis' ])
90+ node_list = self ._get_aggregated_node_list (data [" vis" ])
9191
9292 # loop over topology section and create networkx graph
9393 for node in data ["vis" ]:
9494 for neigh in node ["neighbors" ]:
9595 graph .add_node (
96- node [' primary' ],
96+ node [" primary" ],
9797 ** {
98- ' local_addresses' : node .get (' secondary' , []),
99- ' clients' : node .get (' clients' , []),
98+ " local_addresses" : node .get (" secondary" , []),
99+ " clients" : node .get (" clients" , []),
100100 }
101101 )
102- primary_neigh = self ._get_primary_address (neigh [' neighbor' ], node_list )
102+ primary_neigh = self ._get_primary_address (neigh [" neighbor" ], node_list )
103103 # networkx automatically ignores duplicated edges
104104 graph .add_edge (
105- node [' primary' ], primary_neigh , weight = float (neigh [' metric' ])
105+ node [" primary" ], primary_neigh , weight = float (neigh [" metric" ])
106106 )
107107 return graph
108108
@@ -113,5 +113,5 @@ def _parse_txtinfo(self, data):
113113 """
114114 graph = self ._init_graph ()
115115 for link in data :
116- graph .add_edge (link [' source' ], link [' target' ], weight = link [' cost' ])
116+ graph .add_edge (link [" source" ], link [" target" ], weight = link [" cost" ])
117117 return graph
0 commit comments