def parse(self, data):
graph = self._init_graph()<EOL>if '<STR_LIT:type>' not in data or data['<STR_LIT:type>'] != '<STR_LIT>':<EOL><INDENT>raise ParserError('<STR_LIT>')<EOL><DEDENT>required_keys = ['<STR_LIT>', '<STR_LIT:version>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>']<EOL>for key in required_keys:<EOL><INDENT>if key not in data:<EOL><INDENT>raise ParserError('<STR_LIT>'.format(key))<EOL><DEDENT><DEDENT>self.protocol = data['<STR_LIT>']<EOL>self.version = data['<STR_LIT:version>']<EOL>self.revision = data.get('<STR_LIT>')  <EOL>self.metric = data['<STR_LIT>']<EOL>for node in data['<STR_LIT>']:<EOL><INDENT>graph.add_node(node['<STR_LIT:id>'],<EOL>label=node['<STR_LIT:label>'] if '<STR_LIT:label>' in node else None,<EOL>local_addresses=node.get('<STR_LIT>', []),<EOL>**node.get('<STR_LIT>', {}))<EOL><DEDENT>for link in data['<STR_LIT>']:<EOL><INDENT>try:<EOL><INDENT>source = link["<STR_LIT:source>"]<EOL>dest = link["<STR_LIT:target>"]<EOL>cost = link["<STR_LIT>"]<EOL><DEDENT>except KeyError as e:<EOL><INDENT>raise ParserError('<STR_LIT>' % e)<EOL><DEDENT>properties = link.get('<STR_LIT>', {})<EOL>graph.add_edge(source, dest, weight=cost, **properties)<EOL><DEDENT>return graph<EOL>
Converts a NetJSON 'NetworkGraph' object
to a NetworkX Graph object,which is then returned.
Additionally checks for protocol version, revision and metric.