diff --git a/mb_netmgmt/snmp.py b/mb_netmgmt/snmp.py index bc99b25..57f1d48 100644 --- a/mb_netmgmt/snmp.py +++ b/mb_netmgmt/snmp.py @@ -111,8 +111,7 @@ def translate_json_to_network_response(self, json): value = b64decode(value, validate=True) except (binascii.Error, TypeError): pass - asn1_class = ASN1_Class_UNIVERSAL.__dict__[response["tag"]] - result += SNMPvarbind(oid=oid, value=asn1_class.asn1_object(value)) + result += to_varbind(oid, value, response["tag"]) return result @@ -142,3 +141,8 @@ def to_dict(varbind): if varbind.endOfMibView: result["endOfMibView"] = 0 return result + + +def to_varbind(oid, value, tag): + asn1_class = ASN1_Class_UNIVERSAL.__dict__[tag] + return SNMPvarbind(oid=oid, value=asn1_class.asn1_object(value)) diff --git a/test/test_mb_netmgmt.py b/test/test_mb_netmgmt.py index 7a1f44e..b898f9d 100644 --- a/test/test_mb_netmgmt.py +++ b/test/test_mb_netmgmt.py @@ -259,3 +259,8 @@ def test_no_such_instance_to_dict(): varbind = SNMPvarbind(value=None, noSuchInstance=ASN1_NULL(0)) result = snmp.to_dict(varbind) assert result == {"tag": None, "val": None, "noSuchInstance": 0} + + +def test_to_varbind(): + result = snmp.to_varbind("1.3", 0, "NULL") + assert result == SNMPvarbind(oid="1.3", value=0)