コード例 #1
0
    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))
コード例 #2
0
ファイル: test_utilities.py プロジェクト: Tribler/tribler
    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))
コード例 #3
0
ファイル: TorrentDef.py プロジェクト: joepeak/tribler
    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
コード例 #4
0
ファイル: TorrentDef.py プロジェクト: synctext/tribler
    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
コード例 #5
0
 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'
     ])
コード例 #6
0
ファイル: TorrentDef.py プロジェクト: joepeak/tribler
    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
コード例 #7
0
ファイル: TorrentDef.py プロジェクト: joepeak/tribler
    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
コード例 #8
0
ファイル: TorrentDef.py プロジェクト: zippav/tribler
    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
コード例 #9
0
ファイル: TorrentDef.py プロジェクト: Tribler/tribler
    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
コード例 #10
0
ファイル: TorrentDef.py プロジェクト: synctext/tribler
    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
コード例 #11
0
ファイル: TorrentDef.py プロジェクト: synctext/tribler
    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
コード例 #12
0
ファイル: TorrentDef.py プロジェクト: joepeak/tribler
    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
コード例 #13
0
ファイル: TorrentDef.py プロジェクト: synctext/tribler
    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
コード例 #14
0
 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))])
コード例 #15
0
 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