def on_response(self, url, response): try: from urlparse import urlparse except ImportError: # Python 3.X from urllib import parse as urlparse if response.error: self.write("Unable to fetch icon.") self.finish() return fetch_url = None try: content = response.body.decode("utf-8") except UnicodeDecodeError: content = response.body parsed_url = urlparse(url) (fetch_url, mimetype) = self.get_favicon_url(content) if fetch_url: if not fetch_url.startswith("http"): fetch_url = "%s://%s%s" % (parsed_url.scheme, parsed_url.netloc, fetch_url) if not mimetype: mimetype = "image/x-icon" # Default if not fetch_url: fetch_url = "%s://%s/favicon.ico" % (parsed_url.scheme, parsed_url.netloc) if fetch_url.startswith("http://") or fetch_url.startswith("https://"): noop() else: raise tornado.web.HTTPError(404) http = tornado.httpclient.AsyncHTTPClient() callback = partial(self.icon_fetch, url, mimetype) try: http.fetch(fetch_url, callback, connect_timeout=5.0, request_timeout=5.0) except gaierror: # No address associated with hostname self.write("Unable to fetch icon.") self.finish() return
async def ask_for_confirmation(self, user, success_callback: Optional[Awaitable], fail_callback: Optional[Awaitable]): # Raises ValueError if the user is already in the confirmation queue. if user in self.confirmation_queue: raise ValueError(f'{user} is already in the confirmation queue') if success_callback is None: success_callback = utils.noop() if fail_callback is None: fail_callback = utils.noop() self.confirmation_queue[user] = (success_callback, fail_callback)
def on_response(self, url, response): try: from urlparse import urlparse except ImportError: # Python 3.X from urllib import parse as urlparse if response.error: self.write('Unable to fetch icon.') self.finish() return fetch_url = None try: content = response.body.decode('utf-8') except UnicodeDecodeError: content = response.body parsed_url = urlparse(url) (fetch_url, mimetype) = self.get_favicon_url(content) if fetch_url: if not fetch_url.startswith('http'): fetch_url = '%s://%s%s' % ( parsed_url.scheme, parsed_url.netloc, fetch_url) if not mimetype: mimetype = "image/x-icon" # Default if not fetch_url: fetch_url = '%s://%s/favicon.ico' % ( parsed_url.scheme, parsed_url.netloc) if fetch_url.startswith('http://') or fetch_url.startswith('https://'): noop() else: raise tornado.web.HTTPError(404) http = tornado.httpclient.AsyncHTTPClient() callback = partial(self.icon_fetch, url, mimetype) try: http.fetch( fetch_url, callback, connect_timeout=5.0, request_timeout=5.0 ) except socket.gaierror: # No address associated with hostname self.write('Unable to fetch icon.') self.finish() return
def close(self): return noop()
def update(self, **kwargs): return noop()
def create(self, title, subtitle): return noop()