1# Copyright 2022 The Chromium Authors 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4"""Calculates the checksum for pervasive.js. 5 6Usage: 7 python3 checksum_pervasive_js.py pervasive.js 8 9""" 10 11import re 12import sys 13import pervasive_checksum 14 15 16def main(argv): 17 if len(argv) != 2: 18 print('Supply the path to pervasive.js as the sole command-line argument') 19 sys.exit(1) 20 21 filename = argv[1] 22 with open(filename, mode='rb') as f: 23 raw_body = f.read() 24 25 headers = [] 26 with open(f'{filename}.mock-http-headers', mode='r') as lines: 27 for line in lines: 28 if line.startswith('HTTP/'): 29 continue 30 match = re.match(r'^([A-Za-z0-9-]+): *(.*)$', line) 31 if not match: 32 print(f'Failed to parse header line: {line}') 33 continue 34 headers.append((match.group(1), match.group(2))) 35 36 print(pervasive_checksum.calculate_checksum(headers, raw_body)) 37 38 39if __name__ == '__main__': 40 main(sys.argv) 41