Пример #1
0
        def retrieve():
            # retrieve from remote server
            logger.info(f'retrieving port: {name} from {url}')
            try:
                import requests
                response = requests.get(url)
                data = response.content
            except ImportError:
                from urllib.request import urlopen
                f = urlopen(url)
                data = f.read()

            if sha512hash:
                actual_hash = hashlib.sha512(data).hexdigest()
                if actual_hash != sha512hash:
                    utils.exit_with_error(
                        f'Unexpected hash: {actual_hash}\n'
                        'If you are updating the port, please update the hash.'
                    )
            utils.write_binary(fullpath, data)
Пример #2
0
def remove_trailing_zeros(memfile):
    mem_data = utils.read_binary(memfile)
    end = len(mem_data)
    while end > 0 and (mem_data[end - 1] == b'\0' or mem_data[end - 1] == 0):
        end -= 1
    utils.write_binary(memfile, mem_data[:end])