Skip to content

Commit

Permalink
extract to_varbind
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-sahlmann committed Jul 27, 2023
1 parent 4cee78a commit e0c0e59
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 6 additions & 2 deletions mb_netmgmt/snmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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))
5 changes: 5 additions & 0 deletions test/test_mb_netmgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit e0c0e59

Please sign in to comment.