def _get_to_local_file(self, url, md5sum):
        try:
            filename = url[url.rindex('/') + 1:]
            ext_pos = filename.index('.')
            local_filename = "%s/%s-%d%s" % (
                    self.tmp_path,
                    filename[:ext_pos],
                    os.getpid(),
                    filename[ext_pos:])
        except __HOLE__:
            raise AgentUpdateError("Invalid URL")

        try:
            urllib.urlretrieve(url, local_filename)
        except Exception, e:
            raise AgentUpdateError(str(e))

        try:
            f = file(local_filename, 'rb')
        except:
            os.unlink(local_filename)
            raise AgentUpdateError("Couldn't open local file")

        m = hashlib.md5()
        while True:
            file_data = f.read(8096)
            if not file_data:
                break
            m.update(file_data)

        f.close()

        digest = m.hexdigest()
        if digest != md5sum:
            os.unlink(local_filename)
            raise AgentUpdateError("MD5 sums do not match (%s != %s)" % (
                    md5sum, digest))

        return local_filename
dataset/ETHPy150Open rackerlabs/openstack-guest-agents-unix/commands/update.py/UpdateCommand._get_to_local_file