def new_download(self, infohash, torrent_data, permid):
     basename = binascii.hexlify(infohash) + '.torrent'
     torrentfilename = os.path.join(self.helpdir, basename)
     tfile = open(torrentfilename, 'wb')
     tfile.write(torrent_data)
     tfile.close()
     if DEBUG:
         print >> sys.stderr, 'helper: new_download: Got metadata required for helping', show_permid_short(
             permid)
         print >> sys.stderr, 'helper: new_download: torrent: ', torrentfilename
     tdef = TorrentDef.load(torrentfilename)
     if self.dlconfig is None:
         dscfg = DownloadStartupConfig()
     else:
         dscfg = DownloadStartupConfig(self.dlconfig)
     dscfg.set_coopdl_coordinator_permid(permid)
     dscfg.set_dest_dir(self.helpdir)
     dscfg.set_proxy_mode(PROXY_MODE_OFF)
     if DEBUG:
         print >> sys.stderr, 'helper: new_download: Starting a new download'
     d = self.session.start_download(tdef, dscfg)
     d.set_state_callback(self.state_callback, getpeerlist=False)
     network_got_ask_for_help_lambda = lambda: self.network_got_ask_for_help(
         permid, infohash)
     self.session.lm.rawserver.add_task(network_got_ask_for_help_lambda, 0)
 def new_download(self, infohash, torrent_data, permid):
     basename = binascii.hexlify(infohash) + ".torrent"
     torrentfilename = os.path.join(self.helpdir, basename)
     tfile = open(torrentfilename, "wb")
     tfile.write(torrent_data)
     tfile.close()
     if DEBUG:
         print >>sys.stderr, "helper: new_download: Got metadata required for helping", show_permid_short(permid)
         print >>sys.stderr, "helper: new_download: torrent: ", torrentfilename
     tdef = TorrentDef.load(torrentfilename)
     if self.dlconfig is None:
         dscfg = DownloadStartupConfig()
     else:
         dscfg = DownloadStartupConfig(self.dlconfig)
     dscfg.set_coopdl_coordinator_permid(permid)
     dscfg.set_dest_dir(self.helpdir)
     dscfg.set_proxy_mode(PROXY_MODE_OFF)
     if DEBUG:
         print >>sys.stderr, "helper: new_download: Starting a new download"
     d = self.session.start_download(tdef, dscfg)
     d.set_state_callback(self.state_callback, getpeerlist=False)
     network_got_ask_for_help_lambda = lambda: self.network_got_ask_for_help(permid, infohash)
     self.session.lm.rawserver.add_task(network_got_ask_for_help_lambda, 0)