<commit_before>from PLC.Faults import *
from PLC.Method import Method
from PLC.Parameter import Parameter, Mixed
from PLC.Keys import Key, Keys
from PLC.Auth import PasswordAuth

class GetKeys(Method):
    """
    Get an array of structs containing the keys for the specified
    key_ids. If key_id_list is not specified, all keys
    will be queried.

    Admin may get all keys. Non-admins can only get their own keys
    """

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

    accepts = [
        PasswordAuth(),
        [Key.fields['key_id']]
        ]

    returns = [Key.fields]

    def call(self, auth, key_id_list = None):
        	
	#if we are not admin, make sure to only return our own keys       
        if 'admin' not in self.caller['roles']:
		if key_id_list is None:
			key_id_list =  self.caller['key_ids']
		else:
			valid_keys = lambda x: x in self.caller['key_ids']
			key_id_list = filter(valid_keys, key_id_list)
		
	keys = Keys(self.api, key_id_list).values()
	
	# Filter out undesired or None fields (XML-RPC cannot marshal
        # None) and turn each key into a real dict.
	valid_return_fields_only = lambda (key, value): value is not None
        keys = [dict(filter(valid_return_fields_only, key.items())) \
                      for key in keys]		
        return keys<commit_msg>- check for both key_id_list = None and key_id_list = [], both of which   Keys interprets to mean "all keys"<commit_after>from PLC.Faults import *
from PLC.Method import Method
from PLC.Parameter import Parameter, Mixed
from PLC.Keys import Key, Keys
from PLC.Auth import PasswordAuth

class GetKeys(Method):
    """
    Return an array of structs containing details about keys. If
    key_id_list is specified, only the specified keys will be queried.

    Admin may query all keys. Non-admins may only query their own
    keys.
    """

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

    accepts = [
        PasswordAuth(),
        [Key.fields['key_id']]
        ]

    returns = [Key.fields]

    def call(self, auth, key_id_list = None):
	# If we are not admin, make sure to only return our own keys       
        if 'admin' not in self.caller['roles']:
            if not key_id_list:
                key_id_list = self.caller['key_ids']
            else:
                valid_keys = lambda x: x in self.caller['key_ids']
                key_id_list = filter(valid_keys, key_id_list)
		
	keys = Keys(self.api, key_id_list).values()
	
        return keys
{'fraction_non_alphanumeric': 0.09326845093268452, 'fraction_numerical': 0.0, 'mean_word_length': 2.6279411764705882, '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': '3356254', 'n_tokens_mistral': 803, 'n_tokens_neox': 749, 'n_words': 268}