Skip to content

Commit

Permalink
Merge branch 'lextudio:main' into fixed_cache_leak
Browse files Browse the repository at this point in the history
  • Loading branch information
y-iwata-bl authored Nov 11, 2024
2 parents b58bc4d + ab131be commit fa36bd0
Show file tree
Hide file tree
Showing 18 changed files with 564 additions and 214 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ jobs:
poetry build
- name: Test
run: |
poetry run mibdump NET-SNMP-EXAMPLES-MIB
poetry run mibdump IF-MIB
poetry run mibdump --generate-mib-texts NET-SNMP-EXAMPLES-MIB
poetry run mibdump --generate-mib-texts IF-MIB
poetry run mibdump --generate-mib-texts LEXTUDIO-TEST-MIB
poetry run mibdump --generate-mib-texts CISCO-ENHANCED-IPSEC-FLOW-MIB
poetry run pytest --junitxml=junit/test-results-${{ matrix.python-version }}.xml --cov=com --cov-report=xml --cov-report=html
- name: Test summary
uses: test-summary/action@v2
Expand Down
20 changes: 20 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
Revision 7.1.13, released on Nov 07, 2024
-----------------------------------------

- Fixed a resource leak issue.

Revision 7.1.12, released on Nov 06, 2024
-----------------------------------------

- Reverted some changes in named values support.

Revision 7.1.11, released on Nov 04, 2024
-----------------------------------------

- Reverted some changes in fixed length support.

Revision 7.1.10, released on Nov 04, 2024
-----------------------------------------

- Reimplemented getReference in a few MIB objects.

Revision 7.1.9, released on Nov 02, 2024
----------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ We provide security updates for each version until its End-of-Life (EOL) date. B

| Version | Latest Release | End of Life | Notes |
| ------- | -------------- | ----------- | ---------------------------------- |
| 7.1 | 7.1.9 | TBD | EOL to be determined |
| 7.1 | 7.1.13 | TBD | EOL to be determined |
| 7.0 | 7.0.4 | 2025-03-11 | Supported for 6 months after 7.1.0 |
| 6.2 | 6.2.6 | 2025-08-22 | Supported for 1 year after 7.0.0 |
| 6.1 | 6.1.4 | 2025-01-12 | Supported for 6 months after 6.2.0 |
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
# built documents.
#
# The full version, including alpha/beta/rc tags.
release = "7.1.9"
release = "7.1.13"
# The short X.Y version.
version = ".".join(release.split(".")[:2])

Expand Down
334 changes: 167 additions & 167 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pysnmp"
version = "7.1.9"
version = "7.1.13"
description = "A Python library for SNMP"
authors = ["Ilya Etingof <[email protected]>", "LeXtudio Inc. <[email protected]>"]
license = "BSD-2-Clause"
Expand Down
2 changes: 1 addition & 1 deletion pysnmp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
- For backward compatibility, if the version string contains "beta", the string part is removed before converting to a tuple.
"""
# http://www.python.org/dev/peps/pep-0396/
__version__ = "7.1.9"
__version__ = "7.1.13"
# another variable is required to prevent semantic release from updating version in more than one place
main_version = __version__
# backward compatibility
Expand Down
2 changes: 2 additions & 0 deletions pysnmp/hlapi/v1arch/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#
import warnings
from time import time
from typing import Any

from pyasn1.codec.ber import decoder, encoder
from pysnmp import debug
Expand Down Expand Up @@ -38,6 +39,7 @@ class AbstractSnmpDispatcher:

PROTO_DISPATCHER = None
transport_dispatcher: AbstractTransportDispatcher
cache: dict[str, Any]

def __init__(self, transportDispatcher: AbstractTransportDispatcher = None): # type: ignore
if transportDispatcher:
Expand Down
22 changes: 11 additions & 11 deletions pysnmp/proto/rfc1902.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def with_named_values(cls, **values):
enums.update(values.items())

class X(cls):
named_values = namedval.NamedValues(*enums)
namedValues = namedval.NamedValues(*enums)
subtypeSpec = cls.subtypeSpec + constraint.SingleValueConstraint(
*values.values()
) # noqa: N815
Expand Down Expand Up @@ -234,20 +234,20 @@ class instance.
# having zero-range size constraint applied. The following is
# supposed to be used for setting and querying this property.

fixed_length = None
fixedLength = None

def set_fixed_length(self, value):
"""Set fixed length."""
self.fixed_length = value
self.fixedLength = value
return self

def is_fixed_length(self):
"""Return if fixed length."""
return self.fixed_length is not None
return self.fixedLength is not None

def get_fixed_length(self):
"""Return fixed length."""
return self.fixed_length
return self.fixedLength

def clone(self, *args, **kwargs):
"""Clone the data."""
Expand Down Expand Up @@ -367,7 +367,7 @@ class IpAddress(OctetString):
subtypeSpec = OctetString.subtypeSpec + constraint.ValueSizeConstraint(
4, 4
) # noqa: N815
fixed_length = 4
fixedLength = 4

def prettyIn(self, value): # noqa: N802
"""Convert string to IP address."""
Expand Down Expand Up @@ -683,7 +683,7 @@ class Bits(OctetString):
"""

named_values = namedval.NamedValues()
namedValues: namedval.NamedValues = namedval.NamedValues()

