Ticket #2861: deluge-libtorrent-1.1-geoip.patch
File deluge-libtorrent-1.1-geoip.patch, 2.9 KB (added by , 8 years ago) |
---|
-
deluge/core/preferencesmanager.py
a b from deluge.event import ConfigValueChan 22 22 23 23 log = logging.getLogger(__name__) 24 24 25 try: 26 import GeoIP 27 except ImportError: 28 GeoIP = None 29 25 30 DEFAULT_PREFS = { 26 31 "send_info": False, 27 32 "info_sent": 0.0, … … class PreferencesManager(component.Compo 124 129 self.core = component.get("Core") 125 130 self.session = component.get("Core").session 126 131 self.new_release_timer = None 132 self.geoip_instance = None 127 133 128 134 def start(self): 129 135 # Set the initial preferences on start-up … … def _on_set_geoip_db_location(self, key, value): 446 452 if geoip_db: 447 453 try: 448 454 self.session.load_country_db(str(geoip_db)) 449 except RuntimeError as ex: 450 log.error("Unable to load geoip database!") 451 log.exception(ex) 452 except AttributeError: 453 log.warning("GeoIP Unavailable") 455 except (AttributeError, RuntimeError): 456 try: 457 self.geoip_instance = GeoIP.open(geoip_db, GeoIP.GEOIP_STANDARD) 458 except AttributeError: 459 log.warning("GeoIP Unavailable") 460 except Exception as ex: 461 log.error("Unable to load geoip database!") 462 log.exception(ex) 454 463 455 464 def _on_set_cache_size(self, key, value): 456 465 log.debug("%s: %s", key, value) -
deluge/core/torrent.py
a b class Torrent(object): 792 792 continue 793 793 794 794 client = decode_string(str(peer.client)) 795 796 try: 797 country = peer.country 798 except AttributeError: 799 country = "" 800 801 gi = component.get("PreferencesManager").geoip_instance 802 if gi: 803 try: 804 country = gi.country_code_by_addr(peer.ip[0]) 805 except: 806 pass 807 795 808 # Make country a proper string 796 country = str()797 for char in peer.country:809 country_tmp = str() 810 for char in country: 798 811 if not char.isalpha(): 799 country += " "812 country_tmp += " " 800 813 else: 801 country += char 814 country_tmp += char 815 country = country_tmp 802 816 803 817 ret.append({ 804 818 "client": client, -
deluge/ui/gtkui/peers_tab.py
a b class PeersTab(Tab): 214 214 component.get("SessionProxy").get_torrent_status(torrent_id, ["peers"]).addCallback(self._on_get_torrent_status) 215 215 216 216 def get_flag_pixbuf(self, country): 217 if country == " ":217 if not country.strip(): 218 218 return None 219 219 220 220 if country not in self.cached_flag_pixbufs: