Changeset 6bb4559
- Timestamp:
- 05/08/2010 06:26:08 AM (15 years ago)
- Children:
- 8f021c
- Parents:
- 7c9eea
- git-author:
- John Garland <johnnybg+deluge@gmail.com> (05/08/2010 06:24:16 AM)
- git-committer:
- John Garland <johnnybg+deluge@gmail.com> (05/08/2010 06:26:08 AM)
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
deluge/ui/tracker_icons.py
r7c9eea r6bb4559 153 153 154 154 self.pending = {} 155 self.redirects = {} 155 156 156 157 def get(self, host): … … 203 204 """ 204 205 if not url: 205 url = host_to_url(host)206 url = self.host_to_url(host) 206 207 log.debug("Downloading %s", url) 207 208 return download_file(url, mkstemp()[1], force_filename=True) … … 236 237 if f.check(error.PageRedirect): 237 238 # Handle redirect errors 238 location = urljoin(host_to_url(host), error_msg.split(" to ")[1]) 239 location = urljoin(self.host_to_url(host), error_msg.split(" to ")[1]) 240 self.redirects[host] = url_to_host(location) 239 241 d = self.download_page(host, url=location) 240 242 d.addCallbacks(self.on_download_page_complete, self.on_download_page_fail, … … 276 278 """ 277 279 log.debug("Got icons for %s: %s", host, icons) 278 url = host_to_url(host)280 url = self.host_to_url(host) 279 281 icons = [(urljoin(url, icon), mimetype) for icon, mimetype in icons] 280 282 log.debug("Icon urls: %s", icons) … … 346 348 if f.check(error.PageRedirect): 347 349 # Handle redirect errors 348 location = urljoin( host_to_url(host), error_msg.split(" to ")[1])350 location = urljoin(self.host_to_url(host), error_msg.split(" to ")[1]) 349 351 d = self.download_icon([(location, extension_to_mimetype(location.rpartition('.')[2]))] + icons, host) 350 352 if not icons: … … 355 357 elif f.check(IndexError, HTMLParseError): 356 358 # No icons, try favicon.ico as an act of desperation 357 d = self.download_icon([(urljoin( host_to_url(host), "favicon.ico"), extension_to_mimetype("ico"))], host)359 d = self.download_icon([(urljoin(self.host_to_url(host), "favicon.ico"), extension_to_mimetype("ico"))], host) 358 360 d.addCallbacks(self.on_download_icon_complete, self.on_download_icon_fail, 359 361 callbackArgs=(host,), errbackArgs=(host,)) … … 404 406 del self.pending[host] 405 407 return icon 408 409 def host_to_url(self, host): 410 """ 411 Given a host, returns the URL to fetch 412 413 :param host: the tracker host 414 :type host: string 415 :returns: the url of the tracker 416 :rtype: string 417 """ 418 if host in self.redirects: 419 host = self.redirects[host] 420 return "http://%s/" % host 406 421 407 422 ################################ HELPER CLASSES ############################### … … 451 466 ############################### HELPER FUNCTIONS ############################## 452 467 453 def host_to_url(host):454 """455 Given a host, returns the URL to fetch456 457 :param host: the tracker host458 :type host: string459 :returns: the url of the tracker460 :rtype: string461 """462 return "http://%s/" % host463 464 468 def url_to_host(url): 465 469 """ -
tests/test_tracker_icons.py
r7c9eea r6bb4559 53 53 d.addCallback(self.assertEquals, icon) 54 54 return d 55 56 def test_get_publicbt_ico(self): 57 icon = TrackerIcon("../publicbt.ico") 58 d = icons.get("publicbt.org") 59 d.addCallback(self.assertNotIdentical, None) 60 d.addCallback(self.assertEquals, icon) 61 return d
Note:
See TracChangeset
for help on using the changeset viewer.