<commit_before>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 UpdatePeer(Method):
    """
    Updates a peer. Only the fields specified in peer_fields are
    updated, all other fields are left untouched.

    Returns 1 if successful, faults otherwise.
    """

    roles = ['admin']

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

    accepts = [
        Auth(),
        Mixed(Peer.fields['peer_id'],
              Peer.fields['peername']),
        peer_fields
        ]

    returns = Parameter(int, "1 if successful")

    def call(self, auth, peer_id_or_name, peer_fields):
        peer_fields = dict(filter(can_update, peer_fields.items()))

        # Get account information
        peers = Peers(self.api, [peer_id_or_name])
        if not peers:
            raise PLCInvalidArgument, "No such peer"

        peer = peers[0]
        peer.update(peer_fields)
        peer.sync()

        # Log affected objects
	self.object_ids = [peer['peer_id']]

	return 1<commit_msg>- import Faults - add peer check<commit_after>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 (field, value): field in \
             ['peername', 'peer_url', 'key', 'cacert']

class UpdatePeer(Method):
    """
    Updates a peer. Only the fields specified in peer_fields are
    updated, all other fields are left untouched.

    Returns 1 if successful, faults otherwise.
    """

    roles = ['admin']

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

    accepts = [
        Auth(),
        Mixed(Peer.fields['peer_id'],
              Peer.fields['peername']),
        peer_fields
        ]

    returns = Parameter(int, "1 if successful")

    def call(self, auth, peer_id_or_name, peer_fields):
        peer_fields = dict(filter(can_update, peer_fields.items()))

        # Get account information
        peers = Peers(self.api, [peer_id_or_name])
        if not peers:
            raise PLCInvalidArgument, "No such peer"
        peer = peers[0]

        if isinstance(self.caller, Peer):
            if self.caller['peer_id'] != peer['peer_id']:
                raise PLCPermissionDenied, "Not allowed to update specified peer"

        peer.update(peer_fields)
        peer.sync()

        # Log affected objects
	self.object_ids = [peer['peer_id']]

	return 1
{'fraction_non_alphanumeric': 0.10740314537782893, 'fraction_numerical': 0.0030686612965093976, 'mean_word_length': 2.662921348314607, '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': '1971018', 'n_tokens_mistral': 802, 'n_tokens_neox': 754, 'n_words': 223}