<commit_before># -*- coding: utf-8 -*-

""" Management around connected peers """

import nago.core
from nago.core import nago_access

@nago_access
def get():
    """ List all connected peers
    """
    return nago.core.get_peers()

@nago_access
def edit(security_token, **kwargs):
    """ Change the attributes of a connected peer """
    peer = nago.core.get_peer(security_token) or {}
    if not kwargs:
        return "No changes made"
    for k, v in kwargs.items():
        peer[k] = v
    peer.save()
    return "Saved %s changes" % len(kwargs)<commit_msg>peers extension - list and sign methods created<commit_after># -*- coding: utf-8 -*-

""" Management around connected peers """

import nago.core
from nago.core import nago_access

@nago_access
def list(search="unsigned"):
    """ List all connected peers
    """
    peers = nago.core.get_peers()
    if search == "all":
        return peers
    elif search == 'unsigned':
        result = {}
        for token, peer in peers.items():
            if peer.get('access') is None:
                result[token] = peer
        return result
    else:
        result = {}
        for token, peer in peers.items():
            host_name = peer.get('host_name')
            if search in (token, host_name):
                result[token] = peer
        return result

@nago_access
def sign(node=None):
    """ Sign a specific node to grant it access

     you can specify "all" to sign all nodes

     returns the nodes that were signed
    """
    if not node:
        raise Exception("Specify either 'all' your specify token/host_name of node to sign. ")
    if node == 'all':
        node = 'unsigned'
    nodes = list(search=node)
    result = {}
    for token, i in nodes:
        i['access'] = 'node'
        i.save()
        result[token] = i
    return result

@nago_access
def set(token_or_hostname, **kwargs):
    """ Change the attributes of a connected peer """
    peer = nago.core.get_peer(security_token) or {}
    if not kwargs:
        return "No changes made"
    for k, v in kwargs.items():
        peer[k] = v
    peer.save()
    return "Saved %s changes" % len(kwargs)

{'fraction_non_alphanumeric': 0.11830461108523521, 'fraction_numerical': 0.0009315323707498836, 'mean_word_length': 2.414944356120827, 'pattern_counts': {'":': 1, '<': 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': '5968874', 'n_tokens_mistral': 641, 'n_tokens_neox': 642, 'n_words': 216}