<commit_before>from typing import Callable, Iterable
from plenum.server.quorums import Quorums


class NetworkI3PCWatcher:
    def __init__(self, cb: Callable):
        self.nodes = set()
        self.connected = set()
        self.callback = cb
        self.quorums = Quorums(0)

    def connect(self, name: str):
        self.connected.add(name)

    def disconnect(self, name: str):
        had_consensus = self._has_consensus()
        self.connected.discard(name)
        if had_consensus and not self._has_consensus():
            self.callback()

    def set_nodes(self, nodes: Iterable[str]):
        self.nodes = set(nodes)
        self.quorums = Quorums(len(self.nodes))

    def _has_consensus(self):
        return self.quorums.weak.is_reached(len(self.connected))
<commit_msg>INDY-1199: Make interface of NetworkI3PCWatcher more clear<commit_after>from typing import Callable, Iterable
from plenum.server.quorums import Quorums


class NetworkI3PCWatcher:
    def __init__(self, cb: Callable):
        self._nodes = set()
        self.connected = set()
        self.callback = cb
        self.quorums = Quorums(0)

    def connect(self, name: str):
        self.connected.add(name)

    def disconnect(self, name: str):
        had_consensus = self._has_consensus()
        self.connected.discard(name)
        if had_consensus and not self._has_consensus():
            self.callback()

    @property
    def nodes(self):
        return self._nodes

    def set_nodes(self, nodes: Iterable[str]):
        self._nodes = set(nodes)
        self.quorums = Quorums(len(self._nodes))

    def _has_consensus(self):
        return self.quorums.weak.is_reached(len(self.connected))

{'fraction_non_alphanumeric': 0.10361160449970397, 'fraction_numerical': 0.0053285968028419185, 'mean_word_length': 2.81489841986456, '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': '6935227', 'n_tokens_mistral': 545, 'n_tokens_neox': 527, 'n_words': 117}