def test_valid_url(self): """ Test if the URL is valid """ test_url = "http://anno nce.torrentsmd.com:8080/announce" self.assertFalse(is_valid_url(test_url), "%s is not a valid URL" % test_url) test_url2 = "http://announce.torrentsmd.com:8080/announce " self.assertTrue(is_valid_url(test_url2), "%s is a valid URL" % test_url2) test_url3 = "http://localhost:1920/announce" self.assertTrue(is_valid_url(test_url3)) test_url4 = "udp://localhost:1264" self.assertTrue(is_valid_url(test_url4))
def set_tracker_hierarchy(self, hier): """ Set hierarchy of trackers (announce-list) following the spec at http://www.bittorrent.org/beps/bep_0012.html @param hier A hierarchy of trackers as a list of lists. """ # TODO: check input, in particular remove / at end newhier = [] if not isinstance(hier, ListType): raise ValueError("hierarchy is not a list") for tier in hier: if not isinstance(tier, ListType): raise ValueError("tier is not a list") newtier = [] for url in tier: if not is_valid_url(url): self._logger.error("Invalid tracker URL: %s", repr(url)) continue if url.endswith('/'): # Some tracker code can't deal with / at end url = url[:-1] if self.get_tracker() is None: # Backwards compatibility Multitracker Metadata Extension self.set_tracker(url) newtier.append(url) newhier.append(newtier) self.input['announce-list'] = newhier self.metainfo_valid = False
def get_valid_trackers_of_torrent(self, torrent_id): """ Get a set of valid trackers for torrent. Also remove any invalid torrent.""" db_tracker_list = self._torrent_db.getTrackerListByTorrentID( torrent_id) return set([ tracker for tracker in db_tracker_list if is_valid_url(tracker) or tracker == u'DHT' ])
def set_httpseeds(self, value): """ Set list of HTTP seeds following the BEP 17 spec (John Hoffman style): http://www.bittorrent.org/beps/bep_0017.html @param value A list of URLs. """ for url in value: if not is_valid_url(url): raise ValueError("Invalid URL: " + repr(url)) self.input['httpseeds'] = value self.metainfo_valid = False
def set_urllist(self, value): """ Set list of HTTP seeds following the BEP 19 spec (GetRight style): http://www.bittorrent.org/beps/bep_0019.html @param value A list of URLs. """ for url in value: if not is_valid_url(url): raise ValueError("Invalid URL: " + repr(url)) self.input['url-list'] = value self.metainfo_valid = False
def set_tracker(self, url): """ Set the tracker of this torrent, according to a given URL. :param url: The tracker url. """ if not is_valid_url(url): raise ValueError("Invalid URL") if url.endswith('/'): # Some tracker code can't deal with / at end url = url[:-1] self.torrent_parameters['announce'] = url
def set_tracker(self, url): """ Sets the tracker (i.e. the torrent file's 'announce' field). @param url The announce URL. """ if not is_valid_url(url): raise ValueError("Invalid URL") if url.endswith('/'): # Some tracker code can't deal with / at end url = url[:-1] self.input['announce'] = url self.metainfo_valid = False
def get_valid_trackers_of_torrent(self, torrent_id): """ Get a set of valid trackers for torrent. Also remove any invalid torrent.""" db_tracker_list = self.tribler_session.lm.mds.TorrentState.get(infohash=database_blob(torrent_id)).trackers return set([str(tracker.url) for tracker in db_tracker_list if is_valid_url(str(tracker.url)) and not self.is_blacklisted_tracker(str(tracker.url))])
def get_valid_next_tracker_for_auto_check(self): tracker_url = self.get_next_tracker_for_auto_check() while tracker_url and not is_valid_url(tracker_url): self.remove_tracker(tracker_url) tracker_url = self.get_next_tracker_for_auto_check() return tracker_url