# HG changeset patch # User Henry S. Thompson # Date 1773667131 0 # Node ID 2874da240b734033ad8ef6de90a39c297f3cf0fc # Parent 0367405a02fcc1c567fc4af3fa2f5362bc88daef simple test of block ranges appears to work diff -r 0367405a02fc -r 2874da240b73 lib/python/cc/test_warc.py --- a/lib/python/cc/test_warc.py Mon Mar 16 12:25:29 2026 +0000 +++ b/lib/python/cc/test_warc.py Mon Mar 16 13:18:51 2026 +0000 @@ -11,11 +11,15 @@ tt=int(sys.argv.pop(1)) -def showme(wtype,buf,part): +def showme(wtype,buf,part,brange = None): # This should exactly reproduce a complete warc file if called # as per version 1 below if debug: OUT.write(b"----start %d-----\n"%part) + if brange: + OUT.write(buf[0:10]) # print the WARC1.0 line + OUT.write(b"WARC-Range: %d %d\n"%brange) + buf = buf[10:] OUT.write(buf) if buf[-1]!=10: OUT.write(b'\r\n') diff -r 0367405a02fc -r 2874da240b73 lib/python/cc/warc.py --- a/lib/python/cc/warc.py Mon Mar 16 12:25:29 2026 +0000 +++ b/lib/python/cc/warc.py Mon Mar 16 13:18:51 2026 +0000 @@ -112,14 +112,19 @@ # if (bp+length)>bl: # raise ValueError("Done but need more! %s + %s > %s in %s"%(bp, # length,bl,filename)) + brange = Q.popleft() if (wtype in types): # Output whole or part 1 as required if whole: - _out = callback(wtype,bufView[start_1:bp+length], 7) + args = (wtype,bufView[start_1:bp+length], 7, brange) if block \ + else (wtype,bufView[start_1:bp+length], 7) + _out = callback(*args) else: if (parts & 1): bp = eol + 2 - _out = callback(wtype, bufView[start_1:bp], 1) + args = (wtype, bufView[start_1:bp], 1, brange) if block \ + else (wtype, bufView[start_1:bp], 1) + _out = callback(*args) if parts != 1: while buf.startswith(b'\r\n', bp): bp += 2 @@ -132,10 +137,14 @@ if wtype == RESP or wtype == REQ : # request and response have http headers eo2 = buf.index(b'\r\n\r\n', start_2) - _out = callback(wtype, bufView[start_2:eo2 + 2], 2) + args = (wtype, bufView[start_2:eo2 + 2], 2, brange) if block \ + else (wtype, bufView[start_2:eo2 + 2], 2) + _out = callback(*args) else: # rest of the part - _out = callback(wtype, bufView[start_2:eob], 2) + args = (wtype, bufView[start_2:eob], 2, brange) if block \ + else (wtype, bufView[start_2:eob], 2) + _out = callback(*args) if parts & 4: raise ValueError("Not implemented: body part (4): %s"%parts) #bp += length