Exemplo n.º 1
0
 def _receive_response(self, response_obj, timeout_secs):
     # If our response object is fixed width, then just read the number of bytes
     # we need, parse the response, and return.
     if response_obj.isFixedWidth():
         len_obj = response_obj.getWidth()
         data = self.connection.read(len_obj, timeout_secs)
         match_obj = response_obj.isMatch(data, 0)
         # If we got a match, then return success!
         if match_obj.isMatch() == 1:
             return 1
         # Apparently we didn't get the response we were expecting.  Return failure.
         return 0
     else:
         # Our response object is not fixed width, so read data one byte at a time
         # until we either get a full match, a definitive non-match or a timeout.
         data = ''
         st_time = gdutil.get_time()
         while 1:
             curtime = gdutil.get_time()
             if curtime - st_time > timeout_secs:
                 raise gdutil.GDTimeoutException("Got trying to read matching data")
             new_data = self.connection.read(1, timeout_secs)
             if new_data:
                 data += new_data
             if self.debug > 2:
                 print 'calling isMatch with %s' % gdutil.dump_binary_str(data)
             match_obj = response_obj.isMatch(data, 0)
             # If we got a match, then return success!
             if match_obj.isMatch() == 1:
                 return 1
             # If we got a definitive non-match, return failure.
             if match_obj.isNotMatch() == 1:
                 return 0        
Exemplo n.º 2
0
 def isMatch(self, data, offset):
     if self.debug > 6:
         print 'In isMatch() with offset %d, and data.' % offset, gdutil.dump_binary_str(data)
     val = self._getValue(data, offset)
     if val is None:
         # Don't have enough data yet.
         return IsMatchReturn(0)
     if self.debug > 6:
         print 'Got val of %s' % str(val)
     if not self.initial_value is None:
         if self._float_cmp(self.initial_value, val) == 0:
             self.value = val
             if self.debug > 6:
                 print 'Got a match for %s.' % str(val)
             self.updateNodeValue(val)
             return IsMatchReturn(1, self.getWidth())
         else:
             return IsMatchReturn(-1)
     else:
         # If we don't have an initial value, then anything is a match.
         #print 'No initial value.'
         self.value = val
         self.updateNodeValue(val)
         return IsMatchReturn(1, self.getWidth())