changeset 386:69264e6389e2 plus

tweak some arg doc strings, give NotImpl warning for -m
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Sat, 20 Jun 2026 14:58:59 +0100
parents 615efac7fc09
children 4eda36618ca2
files lib/python/cc/ix.py
diffstat 1 files changed, 21 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/lib/python/cc/ix.py	Mon Jun 15 23:31:47 2026 +0100
+++ b/lib/python/cc/ix.py	Sat Jun 20 14:58:59 2026 +0100
@@ -181,7 +181,14 @@
             bl=int(v)
           if options.headers:
             if isinstance(options.headers,dict):
-              if h in options.headers:
+              if (h:=h.lower()) in options.headers:
+                # note
+                #  a) that this is seriously inefficient as it involves a string
+                #     copy for every header line;
+                #  b) it will probably confuse users as they will always see
+                #     lower-case, which is almost never in files, but at lease
+                #     they will not have to do another lower() in order to look
+                #     things up in the result
                 options.headers[h]=v
             else:
               _output(L)
@@ -227,18 +234,18 @@
   fphelp=('format string for turning 4 filename components into a path, must contain %%s exactly 4 times,\ndefault is "%s"'%FPAT).replace('%s','%%s')
   parser.add_argument('--help',help='Show help',action='help')
   parser.add_argument('-d','--debug',help='Debug output',action='store_true')
-  parser.add_argument('-w','--warc',help='output WARC headers',
+  parser.add_argument('-w','--warc',help='Output Warc headers',
                       action='store_true')
-  parser.add_argument('-h','--headers',help='process HTTP headers: collect into dict with named values (,-separated) if arg present, else output',
+  parser.add_argument('-h','--headers',help='Process HTTP headers: if no  (,-separated) args, output as read. With args, collect into dict with named values.  Keys in dict are lower-cased, per HTTP case-insensitivity.',
                       nargs='?',default=None,const=True)
-  parser.add_argument('-b','--body',help='output HTTP body',
+  parser.add_argument('-b','--body',help='Output HTTP body',
                       action='store_true')
-  parser.add_argument('-c','--cmd',help='pipes each result thru CMD')
+  parser.add_argument('-c','--cmd',help='Pipe each result thru CMD')
   parser.add_argument('-p','--process',help='with -c, launches CMD only once',
                       action='store_true')
-  parser.add_argument('-m','--module.function',help='module.function to call with a stream'),
+  parser.add_argument('-m','--module.function',help='Call module.function with a stream'),
   parser.add_argument('-s','--save',action='store_true',
-                      help="write to a temporary file and output the name")
+                      help="Write to a temporary file and output the name")
   parser.add_argument('-f','--fpath',
                       help=fphelp,
                       default=FPAT)
@@ -246,11 +253,11 @@
                   help='File path root, create a copy there if necessary',
                   default=ROOT),
   parser.add_argument('-z','--zipped',
-                      help="output raw gzipped record, ignored if any of -bhw supplied",
+                      help="Output raw gzipped record, ignored if any of -bhw supplied",
                       action='store_true')
   sg=parser.add_mutually_exclusive_group()
   sg.add_argument('-x','--index',
-                      help='take lines of triples from a cdx index file as input',
+                      help='Take lines of triples from a cdx index file as input',
                       action='store_true')
   sg.add_argument('length',type=int,
                   help='length in bytes of gzipped record',
@@ -265,14 +272,16 @@
   parser._action_groups.sort(key=lambda g:g.title)
   #parser.print_help()
   pa=parser.parse_args(sys.argv[1:])
-  #print(pa,file=sys.stderr)
+  print(pa,file=sys.stderr)
   if pa.length is not None:
     # We have to enforce our own check..
     if pa.offset is None or pa.filename is None:
       parser.error("length, offset and filename must all be supplied together")
   if isinstance(pa.headers,str):
-    pa.headers=dict((bytes(k,'utf-8'),None) for k in pa.headers.split(','))
- 
+    pa.headers=dict((bytes(k.lower(),'utf-8'),None) for k in pa.headers.split(','))
+    #   N.B.                 ^^^^^
+  if pa.__getattribute__("module.function") is not None:
+    parser.error("-m,--module.function not supported yet")
   buf=bytearray(128*1024*1024)
 
   whole=not (pa.warc or pa.headers or pa.body)