Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __hash__(self):
return hash(self.id)
def __str__(self):
return self.id
def __repr__(self):
v = vars(self)
return '{}({}{})'.format(type(self).__name__, repr(self.id), (', ' + ', '.join('{} = {}'.format(key, repr(v[key])) for key in v if key != '_id')) if len(v) > 1 else '')
@property
def id(self):
return self._id
class TCPNode(Node):
"""
A node intended for communication over TCP/IP. Its id is the network address (host:port).
"""
def __init__(self, address, **kwargs):
"""
Initialise the TCPNode
:param address: network address of the node in the format 'host:port'
:type address: str
:param **kwargs: any further information that should be kept about this node
"""
super(TCPNode, self).__init__(address, **kwargs)
self.address = address
self.host, port = address.rsplit(':', 1)
def __doChangeCluster(self, request, reverse = False):
requestType = request[0]
requestNodeId = request[1]
if len(request) >= 3:
requestNode = request[2]
if not isinstance(requestNode, Node): # Actually shouldn't be necessary, but better safe than sorry.
requestNode = self.__nodeClass(requestNode)
else:
requestNode = self.__nodeClass(requestNodeId)
if requestType == 'add':
adding = not reverse
elif requestType == 'rem':
adding = reverse
else:
return False
if adding:
newNode = requestNode
# Node already exists in cluster
if newNode is self.__selfNode or newNode in self.__otherNodes:
return False
def __eq__(self, other):
return isinstance(other, Node) and self.id == other.id
def __setattr__(self, name, value):
if name == 'id':
raise AttributeError('Node id is not mutable')
super(Node, self).__setattr__(name, value)
def removeNodeFromCluster(self, node, callback = None):
"""Remove single node from cluster (dynamic membership changes). Async.
You should wait until node successfully added before adding
next node.
:param node: node object or 'nodeHost:nodePort'
:type node: Node | str
:param callback: will be called on success or fail
:type callback: function(`FAIL_REASON <#pysyncobj.FAIL_REASON>`_, None)
"""
if not self.__conf.dynamicMembershipChange:
raise Exception('dynamicMembershipChange is disabled')
if not isinstance(node, Node):
node = self.__nodeClass(node)
self._applyCommand(pickle.dumps(['rem', node.id, node]), callback, _COMMAND_TYPE.MEMBERSHIP)
def setPartnerAddress(self, partner):
self.__node = Node(self, partner, True)