Skip to content

Commit

Permalink
Make ProcessAMP.makeConnection work on Twisted>=21
Browse files Browse the repository at this point in the history
  • Loading branch information
lunkwill42 committed Feb 28, 2024
1 parent c8cd760 commit 5695742
Showing 1 changed file with 17 additions and 3 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

0 comments on commit 5695742

Please sign in to comment.