changeset 390:af49ea848756 plus

sic
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Mon, 22 Jun 2026 12:33:52 +0100
parents 2c04af3ca99a
children b9b301fd064d
files lib/python/cc/test_iwarc.py
diffstat 1 files changed, 70 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/python/cc/test_iwarc.py	Mon Jun 22 12:33:52 2026 +0100
@@ -0,0 +1,70 @@
+#!/usr/bin/env python3
+# cython: profile=False, language_level=3str
+'''Test various parameter settings for complete warc file streaming callback.
+   
+
+Usage: test_iwarc.py [-d] test-number filename warc-types part-mask 
+ -d turns on debugging output
+ filename gives a path to a .warc or .warc.gz WARC file
+ warc-types is list of integers corresponding to WARC record types
+    to be extracted and printed to stdout:
+        warcinfo: 0
+        response: 1 
+        request:  2
+        metadata: 3
+        [revisit: 4 only appears in .../crawldiagnostics/... files]
+      
+ part-mask is a bit-mask controling what part of each record is printed:
+   1: WARC headers
+   2: req/resp HTTP header, warcinfo/metadata features
+   3: resp body'''
+
+import iwarc,sys
+
+OUT=open(sys.stdout.fileno(),'wb')
+
+if (debug:=(sys.argv[1]=='-d')):
+  sys.argv.pop(1)
+
+tt=int(sys.argv.pop(1))
+
+def showme(wtype,buf,part):
+  # This should exactly reproduce a complete warc file if called
+  #  as per test no. 4 below, sub-parts one at a time if no. 1.
+  #  See comments
+  if debug:
+    OUT.write(b"----start %d-----\n"%part)
+  OUT.write(buf)
+  if buf and buf[-1]!=10:
+    OUT.write(b'\r\n')
+  if part==7:
+    OUT.write(b'\r\n') # to match complete file formatting
+  if debug:
+    OUT.write(b"----end %d-----\n"%part)
+  return OUT
+
+if tt==1:
+  # all parts
+  iwarc.warc(sys.argv[1],showme,[1,2,3,0],debug=debug)
+elif tt==2:
+  # just the initial warcinfo record, WARC (1), CC (2), both (3)
+  iwarc.warc(sys.argv[1],showme,[0],parts=int(sys.argv[2]),debug=debug)
+elif tt==3:
+  # just the initial warcinfo record
+  iwarc.warc(sys.argv[1],showme,[0],whole=True,debug=debug)
+elif tt==4:
+  # the whole thing
+  iwarc.warc(sys.argv[1],showme,[1,2,3,0,4],whole=True,debug=debug)
+elif tt==5:
+  # response records
+  iwarc.warc(sys.argv[1],showme,[1],parts=int(sys.argv[2]),debug=debug)
+elif tt==6:
+  # revisit records
+  iwarc.warc(sys.argv[1],showme,[4],parts=int(sys.argv[2]),debug=debug)
+elif tt==7:
+  # metadata records
+  iwarc.warc(sys.argv[1],showme,[3],parts=int(sys.argv[2]),debug=debug)
+elif tt==8:
+  # request records
+  iwarc.warc(sys.argv[1],showme,[2],parts=int(sys.argv[2]),debug=debug)
+