def get(self,
         message_template,
         timeout=None,
         header_filter=None,
         latest=None):
     header_fields = message_template.header_parameters
     logger.trace("Get message with params %s" % header_fields)
     if latest:
         self._fill_cache()
     msg = self._get_from_cache(message_template, header_fields,
                                header_filter, latest)
     if msg:
         logger.trace("Cache hit. Cache currently has %s messages" %
                      len(self._cache))
         return msg
     cutoff = time.time() + float(timeout if timeout else 0)
     while not timeout or time.time() < cutoff:
         with self._lock:
             header, pdu_bytes = self._protocol.read(self._stream,
                                                     timeout=timeout)
             if self._matches(header, header_fields, header_filter):
                 return self._to_msg(message_template, header, pdu_bytes)
             else:
                 self._match_or_cache(header, pdu_bytes)
     raise AssertionError('Timeout %fs exceeded in message stream.' %
                          float(timeout))
 def _decode_one(self, data, bag, little_endian=False):
     for case in self._fields.values():
         try:
             match = case.decode(data, bag, little_endian=little_endian)
             logger.trace("'%s' matches in bag '%s'. value: %r" % (case.name, self.name, match[match.len - 1]))
             return match
         except Exception as e:
             logger.trace("'%s' does not match in bag '%s'. Error: %s" % (case.name, self.name, e.message))
     raise AssertionError("Unable to decode bag value.")
 def get(self, message_template, timeout=None, header_filter=None):
     header_fields = message_template.header_parameters
     logger.trace("Get message with params %s" % header_fields)
     msg = self._get_from_cache(message_template, header_fields, header_filter)
     if msg:
         logger.trace("Cache hit. Cache currently has %s messages" % len(self._cache))
         return msg
     while True:
         with LOCK:
             header, pdu_bytes = self._protocol.read(self._stream, timeout=timeout)
             if self._matches(header, header_fields, header_filter):
                 return self._to_msg(message_template, header, pdu_bytes)
             else:
                 self._match_or_cache(header, pdu_bytes)
Exemple #4
0
 def get(self, message_template, timeout=None, header_filter=None):
     header_fields = message_template.header_parameters
     logger.trace("Get message with params %s" % header_fields)
     msg = self._get_from_cache(message_template, header_fields,
                                header_filter)
     if msg:
         logger.trace("Cache hit. Cache currently has %s messages" %
                      len(self._cache))
         return msg
     while True:
         with LOCK:
             header, pdu_bytes = self._protocol.read(self._stream,
                                                     timeout=timeout)
             if self._matches(header, header_fields, header_filter):
                 return self._to_msg(message_template, header, pdu_bytes)
             else:
                 self._match_or_cache(header, pdu_bytes)
Exemple #5
0
 def get(self, message_template, timeout=None, header_filter=None, latest=None):
     header_fields = message_template.header_parameters
     logger.trace("Get message with params %s" % header_fields)
     if latest:
         self._fill_cache()
     msg = self._get_from_cache(message_template, header_fields, header_filter, latest)
     if msg:
         logger.trace("Cache hit. Cache currently has %s messages" % len(self._cache))
         return msg
     cutoff = time.time() + float(timeout if timeout else 0)
     while not timeout or time.time() < cutoff:
         with LOCK:
             header, pdu_bytes = self._protocol.read(self._stream, timeout=timeout)
             if self._matches(header, header_fields, header_filter):
                 return self._to_msg(message_template, header, pdu_bytes)
             else:
                 self._match_or_cache(header, pdu_bytes)
     raise AssertionError('Timeout %fs exceeded in message stream.' % float(timeout))