Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def handle_api(loop, term_ev, term_barrier, server, registry):
request_id = 0
while not term_ev.is_set():
try:
req_data = await server.read()
except aiozmq.stream.ZmqStreamClosed:
break
req = Message.decode(req_data[0])
resp = Message()
request_id += 1
if 'action' not in req:
log.warn(_r('Malformed API request!', request_id))
resp['reply'] = SornaResponseTypes.INVALID_INPUT
resp['cause'] = 'Malformed API request.'
elif req['action'] == ManagerRequestTypes.PING:
try:
log.info(_r('PING (body:{})', request_id, req['body']))
except KeyError:
log.warn(_r('PING: invalid parameters', request_id))
def read(self):
if self._exception is not None:
raise self._exception
if self._closing:
raise ZmqStreamClosed()
if not self._queue_len:
if self._waiter is not None:
raise RuntimeError('read called while another coroutine is '
'already waiting for incoming data')
self._waiter = asyncio.Future(loop=self._loop)
try:
yield from self._waiter
finally:
self._waiter = None
msg_len, msg = self._queue.popleft()
self._queue_len -= msg_len
self._maybe_resume_transport()
return msg
def read_event(self):
if self._closing:
raise ZmqStreamClosed()
if not self._event_queue:
if self._event_waiter is not None:
raise RuntimeError('read_event called while another coroutine'
' is already waiting for incoming data')
self._event_waiter = asyncio.Future(loop=self._loop)
try:
yield from self._event_waiter
finally:
self._event_waiter = None
event = self._event_queue.popleft()
return event
def feed_closing(self):
"""Private"""
self._closing = True
self._transport = None
waiter = self._waiter
if waiter is not None:
self._waiter = None
if not waiter.cancelled():
waiter.set_exception(ZmqStreamClosed())
waiter = self._event_waiter
if waiter is not None:
self._event_waiter = None
if not waiter.cancelled():
waiter.set_exception(ZmqStreamClosed())
serial = int(match.group('serial')) if match.group('serial') else 0
return VersionInfo(major, minor, micro, releaselevel, serial)
except Exception:
raise ImportError("Invalid package version {}".format(ver))
version_info = _parse_version(__version__)
if zmq.zmq_version_info()[0] < 3: # pragma no cover
raise ImportError("aiozmq doesn't support libzmq < 3.0")
# make pyflakes happy
(ZmqSelector, ZmqEventLoop, ZmqEventLoopPolicy, ZmqTransport, ZmqProtocol,
ZmqStream, ZmqStreamProtocol, ZmqStreamClosed, create_zmq_stream,
create_zmq_connection)
serial = int(match.group('serial')) if match.group('serial') else 0
return VersionInfo(major, minor, micro, releaselevel, serial)
except Exception:
raise ImportError("Invalid package version {}".format(ver))
version_info = _parse_version(__version__)
if zmq.zmq_version_info()[0] < 3: # pragma no cover
raise ImportError("aiozmq doesn't support libzmq < 3.0")
# make pyflakes happy
(ZmqSelector, ZmqEventLoop, ZmqEventLoopPolicy, ZmqTransport, ZmqProtocol,
ZmqStream, ZmqStreamProtocol, ZmqStreamClosed, create_zmq_stream,
create_zmq_connection)