Exemple #1
0
 def data_received(self, data):
     """Called when some data is received.
     """
     self.timer.cancel()
     logger.debug('-> Data received: {!r}'.format(data))
     response = self.handle_data(data)
     if response is not None:
         logger.debug('<- Sending response: {!r}'.format(response))
         self.transport.write(response)
Exemple #2
0
 def connection_made(self, transport):
     """Called when a connection is made.
     """
     self.transport = transport
     peername = transport.get_extra_info('peername')
     self.ip = peername[0]
     self.client = "{:s}:{:d}".format(*peername)
     logger.debug('Connection from {}'.format(peername))
     clients.append(self)
     self.env = envs[self.ip]
Exemple #3
0
 def on_enq(self, data):
     """Calls on <ENQ> message receiving.
     """
     logger.debug('on_enq: %r', data)
     if not self.in_transfer_state:
         self.in_transfer_state = True
         return ACK
     else:
         logger.error('ENQ is not expected')
         return NAK
Exemple #4
0
 def on_eot(self, data):
     """Calls on <EOT> message receiving."""
     logger.debug('on_eot: %r', data)
     if self.in_transfer_state:
         # put the records together to a message
         if self.messages:
             message = b"".join(self.messages)
             self.queue.put_nowait(message)
         self.discard_env()
     else:
         raise InvalidState('Server is not ready to accept EOT message.')
Exemple #5
0
 def on_message(self, data):
     """Calls on ASTM message receiving."""
     logger.debug('on_message: %r', data)
     if not self.in_transfer_state:
         self.discard_chunked_messages()
         return NAK
     else:
         try:
             self.handle_message(data)
             return ACK
         except Exception as exc:
             logger.error(
                 'Error occurred on message handling. {!r}'.format(exc))
             return NAK
Exemple #6
0
 def dispatch_astm_message(message):
     """Dispatch astm message
     """
     logger.debug('Dispatching ASTM Message')
     if output:
         path = os.path.abspath(output)
         loop.create_task(asyncio.to_thread(write_message, message, path))
     if url:
         session = lims.Session(url)
         session_args = {
             'delay': args.delay,
             'retries': args.retries,
             'consumer': args.consumer,
         }
         loop.create_task(
             asyncio.to_thread(post_to_senaite, message, session,
                               **session_args))
Exemple #7
0
 def __init__(self, loop, queue, **kwargs):
     logger.debug("ASTMProtocol:constructor")
     # Invoke on_timeout callback *after* the given time.
     timeout = kwargs.get("timeout", TIMEOUT)
     self.timer = loop.call_later(timeout, self.on_timeout)
     self.queue = queue
Exemple #8
0
 def connection_lost(self, ex):
     """Called when the connection is lost or closed.
     """
     logger.debug('Connection lost: {!s}'.format(self.client))
     # remove the connected client
     clients.remove(self)
Exemple #9
0
 def on_timeout(self):
     """Calls when timeout event occurs. Used to limit waiting time for
     response data."""
     logger.debug("on_timeout")
     self.discard_env()
     self.transport.close()
Exemple #10
0
 def on_nak(self, data):
     """Calls on <NAK> message receiving."""
     logger.debug('on_nak: %r', data)
     raise NotAccepted('Server should not be NAKed.')