<commit_before>#
# <NAME> - INRIA
# 

from PLC.Faults import *
from PLC.Method import Method
from PLC.Parameter import Parameter, Mixed
from PLC.Auth import Auth

from PLC.Peers import Peer, Peers

can_update = lambda(k,v): k in ['peername','peer_url','auth_person_id']

class AddPeer (Method):
    """
    Creates a peer entry in the database and returns its id
    Temporarily, requires to provide an auth_person_id 
    this is used to store the credentials that we'll
    use when connecting to the peer's API
    """

    roles = ['admin']
    peer_fields = dict( [x for x in Peer.fields.iteritems() if can_update(x)] )

    accepts = [ Auth(),
		peer_fields
		]

    returns = Parameter (int, "peer_id")

    def call (self, auth, fields):

	peer = Peer (self.api,fields);
	peer.sync()
	
	return peer['peer_id']
	
<commit_msg>- style nits, fix docs<commit_after>#
# <NAME> - INRIA
# 

from PLC.Method import Method
from PLC.Parameter import Parameter, Mixed
from PLC.Auth import Auth
from PLC.Peers import Peer, Peers

can_update = lambda (field, value): field in \
             ['peername', 'peer_url', 'key', 'cacert']

class AddPeer(Method):
    """
    Adds a new peer.

    Returns the new peer_id (> 0) if successful, faults otherwise.
    """

    roles = ['admin']

    peer_fields = dict(filter(can_update, Peer.fields.items()))

    accepts = [
        Auth(),
        peer_fields
        ]

    returns = Parameter(int, "New peer_id (> 0) if successful")

    def call(self, auth, peer_fields):
	peer = Peer(self.api, peer_fields);
	peer.sync()
	return peer['peer_id']
{'fraction_non_alphanumeric': 0.1192429022082019, 'fraction_numerical': 0.0012618296529968455, 'mean_word_length': 3.2293333333333334, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '882542', 'n_tokens_mistral': 544, 'n_tokens_neox': 503, 'n_words': 169}