Skip to content

Commit

Permalink
extract to_dict function
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-sahlmann committed Jul 27, 2023
1 parent ce34c49 commit f1a05f7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
repos:
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
- repo: https://github.com/google/yamlfmt
rev: v0.8.0
hooks:
- id: yamlfmt
12 changes: 8 additions & 4 deletions mb_netmgmt/snmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ def read_proxy_response(self):
raise
result = dict()
for varbind in snmp_response.PDU.varbindlist:
result[varbind.oid.val] = {
"val": decode(varbind.value.val),
"tag": str(varbind.value.tag),
}
result[varbind.oid.val] = to_dict(varbind)

return result

Expand Down Expand Up @@ -126,3 +123,10 @@ def decode(value):
return value
except UnicodeDecodeError:
return b64encode(value).decode()


def to_dict(varbind):
return {
"val": decode(varbind.value.val),
"tag": str(varbind.value.tag),
}

0 comments on commit f1a05f7

Please sign in to comment.