Skip to content

Commit

Permalink
Merge pull request #2796 from lunkwill42/upgrade/twisted
Browse files Browse the repository at this point in the history
Upgrade Twisted to a version compatible with both Python 3.7 and 3.11
  • Loading branch information
lunkwill42 authored Feb 29, 2024
2 parents 106ef20 + 68e0641 commit cdac0a5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
20 changes: 17 additions & 3 deletions python/nav/ipdevpoll/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,25 @@ def __init__(self, is_worker, **kwargs):
self.lost_handler = None

def makeConnection(self, transport):
"""Called when a connection has been made to the AMP endpoint"""
if not hasattr(transport, 'getPeer'):
"""Overrides the base implementation to fake the required getPeer() and
getHost() methods on the incoming process transport object, if needed ( the
base AMP class was not really designed with process pipe transports in mind,
but with IP transports).
Process transports in Twisted<21 did not implement these methods at all,
while in Twisted>=21 they resolve to base methods that raise
`NotImplementError`.
"""
try:
transport.getPeer()
except (AttributeError, NotImplementedError):
setattr(transport, 'getPeer', lambda: "peer")
if not hasattr(transport, 'getHost'):

try:
transport.getHost()
except (AttributeError, NotImplementedError):
setattr(transport, 'getHost', lambda: "host")

super(ProcessAMP, self).makeConnection(transport)

def connectionLost(self, reason):
Expand Down
3 changes: 2 additions & 1 deletion python/nav/mibs/mibretriever.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from twisted.internet import defer, reactor
from twisted.internet.defer import returnValue
from twisted.internet.error import TimeoutError
from twisted.python.failure import Failure

from nav.Snmp import safestring
from nav.ipdevpoll import ContextLogger
Expand Down Expand Up @@ -428,7 +429,7 @@ def _result_formatter(result):

return formatted_result

def _snmp_timeout_handler(failure: defer.failure.Failure):
def _snmp_timeout_handler(failure: Failure):
"""Transforms SnmpTimeoutErrors into "regular" TimeoutErrors"""
failure.trap(SnmpTimeoutError)
raise TimeoutError(failure.value)
Expand Down
3 changes: 1 addition & 2 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ psycopg2==2.9.9 # requires libpq to build
IPy==1.01
pyaml

twisted>=20.0.0,<21

twisted~=23.8.0 # last version that still supports Python 3.7

networkx==2.6.3
Pillow>3.3.2
Expand Down
2 changes: 1 addition & 1 deletion tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pytest-metadata<2.0.0
pytest-cov==2.7.1
pytest-selenium==2.0.1
pytest-timeout
pytest-twisted==1.12
pytest-twisted~=1.13.0
pytidylib==0.3.2
selenium==3.141.0
whisper>=0.9.9
Expand Down

0 comments on commit cdac0a5

Please sign in to comment.