def get_url(url): """Downloads the .torrent metainfo file specified by the passed URL and returns data, the raw contents of the metainfo file. Any exception raised while trying to obtain the metainfo file is caught and GetTorrent.URLException is raised instead. """ data = None err_str = ( (_('Could not download or open "%s"') % url) + "\n" + _("Try using a web browser to download the torrent file.") ) u = None # pending protocol changes, convert: # torrent://http://path.to/file # and: # bittorrent://http://path.to/file # to: # http://path.to/file url = urlpat_torrent.sub("", url) url = urlpat_bittorrent.sub("", url) try: u = zurllib.urlopen(url) data = u.read() u.close() except Exception, e: if u is not None: u.close() raise URLException(err_str + "\n(%s)" % e)
def get_language(name): from BTL import LOCALE_URL url = LOCALE_URL + name + ".tar.gz" socket.setdefaulttimeout(5) r = urllib.urlopen(url) # urllib seems to ungzip for us tarname = os.path.join(locale_root, name + ".tar") f = file(tarname, 'wb') f.write(r.read()) f.close() tar = tarfile.open(tarname, "r") for tarinfo in tar: tar.extract(tarinfo, path=locale_root) tar.close()