class_docstr: A Thread for running a zmq Authenticator
  
  This is run in the background by ThreadedAuthenticator
class_docstr_tok: ["A","Thread","for","running","a","zmq","Authenticator","This","is","run","in","the","background","by","ThreadedAuthenticator"]
docstr: Handle a message from front-end API.
docstr_tok: ["Handle","a","message","from","front-end","API","."]
code: def _handle_pipe(self, msg):
      """
      Handle a message from front-end API.
      """
      terminate = False
  
      if msg is None:
          terminate = True
          return terminate
  
      command = msg[0]
      self.log.debug("auth received API command %r", command)
  
      if command == b"ALLOW":
          addresses = [u(m, self.encoding) for m in msg[1:]]
          try:
              self.authenticator.allow(*addresses)
          except Exception as e:
              self.log.exception("Failed to allow %s", addresses)
  
      elif command == b"DENY":
          addresses = [u(m, self.encoding) for m in msg[1:]]
          try:
              self.authenticator.deny(*addresses)
          except Exception as e:
              self.log.exception("Failed to deny %s", addresses)
  
      elif command == b"PLAIN":
          domain = u(msg[1], self.encoding)
          json_passwords = msg[2]
          self.authenticator.configure_plain(
              domain, jsonapi.loads(json_passwords)
          )
  
      elif command == b"CURVE":
          # For now we don't do anything with domains
          domain = u(msg[1], self.encoding)
  
          # If location is CURVE_ALLOW_ANY, allow all clients. Otherwise
          # treat location as a directory that holds the certificates.
          location = u(msg[2], self.encoding)
          self.authenticator.configure_curve(domain, location)
  
      elif command == b"TERMINATE":
          terminate = True
  
      else:
          self.log.error("Invalid auth command from API: %r", command)
  
      return terminate
  
imports: import time
  import logging
  from threading import Thread, Event
  import zmq
  from zmq.utils import jsonapi
  from zmq.utils.strtypes import bytes, unicode, b, u
  import sys
  from .base import Authenticator
label_desc: Use image node_id 4 for calling the AuthenticationThread obj's underlying member method code with example usage: obj._handle_pipe(msg) and returns: terminate, terminate