def test_is_allowed_mimetype(self): # negative tests for test in ["text/plain", "foo", "", None, ]: self.assertEqual(filetypes.is_allowed_mimetype(test), False) # positive tests for test in ["video/flv", "audio/mp4", "application/x-bittorrent", ]: self.assertEqual(filetypes.is_allowed_mimetype(test), True)
def test_is_allowed_mimetype(self): # negative tests for test in [ "text/plain", "foo", "", None, ]: self.assertEqual(filetypes.is_allowed_mimetype(test), False) # positive tests for test in [ "video/flv", "audio/mp4", "application/x-bittorrent", ]: self.assertEqual(filetypes.is_allowed_mimetype(test), True)
def should_load_mimetype(self, url, mimetype): """Like should_load_url(), but for mimetype checking. """ # FIXME: this never gets called on windows if filetypes.is_allowed_mimetype(mimetype): logging.debug("miro wants to handle %s", url) metadata = {'mime_type': mimetype} self.emit('download-started') messages.DownloadURL(url, self.unknown_callback, metadata).send_to_backend() return False return True
def should_load_url(self, url, mimetype=None): """Returns True if the Miro browser should handle the url and False otherwise. Situations which should return false: * if the url is something that Miro should download instead * other things? """ if mimetype is not None: logging.debug("got %s (%s)", url, mimetype) else: logging.debug("got %s", url) if url in self.seen_cache: del self.seen_cache[url] return True url = util.to_uni(url) if subscription.is_subscribe_link(url): messages.SubscriptionLinkClicked(url).send_to_backend() return False def unknown_callback(url): call_on_ui_thread(self.handle_unknown_url, url) if filetypes.is_maybe_rss_url(url): logging.debug("miro wants to handle %s", url) messages.DownloadURL(url, unknown_callback).send_to_backend() return False # parse the path out of the url and run that through the filetypes # code to see if it might be a video, audio or torrent file. # if so, try downloading it. ret = urlparse(url) if filetypes.is_allowed_filename(ret[2]): logging.debug("miro wants to handle %s", url) messages.DownloadURL(url, unknown_callback).send_to_backend() return False if mimetype is not None and filetypes.is_allowed_mimetype(mimetype): logging.debug("miro wants to handle %s", url) messages.DownloadURL(url, unknown_callback).send_to_backend() return False return True