<commit_before>from PLC.Faults import *
from PLC.Method import Method
from PLC.Parameter import Parameter, Mixed
from PLC.NodeNetworks import NodeNetwork, NodeNetworks
from PLC.Nodes import Node, Nodes
from PLC.Auth import PasswordAuth

class AdmGetAllNodeNetworks(Method):
    """
    Returns all the networks this node is connected to, as an array of
    structs.
    """

    roles = ['admin', 'pi', 'user', 'tech']

    accepts = [
        PasswordAuth(),
        Mixed(Node.fields['node_id'],
              Node.fields['hostname'])
        ]

    returns = [NodeNetwork.fields]

    def call(self, auth, node_id_or_hostname):
        # Authenticated function
        assert self.caller is not None

        # Get node information
        nodes = Nodes(self.api, [node_id_or_hostname]).values()
	if not nodes:
            raise PLCInvalidArgument, "No such node"
	node = nodes[0]

	# Get node networks for this node
	nodenetworks = NodeNetworks(self.api, node['nodenetwork_ids']).values()
	if not nodenetworks:
            raise PLCInvalidArgument, "Node has no node networks"

	# Filter out undesired or None fields (XML-RPC cannot marshal
        # None) and turn each node into a real dict.
        valid_return_fields_only = lambda (key, value): value is not None
        nodenetworks = [dict(filter(valid_return_fields_only, nodenetwork.items())) \
                        for nodenetwork in nodenetworks]
       	
	return nodenetworks<commit_msg>- fix if node has no node networks<commit_after>from PLC.Faults import *
from PLC.Method import Method
from PLC.Parameter import Parameter, Mixed
from PLC.NodeNetworks import NodeNetwork, NodeNetworks
from PLC.Nodes import Node, Nodes
from PLC.Auth import PasswordAuth

class AdmGetAllNodeNetworks(Method):
    """
    Returns all the networks this node is connected to, as an array of
    structs.
    """

    roles = ['admin', 'pi', 'user', 'tech']

    accepts = [
        PasswordAuth(),
        Mixed(Node.fields['node_id'],
              Node.fields['hostname'])
        ]

    returns = [NodeNetwork.fields]

    def call(self, auth, node_id_or_hostname):
        # Authenticated function
        assert self.caller is not None

        # Get node information
        nodes = Nodes(self.api, [node_id_or_hostname]).values()
	if not nodes:
            raise PLCInvalidArgument, "No such node"
	node = nodes[0]

	# Get node networks for this node
        if node['nodenetwork_ids']:
            nodenetworks = NodeNetworks(self.api, node['nodenetwork_ids']).values()
        else:
            nodenetworks = []

	# Filter out undesired or None fields (XML-RPC cannot marshal
        # None) and turn each node into a real dict.
        valid_return_fields_only = lambda (key, value): value is not None
        nodenetworks = [dict(filter(valid_return_fields_only, nodenetwork.items())) \
                        for nodenetwork in nodenetworks]
       	
	return nodenetworks
{'fraction_non_alphanumeric': 0.08787465940054497, 'fraction_numerical': 0.0006811989100817438, 'mean_word_length': 2.8192457737321197, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '111387', 'n_tokens_mistral': 873, 'n_tokens_neox': 842, 'n_words': 270}