def connect_to_tracker(self): # create the HTTP GET message # Note: some trackers have strange URLs, e.g., # http://moviezone.ws/announce.php?passkey=8ae51c4b47d3e7d0774a720fa511cc2a # which has some sort of 'key' as parameter, so we need to use the add_url_params # utility function to handle such cases. url = add_url_params("http://%s:%s%s" % (self._tracker_address[0], self._tracker_address[1], self._announce_page.replace(u'announce', u'scrape')), {"info_hash": self._infohash_list}) # no more requests can be appended to this session self._is_initiated = True self._last_contact = int(time.time()) agent = RedirectAgent(Agent(reactor, connectTimeout=self.timeout, pool=self._connection_pool)) try: self.request = self.register_task("request", agent.request('GET', bytes(url))) self.request.addCallback(self.on_response) self.request.addErrback(self.on_error) self._logger.debug(u"%s HTTP SCRAPE message sent: %s", self, url) self.start_timeout() # Return deferred that will evaluate when the whole chain is done. self.result_deferred = self.register_task("result", Deferred(canceller=self._on_cancel)) except UnicodeEncodeError as e: self.result_deferred = defer.fail(e) return self.result_deferred
def test_add_url_param_some_present(self): url = 'http://stackoverflow.com/test?answers=true' new_params = {'answers': False, 'data': ['some', 'values']} result = add_url_params(url, new_params) self.assertEqual( result, 'http://stackoverflow.com/test?data=some&data=values&answers=false' )
def connect_to_tracker(self): # create the HTTP GET message # Note: some trackers have strange URLs, e.g., # http://moviezone.ws/announce.php?passkey=8ae51c4b47d3e7d0774a720fa511cc2a # which has some sort of 'key' as parameter, so we need to use the add_url_params # utility function to handle such cases. url = add_url_params( "http://%s:%s%s" % (self._tracker_address[0], self._tracker_address[1], self._announce_page.replace(u'announce', u'scrape')), {"info_hash": self._infohash_list}) # no more requests can be appended to this session self._is_initiated = True self._last_contact = int(time.time()) agent = RedirectAgent( Agent(reactor, connectTimeout=self.timeout, pool=self._connection_pool)) try: self.request = self.register_task("request", agent.request('GET', bytes(url))) self.request.addCallback(self.on_response) self.request.addErrback(self.on_error) self._logger.debug(u"%s HTTP SCRAPE message sent: %s", self, url) self.start_timeout() # Return deferred that will evaluate when the whole chain is done. self.result_deferred = self.register_task( "result", Deferred(canceller=self._on_cancel)) except UnicodeEncodeError as e: self.result_deferred = defer.fail(e) return self.result_deferred
def test_add_url_param_clean(self): url = 'http://stackoverflow.com/test' new_params = {'data': ['some', 'values']} result = add_url_params(url, new_params) self.assertEqual(result, 'http://stackoverflow.com/test?data=some&data=values')
def test_add_url_param_some_present(self): url = 'http://stackoverflow.com/test?answers=true' new_params = {'answers': False, 'data': ['some', 'values']} result = add_url_params(url, new_params) self.assertEqual(result, 'http://stackoverflow.com/test?data=some&data=values&answers=false')
def test_add_url_param_clean(self): url = 'http://stackoverflow.com/test' new_params = {'data': ['some', 'values']} result = add_url_params(url, new_params) self.assertEqual( result, 'http://stackoverflow.com/test?data=some&data=values')