summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelie <elie>2011-10-12 20:04:32 +0000
committerelie <elie>2011-10-12 20:04:32 +0000
commita09405074ad5707c593909e0f011346687b7dfb9 (patch)
treefa74b5da4078d95dd79528271dfc841e9ea37b3e
parent93eabdf4d96e13dcddbf692a41a4ea53e5c87014 (diff)
downloadpysnmp-a09405074ad5707c593909e0f011346687b7dfb9.tar.gz
keep a Null object instance around to save on frequent instantiations
-rw-r--r--pysnmp/proto/api/v1.py7
-rw-r--r--pysnmp/proto/api/v2c.py1
2 files changed, 4 insertions, 4 deletions
diff --git a/pysnmp/proto/api/v1.py b/pysnmp/proto/api/v1.py
index 7766bef..da96a2a 100644
--- a/pysnmp/proto/api/v1.py
+++ b/pysnmp/proto/api/v1.py
@@ -7,6 +7,7 @@ from pysnmp import nextid
Integer = univ.Integer
OctetString = univ.OctetString
Null = univ.Null
+null = Null('')
ObjectIdentifier = univ.ObjectIdentifier
IpAddress = rfc1155.IpAddress
@@ -26,10 +27,9 @@ TrapPDU = rfc1157.TrapPDU
Message = rfc1157.Message
class VarBindAPI:
- _null = Null('')
def setOIDVal(self, varBind, (oid, val)):
varBind.setComponentByPosition(0, oid)
- if val is None: val = self._null
+ if val is None: val = null
varBind.setComponentByPosition(1).getComponentByPosition(1).setComponentByType(val.getTagSet(), val, 1, verifyConstraints=False)
return varBind
@@ -41,7 +41,6 @@ apiVarBind = VarBindAPI()
getNextRequestID = nextid.Integer(0xffffff)
class PDUAPI:
- _null = Null('')
_errorStatus = _errorIndex = Integer(0)
def setDefaults(self, pdu):
pdu.setComponentByPosition(
@@ -111,7 +110,7 @@ class PDUAPI:
if apiPDU.getErrorStatus(rspPDU) == 2:
varBindRow = []
for varBind in apiPDU.getVarBinds(reqPDU):
- varBindRow.append((varBind[0], self._null))
+ varBindRow.append((varBind[0], null))
return [ varBindRow ]
else:
return [ apiPDU.getVarBinds(rspPDU) ]
diff --git a/pysnmp/proto/api/v2c.py b/pysnmp/proto/api/v2c.py
index 235b5bc..cfaa125 100644
--- a/pysnmp/proto/api/v2c.py
+++ b/pysnmp/proto/api/v2c.py
@@ -4,6 +4,7 @@ from pyasn1.type import univ, namedtype, namedval, constraint
# Shortcuts to SNMP types
Null = univ.Null
+null = Null('')
ObjectIdentifier = univ.ObjectIdentifier
Integer = rfc1902.Integer