code: def _decorate(flush=True, attempts=1, only_authenticate=False):
      
      def decorator(function):
          def decorated(job, host, conn, *args, **kwargs):
              failed = 0
              while True:
                  try:
                      if only_authenticate:
                          conn.authenticate(flush=flush)
                      else:
                          conn.login(flush=flush)
                  except LoginFailure as e:
                      failed += 1
                      if failed >= attempts:
                          raise
                      continue
                  break
              return function(job, host, conn, *args, **kwargs)
          copy_labels(function, decorated)
          return decorated
      return decorator
docs: Wraps the given function such that conn.login() or conn.authenticate() is
      executed.
      Doing the real work for autologin and autoauthenticate to minimize code
      duplication.
  
      :type  flush: bool
      :param flush: Whether to flush the last prompt from the buffer.
      :type  attempts: int
      :param attempts: The number of login attempts if login fails.
      :type only_authenticate: bool
      :param only_authenticate: login or only authenticate (don't authorize)?
      :rtype:  function
      :return: The wrapped function.