Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
cmd = funcID
sync = kwargs.pop('sync', False)
if callback is not None:
sync = False
if sync:
asyncResult = AsyncResult()
callback = asyncResult.onResult
timeout = kwargs.pop('timeout', None)
applier(pickle.dumps(cmd), callback, _COMMAND_TYPE.REGULAR)
if sync:
res = asyncResult.event.wait(timeout)
if not res:
raise SyncObjException('Timeout')
if not asyncResult.error == 0:
raise SyncObjException(asyncResult.error)
return asyncResult.result
if callback is not None:
sync = False
if sync:
asyncResult = AsyncResult()
callback = asyncResult.onResult
timeout = kwargs.pop('timeout', None)
applier(pickle.dumps(cmd), callback, _COMMAND_TYPE.REGULAR)
if sync:
res = asyncResult.event.wait(timeout)
if not res:
raise SyncObjException('Timeout')
if not asyncResult.error == 0:
raise SyncObjException(asyncResult.error)
return asyncResult.result
self.__conf.validate()
if self.__conf.password is not None:
if not HAS_CRYPTO:
raise ImportError("Please install 'cryptography' module")
self.__encryptor = getEncryptor(self.__conf.password)
else:
self.__encryptor = None
consumers = consumers or []
newConsumers = []
for c in consumers:
if not isinstance(c, SyncObjConsumer) and getattr(c, '_consumer', None):
c = c._consumer()
if not isinstance(c, SyncObjConsumer):
raise SyncObjException('Consumers must be inherited from SyncObjConsumer')
newConsumers.append(c)
consumers = newConsumers
self.__consumers = consumers
if not isinstance(selfNode, Node) and selfNode is not None:
selfNode = nodeClass(selfNode)
self.__selfNode = selfNode
self.__otherNodes = set() # set of Node
for otherNode in otherNodes:
if not isinstance(otherNode, Node):
otherNode = nodeClass(otherNode)
self.__otherNodes.add(otherNode)
self.__readonlyNodes = set() # set of Node
self.__connectedNodes = set() # set of Node
self.__nodeClass = nodeClass
def newFunc(self, *args, **kwargs):
if kwargs.pop('_doApply', False):
return func(self, *args, **kwargs)
else:
if isinstance(self, SyncObj):
applier = self._applyCommand
funcName = self._getFuncName(func.__name__)
funcID = self._methodToID[funcName]
elif isinstance(self, SyncObjConsumer):
consumerId = id(self)
funcName = self._syncObj._getFuncName((consumerId, func.__name__))
funcID = self._syncObj._methodToID[(consumerId, funcName)]
applier = self._syncObj._applyCommand
else:
raise SyncObjException("Class should be inherited from SyncObj or SyncObjConsumer")
callback = kwargs.pop('callback', None)
if kwargs:
cmd = (funcID, args, kwargs)
elif args and not kwargs:
cmd = (funcID, args)
else:
cmd = funcID
sync = kwargs.pop('sync', False)
if callback is not None:
sync = False
if sync:
asyncResult = AsyncResult()
callback = asyncResult.onResult
def __init__(self, ver):
SyncObjException.__init__(self, 'wrongVer')
self.ver = ver