def action(self): from miro import httpauth id_, args = self.args[0], self.args[1:] def callback(auth_header): c = GotHTTPAuthCommand(self.daemon, id_, auth_header) c.send() httpauth.ask_for_http_auth(callback, *args)
def _handle_auth(self, auth_type, header_key, url, location): # this method needs to run in the eventloop because it uses the # httpauth module. At this point the transfer is removed from # curl_manager's, so we don't have to worry about accessing our # attributes. self.current_auth_type = auth_type self.auth_attempts[auth_type] += 1 if auth_type == 'http' and self.http_auth is not None: httpauth.remove(self.http_auth) elif auth_type == 'proxy' and self.proxy_auth is not None: httpauth.remove(self.proxy_auth) if self.auth_attempts[auth_type] > MAX_AUTH_ATTEMPTS: self.handle_auth_failure() return try: auth_header = self.headers[header_key] except KeyError: self.handle_auth_failure() return if auth_type == 'http': # now that we have the www-authenticate header, try again to find # an existing password existing_auth = httpauth.find_http_auth(url, auth_header) if existing_auth is not None: self.http_auth = existing_auth self._send_new_request() return try: httpauth.ask_for_http_auth(self._ask_for_http_auth_callback, url, auth_header, location) except (AssertionError, ValueError), e: logging.warn("Error when parsing auth header: %s", e) self.handle_auth_failure()
def ask_for_http_auth(self, url, auth_header): httpauth.ask_for_http_auth(self.callback, url, auth_header, "My Location") self.runEventLoop(timeout=0.1) return self.callback_data