Revision aa2efc52 lib/confd/client.py

b/lib/confd/client.py
607 607
    self._callback(up)
608 608

  
609 609

  
610
class StoreResultCallback:
611
  """Callback that simply stores the most recent answer.
612

  
613
  @ivar _answers: dict of salt to (have_answer, reply)
614

  
615
  """
616
  _NO_KEY = (False, None)
617

  
618
  def __init__(self):
619
    """Constructor for StoreResultCallback
620

  
621
    """
622
    # answers contains a dict of salt -> best result
623
    self._answers = {}
624

  
625
  def GetResponse(self, salt):
626
    """Return the best match for a salt
627

  
628
    """
629
    return self._answers.get(salt, self._NO_KEY)
630

  
631
  def _HandleExpire(self, up):
632
    """Expiration handler.
633

  
634
    """
635
    if up.salt in self._answers and self._answers[up.salt] == self._NO_KEY:
636
      del self._answers[up.salt]
637

  
638
  def _HandleReply(self, up):
639
    """Handle a single confd reply, and decide whether to filter it.
640

  
641
    """
642
    self._answers[up.salt] = (True, up)
643

  
644
  def __call__(self, up):
645
    """Filtering callback
646

  
647
    @type up: L{ConfdUpcallPayload}
648
    @param up: upper callback
649

  
650
    """
651
    if up.type == UPCALL_REPLY:
652
      self._HandleReply(up)
653
    elif up.type == UPCALL_EXPIRE:
654
      self._HandleExpire(up)
655

  
656

  
610 657
def GetConfdClient(callback):
611 658
  """Return a client configured using the given callback.
612 659

  

Also available in: Unified diff