def read_torrent_file(self, filename): '''Attempt to read a torrent file and return its content. Returns a dictionary''' try: with open(filename, mode='rb') as localized_file: return bdecoder.decode(localized_file.read().decode("latin1")) except IOError as e: print("File ",filename," could not be found") self.good_status = False
def read_torrent_file(self, filename): '''Attempt to read a torrent file and return its content. Returns a dictionary''' try: with open(filename, mode='rb') as localized_file: return bdecoder.decode(localized_file.read().decode("latin1")) except IOError as e: print("File ", filename, " could not be found") self.good_status = False
def get_peer_list(self,raw_reply): '''Returns dictionary of peers with ip,port keys''' response = bdecoder.decode(raw_reply) # decode if not self.refresh: self.refresh = response['interval'] if 'peers' not in response: print("Peer list from tracker is empty. ",end="") if 'failure reason' in response: print(response['failure reason']) return unparsed_peers = response['peers'].encode("latin1") # get the right encoding peers_list = [] if type(unparsed_peers)==dict: print("Unsupported peers model: dictionary") sys.exit(1) else: # binary model peers = self._parse_binary_peers(unparsed_peers) for p in peers: peers_list.append(self.get_peer_info(p)) return [{"ip":k[0],"port":k[1]} for k in peers_list]