From 4a80530e2a589c8e29ee93fe26b819aa00d16935 Mon Sep 17 00:00:00 2001 From: Rajul Kumar Date: Tue, 9 Jan 2024 22:36:51 -0500 Subject: [PATCH] Accept buffered IO stream objects as fd in hdrFromFdno fd arg to hdrFromFdno might be a buffered IO stream object like the one returned by open(). As rpm.transaction.hdrFromFdno accepts the buffered IO object as fd, the method here should accept the object as well. --- src/rpmdyn/_transaction.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/rpmdyn/_transaction.py b/src/rpmdyn/_transaction.py index 56e8bc7..ef31752 100644 --- a/src/rpmdyn/_transaction.py +++ b/src/rpmdyn/_transaction.py @@ -1,3 +1,5 @@ +from io import IOBase + from ._ffi import gc, cstr from . import _ffi, _const @@ -111,6 +113,11 @@ def getVSFlags(self): return _ffi.rpmtsVSFlags(self.__ts) def hdrFromFdno(self, fd): + # Accept the Buffered I/O stream object as fd. It inherits IOBase + # the proides the underlying FD number where available. + if isinstance(fd, IOBase): + fd = fd.fileno() + assert isinstance(fd, int) rpmfd = _ffi.fdDup(fd)