From d917b94f24e274ad2af0caccb1eaeb27bd90af60 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Fri, 29 Jun 2018 23:24:28 +0300 Subject: [PATCH] Field names in SEQUENCE's repr --- VERSION | 2 +- doc/examples.rst | 7 ++++--- doc/features.rst | 2 +- doc/news.rst | 13 +++++++++++++ pyderasn.py | 6 +++--- 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/VERSION b/VERSION index cc1923a..bd28b9c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.8 +3.9 diff --git a/doc/examples.rst b/doc/examples.rst index f780360..f5b58d9 100644 --- a/doc/examples.rst +++ b/doc/examples.rst @@ -179,9 +179,10 @@ it's DER encoded representation is already in ``raw`` variable):: >>> crt, tail = Certificate().decode(raw) >>> crt - Certificate SEQUENCE[TBSCertificate SEQUENCE[[0] EXPLICIT Version - INTEGER v3 OPTIONAL, CertificateSerialNumber INTEGER 61595, - AlgorithmIdentifier SEQUENCE[OBJECT IDENTIFIER 1.2.840.113549.1.1.5... + Certificate SEQUENCE[tbsCertificate: TBSCertificate SEQUENCE[ + version: [0] EXPLICIT Version INTEGER v3 OPTIONAL; + serialNumber: CertificateSerialNumber INTEGER 61595; + signature: AlgorithmIdentifier SEQUENCE[OBJECT IDENTIFIER 1.2.840.113549.1.1.5... Pretty printing --------------- diff --git a/doc/features.rst b/doc/features.rst index a0a75fa..463586e 100644 --- a/doc/features.rst +++ b/doc/features.rst @@ -45,7 +45,7 @@ There are drawbacks: * PyDERASN does **not** have object recreation capable ``repr``-s:: pyderasn>>> repr(algo_id) - AlgorithmIdentifier SEQUENCE[OBJECT IDENTIFIER 1.3.14.3.2.26, [UNIV 5] ANY 0500 OPTIONAL] + AlgorithmIdentifier SEQUENCE[algorithm: OBJECT IDENTIFIER 1.3.14.3.2.26; parameters: [UNIV 5] ANY 0500 OPTIONAL] pyasn1>>> repr(algo_id) AlgorithmIdentifier().setComponents(ObjectIdentifier('1.3.14.3.2.26'), Any(hexValue='0500')) diff --git a/doc/news.rst b/doc/news.rst index 971011e..7c067ed 100644 --- a/doc/news.rst +++ b/doc/news.rst @@ -1,6 +1,19 @@ News ==== +.. _release3.9: + +3.9 +--- +SEQUENCE's values are printed with field's name. Previously there was +the following output:: + + AlgorithmIdentifier SEQUENCE[OBJECT IDENTIFIER 1.3.14.3.2.26, [UNIV 5] ANY 0500 OPTIONAL] + +now it is:: + + AlgorithmIdentifier SEQUENCE[algorithm: OBJECT IDENTIFIER 1.3.14.3.2.26; parameters: [UNIV 5] ANY 0500 OPTIONAL] + .. _release3.8: 3.8 diff --git a/pyderasn.py b/pyderasn.py index 5c40361..6f30f58 100755 --- a/pyderasn.py +++ b/pyderasn.py @@ -4240,7 +4240,7 @@ class Sequence(Obj): ("algorithm", ObjectIdentifier("1.2.3")), ("parameters", Any(Null())) )) - AlgorithmIdentifier SEQUENCE[OBJECT IDENTIFIER 1.2.3, ANY 0500 OPTIONAL] + AlgorithmIdentifier SEQUENCE[algorithm: OBJECT IDENTIFIER 1.2.3; parameters: ANY 0500 OPTIONAL] You can determine if value exists/set in the sequence and take its value: @@ -4595,8 +4595,8 @@ class Sequence(Obj): _value = self._value.get(name) if _value is None: continue - cols.append(repr(_value)) - return "%s[%s]" % (value, ", ".join(cols)) + cols.append("%s: %s" % (name, repr(_value))) + return "%s[%s]" % (value, "; ".join(cols)) def pps(self, decode_path=()): yield _pp( -- 2.44.0