code: def _handle_login(opt, action, bz):
      
      is_login_command = (action == 'login')
  
      do_interactive_login = (is_login_command or
          opt.login or opt.username or opt.password)
      username = getattr(opt, "pos_username", None) or opt.username
      password = getattr(opt, "pos_password", None) or opt.password
  
      try:
          if do_interactive_login:
              if bz.url:
                  print("Logging into %s" % urlparse(bz.url)[1])
              bz.interactive_login(username, password,
                      restrict_login=opt.restrict_login)
      except bugzilla.BugzillaError as e:
          print(str(e))
          sys.exit(1)
  
      if opt.ensure_logged_in and not bz.logged_in:
          print("--ensure-logged-in passed but you aren't logged in to %s" %
              bz.url)
          sys.exit(1)
  
      if is_login_command:
          msg = "Login successful."
          if bz.cookiefile or bz.tokenfile:
              msg = "Login successful, token cache updated."
  
          print(msg)
          sys.exit(0)
docs: Handle all login related bits