From ccac817f2beaabf252e762238eb86f9b3e034df5 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson <jbjohnso@us.ibm.com> Date: Sat, 14 Sep 2013 21:36:44 -0400 Subject: [PATCH] Enhance filehandle registration Previously, pyghmi only could have file objects registered. Accept and adjust as appropriate to accomodate plain int filedescriptors. This allows, for example, os.pipe() construct to be hooked. Change-Id: Ie5e81a2276c68e9235d373d4a662f7b1aef153f5 --- pyghmi/ipmi/private/session.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pyghmi/ipmi/private/session.py b/pyghmi/ipmi/private/session.py index 124308a8..049fa24b 100644 --- a/pyghmi/ipmi/private/session.py +++ b/pyghmi/ipmi/private/session.py @@ -660,7 +660,10 @@ class Session: rdata = cls.socket.recvfrom(3000) pktqueue.append(rdata) for handlepair in _poller(cls.readersockets): - myhandle = handlepair.fileno() + if isinstance(handlepair, int): + myhandle = handlepair + else: + myhandle = handlepair.fileno() if myhandle != cls.socket.fileno(): myfile = cls._external_handlers[myhandle][1] cls._external_handlers[myhandle][0](myfile) @@ -701,7 +704,10 @@ class Session: :param callback: function to call when input detected on the handle. will receive the handle as an argument """ - cls._external_handlers[handle.fileno()] = (callback, handle) + if isinstance(handle, int): + cls._external_handlers[handle] = (callback, handle) + else: + cls._external_handlers[handle.fileno()] = (callback, handle) cls.readersockets += [handle] @classmethod