def get_file(url, cookies={}, verify=True): class Request(object): pass r = Request try: r.content = read_file(url) except Exception, e: pass
def get_file(url, cookies={}, headers={}, verify=True): class Request(object): pass r = Request try: r.content = read_file(url) except Exception: pass return r
def download_torrent_file(self, torrent_url, cookies_dict): download = TorrentDownload() download.torrent_url = torrent_url download.cookies_dict = cookies_dict download.torrent_url = torrent_url download.success = self.download_success if self.use_filedump: download.filedump = self.use_filedump elif os.path.isfile(torrent_url): download.filedump = read_file(torrent_url) self.downloads.append(download) return download
def download_torrent_file(self, torrent_url, cookies=None, headers=None): download = TorrentDownload() download.torrent_url = torrent_url download.cookies = cookies download.headers = headers download.torrent_url = torrent_url download.success = self.download_success if self.use_filedump: download.filedump = self.use_filedump elif os.path.isfile(torrent_url): download.filedump = read_file(torrent_url) self.downloads.append(download) return download
def test_get_torrent(self): handler = TorrentHandler(self.log) handler.download_torrent_file = test_component.download_torrent_file filename = yarss2.util.common.get_resource( "FreeBSD-9.0-RELEASE-amd64-dvd1.torrent", path="tests/data/") test_component.use_filedump = read_file(filename) torrent_info = { "link": "http://url.com/file.torrent", "site_cookies_dict": { "cookiekey": "cookievalue" }, "user_agent": "test" } download = handler.get_torrent(torrent_info) self.assertEquals(download.headers, {'User-Agent': 'test'}) self.assertEquals(download.cookies, {'cookiekey': 'cookievalue'}) self.assertFalse(download.is_magnet)
def test_add_torrents(self): handler = TorrentHandler(self.log) from yarss2.rssfeed_handling import RSSFeedHandler self.rssfeedhandler = RSSFeedHandler(self.log) # Override method download_torrent_file handler.download_torrent_file = test_component.download_torrent_file filename = yarss2.util.common.get_resource("FreeBSD-9.0-RELEASE-amd64-dvd1.torrent", path="tests/data/") test_component.use_filedump = read_file(filename) config = get_test_config_dict() # 0 is the rssfeed key match_result = self.rssfeedhandler.fetch_feed_torrents(config, "0") matching_torrents = match_result["matching_torrents"] saved_subscriptions = [] def save_subscription_func(subscription_data): saved_subscriptions.append(subscription_data) handler.add_torrents(save_subscription_func, matching_torrents, self.config.get_config()) self.assertEquals(len(saved_subscriptions), 1) handler.use_filedump = None
def test_add_torrents(self): handler = TorrentHandler(self.log) from yarss2.rssfeed_handling import RSSFeedHandler self.rssfeedhandler = RSSFeedHandler(self.log) # Override method download_torrent_file handler.download_torrent_file = test_component.download_torrent_file filename = yarss2.util.common.get_resource( "FreeBSD-9.0-RELEASE-amd64-dvd1.torrent", path="tests/data/") test_component.use_filedump = read_file(filename) config = get_test_config_dict() # 0 is the rssfeed key match_result = self.rssfeedhandler.fetch_feed_torrents(config, "0") matching_torrents = match_result["matching_torrents"] saved_subscriptions = [] def save_subscription_func(subscription_data): saved_subscriptions.append(subscription_data) handler.add_torrents(save_subscription_func, matching_torrents, self.config.get_config()) self.assertEquals(len(saved_subscriptions), 3) handler.use_filedump = None