Mercurial > hg > cc > cirrus_work
view lib/python/cc/cdx_extras.py @ 301:4981c41628dd trim
works
| author | Henry S. Thompson <ht@inf.ed.ac.uk> |
|---|---|
| date | Tue, 13 May 2025 12:04:01 +0100 |
| parents | ce5b2c1da222 |
| children |
line wrap: on
line source
#!/usr/bin/python3 '''Output the necessary for updating a segment index file with lastmod''' import sys, re import unpackz PAT = re.compile(b'\r\nLast-Modified: ([^\r]*)',re.MULTILINE) def whereandwhat(count,offset,data,outfile): '''Callback from unpackz to extract what we need''' #if offset == 345053206: # breakpoint() if data.startswith(b'WARC/1.0\r\nWARC-Type: response\r\n') and \ b'Last-Modified: ' in data: # included for speed (worth factor of 3) if (http_start := data.find(b'\r\nHTTP/')) == -1: print("missing HTTP at %s %s"%(count,offset), file=sys.stderr) return if (http_end := data.find(b'\r\n\r\n',http_start)) == -1: print("missing end of HTTP at %s %s"%(count,offset), file=sys.stderr) return if (m:=PAT.search(data,http_start,http_end)): print(count,offset,m[1].decode('UTF-8'),sep='\t') unpackz.unpackz(sys.argv[1],whereandwhat)
