]> Cypherpunks.ru repositories - pyderasn.git/commitdiff
CLI --evgen
authorSergey Matveev <stargrave@stargrave.org>
Fri, 14 Feb 2020 14:34:18 +0000 (17:34 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 16 Feb 2020 18:25:49 +0000 (21:25 +0300)
doc/news.rst
pyderasn.py

index 7e110786a3ff064d001a0a00c2e920f34558c833..5665a42c59cf635cde0734a843aec173ba53eae8 100644 (file)
@@ -15,7 +15,8 @@ News
   encoded representation storage
 * Initial support for so called ``evgen_mode``: event generation mode,
   where no in-memory objects storing happens, giving ability to process
-  ASN.1 data without fully parsing it first
+  ASN.1 data without fully parsing it first. ``python -m pyderasn`` has
+  ``--evgen`` mode switcher
 * Initial experimental CER encoding mode, allowing streaming encoding of
   the data directly to some writeable object
 * Ability to use mmap-ed memoryviews to skip files loading to memory
index 002f0605c42e65b804ffc1d4907142a7000cd521..fe1d4ab800624dfcb03307fe06b649f9ae259b3b 100755 (executable)
@@ -1943,6 +1943,7 @@ def pprint(
         with_colours=False,
         with_decode_path=False,
         decode_path_only=(),
+        decode_path=(),
 ):
     """Pretty print object
 
@@ -1995,7 +1996,7 @@ def pprint(
             else:
                 for row in _pprint_pps(pp):
                     yield row
-    return "\n".join(_pprint_pps(obj.pps()))
+    return "\n".join(_pprint_pps(obj.pps(decode_path)))
 
 
 ########################################################################
@@ -6706,6 +6707,11 @@ def main():  # pragma: no cover
         action="store_true",
         help="Allow explicit tag out-of-bound",
     )
+    parser.add_argument(
+        "--evgen",
+        action="store_true",
+        help="Turn on event generation mode",
+    )
     parser.add_argument(
         "RAWFile",
         type=argparse.FileType("rb"),
@@ -6734,10 +6740,9 @@ def main():  # pragma: no cover
     }
     if args.defines_by_path is not None:
         ctx["defines_by_path"] = obj_by_path(args.defines_by_path)
-    obj, tail = schema().decode(raw, ctx=ctx)
     from os import environ
-    print(pprinter(
-        obj,
+    pprinter = partial(
+        pprinter,
         oid_maps=oid_maps,
         with_colours=environ.get("NO_COLOR") is None,
         with_decode_path=args.print_decode_path,
@@ -6745,7 +6750,13 @@ def main():  # pragma: no cover
             () if args.decode_path_only is None else
             tuple(args.decode_path_only.split(":"))
         ),
-    ))
+    )
+    if args.evgen:
+        for decode_path, obj, tail in schema().decode_evgen(raw, ctx=ctx):
+            print(pprinter(obj, decode_path=decode_path))
+    else:
+        obj, tail = schema().decode(raw, ctx=ctx)
+        print(pprinter(obj))
     if tail != b"":
         print("\nTrailing data: %s" % hexenc(tail))