2009/9/23 Guido Trotter <[email protected]>:
> --- a/lib/confd/client.py
> +++ b/lib/confd/client.py
> +class ConfdFilterCallback:
> +  def _LogFilter(self, salt, new_reply, old_reply):
> +    if not self._logger:
> +      return
> +
> +    if new_reply.serial > old_reply.serial:
> +      self._logger.debug("Filtering confirming answer, with newer"
> +          -              " serial for query %s" % salt)

TypeError: unsupported operand type(s) for -: 'str' and 'str'

> +    elif new_reply.serial == old_reply.serial:
> +      if new_reply.answer != old_reply.answer:
> +        self._logger.debug("Got incoherent answers for query %s"
> +                           " (serial: %s)" % (salt, new_reply.serial))
> +      else:
> +        self._logger.debug("Filtering confirming answer, with same"
> +                           " serial for query %s" % salt)
> +    else:
> +      self._logger.debug("Filtering outdated answer for query %s"
> +                         " serial: (%d < %d)" % (salt, old_reply.serial,
> +                                                 new_reply.serial))
> +
> +  def _HandleExpire(self, up):
> +    if salt in self._answers:
> +      del self._answers[salt]
> +
> +  def _HandleReply(self, up):
> +    filter_upcall = False
> +    salt = up.salt
> +    if salt not in self._answers:
> +      self._answers[salt] = up.server_reply
> +    elif up.server_reply.serial > self._answers[salt].serial:
> +      old_answer = self._answers[salt]
> +      self._answers[salt] = up.server_reply
> +      if up.server_reply.answer == old_answer.answer:
> +        filter_upcall = True
> +        self._LogFilter(self, salt, up.server_reply, old_answer)
> +    else:
> +      filter_upcall = True
> +      self._LogFilter(self, salt, up.server_reply, self._answers[salt])
> +
> +    return filter_upcall
> +
> +  def __call__(self, up):
> +    filter_upcall = False
> +    if up.type == UPCALL_REPLY:
> +      filter_upcall = self._HandleReply(up)
> +    elif up.type == UPCALL_EXPIRE:
> +      self._HandleExpire(up)

I think a lookup table might make sense here.

try:
  fn = self._handlers[up.type]
except KeyError:
  raise Exception("Unknown …")

return fn(up)

> +    if not filter_upcall:
> +      self._callback(up)

Reply via email to