def __new__(cls, *args, **kwargs):
"""Create a new instance of the class."""
Expand All @@ -699,7 +699,7 @@ def prettyIn(self, bits): # noqa: N802
return OctetString.prettyIn(self, bits) # raw bitstring
octets = []
for bit in bits: # tuple of named bits
v = self.named_values.getValue(bit)
v = self.namedValues.getValue(bit)
if v is None:
raise error.ProtocolError("Unknown named bit %s" % bit)
d, m = divmod(v, 8)
Expand All @@ -717,7 +717,7 @@ def prettyOut(self, value): # noqa: N802
j = 7
while j >= 0:
if v & (0x01 << j):
name = self.named_values.getName(i * 8 + 7 - j)
name = self.namedValues.getName(i * 8 + 7 - j)
if name is None:
name = f"UnknownBit-{i * 8 + 7 - j}"
names.append(name)
Expand All @@ -730,11 +730,11 @@ def with_named_bits(cls, **values):
Reduce fully duplicate enumerations along the way.
"""
enums = set(cls.named_values.items())
enums = set(cls.namedValues.items())
enums.update(values.items())

class X(cls):
named_values = namedval.NamedValues(*enums)
namedValues = namedval.NamedValues(*enums)

X.__name__ = cls.__name__
return X
Expand Down
18 changes: 11 additions & 7 deletions pysnmp/smi/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import sys
import time
import traceback
from typing import Any
import warnings
from errno import ENOENT
from importlib.machinery import BYTECODE_SUFFIXES, SOURCE_SUFFIXES
Expand All @@ -18,6 +19,9 @@
from pysnmp import debug, version as pysnmp_version
from pysnmp.smi import error

if __debug__:
import runpy


PY_SUFFIXES = SOURCE_SUFFIXES + BYTECODE_SUFFIXES

Expand Down Expand Up @@ -354,7 +358,12 @@ def load_module(self, modName, **userCtx):
g = {"mibBuilder": self, "userCtx": userCtx}

try:
exec(codeObj, g)
if __debug__:
runpy.run_path(
modPath, g
) # IMPORTANT: enable break points in loaded MIBs
else:
exec(codeObj, g)

except Exception:
self.__modPathsSeen.remove(modPath)
Expand Down Expand Up @@ -417,11 +426,6 @@ def load_modules(self, *modNames, **userCtx):
f"{modName} compilation error(s): {errs}"
)

if errs:
raise error.MibNotFoundError(
f"{modName} compilation error(s): {errs}"
)

# compilation succeeded, MIB might load now
self.load_module(modName, **userCtx)

Expand All @@ -444,7 +448,7 @@ def unload_modules(self, *modNames):

return self

def import_symbols(self, modName, *symNames, **userCtx):
def import_symbols(self, modName, *symNames, **userCtx) -> "tuple[Any, ...]":
"""Import MIB symbols."""
if not modName:
raise error.SmiError("importSymbols: empty MIB module name")
Expand Down
44 changes: 38 additions & 6 deletions pysnmp/smi/mibs/SNMPv2-CONF.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class ObjectGroup(MibNode):
status = "current"
objects = ()
description = ""
reference = ""

def getStatus(self):
return self.status
Expand All @@ -39,20 +40,31 @@ def setDescription(self, v):
self.description = v
return self

def getReference(self):
return self.reference

def setReference(self, v):
self.reference = v
return self

def asn1Print(self):
return """\
OBJECT-GROUP
OBJECTS {{ {} }}
STATUS "{}"
DESCRIPTION "{}"
""".format(
", ".join([x for x in self.getObjects()]), self.getDescription()
", ".join([x for x in self.getObjects()]),
self.status,
self.getDescription(),
)


class NotificationGroup(MibNode):
status = "current"
objects = ()
description = ""
reference = ""

def getStatus(self):
return self.status
Expand All @@ -78,13 +90,23 @@ def setDescription(self, v):
self.description = v
return self

def getReference(self):
return self.reference

def setReference(self, v):
self.reference = v
return self

def asn1Print(self):
return """\
NOTIFICATION-GROUP
NOTIFICATIONS {{ {} }}
STATUS "{}"
DESCRIPTION "{}"
""".format(
", ".join([x for x in self.getObjects()]), self.getDescription()
", ".join([x for x in self.getObjects()]),
self.getStatus(),
self.getDescription(),
)


Expand Down Expand Up @@ -117,13 +139,23 @@ def setDescription(self, v):
self.description = v
return self

def getReference(self):
return self.reference

def setReference(self, v):
self.reference = v
return self

def asn1Print(self):
return """\
MODULE-COMPLIANCE
OBJECT {{ {} }}
STATUS "{}"
DESCRIPTION "{}"
OBJECT {{ {} }}
""".format(
", ".join([x for x in self.getObjects()]), self.getDescription()
self.getStatus(),
self.getDescription(),
", ".join([x for x in self.getObjects()]),
)


Expand Down Expand Up @@ -166,11 +198,11 @@ def setProductRelease(self, v):
def asn1Print(self):
return """\
AGENT-CAPABILITIES
STATUS "{}"
PRODUCT-RELEASE "{}"
STATUS "{}"
DESCRIPTION "{}"
""".format(
self.getStatus(), self.getProductRelease(), self.getDescription()
self.getProductRelease(), self.getStatus(), self.getDescription()
)


Expand Down
2 changes: 1 addition & 1 deletion pysnmp/smi/mibs/SNMPv2-TC.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def prettyIn(self, value): # override asn1 type method

if self.displayHint and (
self.__integer.isSuperTypeOf(self, matchConstraints=False)
and self.getNamedValues()
and not self.getNamedValues()
or self.__unsigned32.isSuperTypeOf(self, matchConstraints=False)
or self.__timeticks.isSuperTypeOf(self, matchConstraints=False)
):
Expand Down
Loading

0 comments on commit fa36bd0

Please sign in to comment.