From 9ebd0c0fab207c02f2046a1d221f147aa69c6c26 Mon Sep 17 00:00:00 2001 From: Ilya Etingof Date: Fri, 26 Oct 2018 08:44:06 +0200 Subject: [PATCH] Expose ASN.1 `Null` type through `rfc1902` module --- CHANGES.txt | 1 + docs/source/docs/api-reference.rst | 14 ++++++++++++++ pysnmp/proto/rfc1902.py | 27 ++++++++++++++++++++++++++- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index c1fc9058..4944bad9 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -61,6 +61,7 @@ Revision 5.0.0, released 2018-10-?? Revision 4.4.7, released 2018-11-XX ----------------------------------- +- Exposed ASN.1 `Null` type through `rfc1902` module for convenience. - Use `compile()` before `exec`'ing MIB modules to attach filename to the stack frames (ultimately shown in traceback/debugger) - Fixed hlapi/v3arch transport target caching to ensure transport targets diff --git a/docs/source/docs/api-reference.rst b/docs/source/docs/api-reference.rst index 2d0d9d42..1ede28ce 100644 --- a/docs/source/docs/api-reference.rst +++ b/docs/source/docs/api-reference.rst @@ -441,6 +441,20 @@ data description language. PySNMP types are derived from .. toctree:: :maxdepth: 2 +.. _null: + +Null type ++++++++++ + +.. autoclass:: pysnmp.proto.rfc1902.Null(initializer) + :members: + +.. note:: + + The `NULL` type actually belongs to the base ASN.1 types. It is not defined + in :RFC:`1902#section-2` as an SNMP type. The `Null` type is exposed through + `rfc1902` module just for convenience. + .. _integer32: Integer32 type diff --git a/pysnmp/proto/rfc1902.py b/pysnmp/proto/rfc1902.py index 3caa81d7..4bd82669 100644 --- a/pysnmp/proto/rfc1902.py +++ b/pysnmp/proto/rfc1902.py @@ -10,7 +10,32 @@ from pysnmp.proto import rfc1155, error __all__ = ['Opaque', 'TimeTicks', 'Bits', 'Integer', 'OctetString', 'IpAddress', 'Counter64', 'Unsigned32', 'Gauge32', 'Integer32', - 'ObjectIdentifier', 'Counter32'] + 'ObjectIdentifier', 'Counter32', 'Null'] + + +class Null(univ.Null): + """Creates an instance of SNMP Null class. + + :py:class:`~pysnmp.proto.rfc1902.Null` type represents the absence + of value. + + Parameters + ---------- + initializer: str + Python string object. Must be an empty string. + + Raises + ------ + PyAsn1Error : + On constraint violation or bad initializer. + + Examples + -------- + >>> from pysnmp.proto.rfc1902 import * + >>> Null('') + Null('') + >>> + """ class Integer32(univ.Integer):