diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2009-10-15 11:01:00 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2009-10-15 11:01:00 +0300 |
commit | aa2ae3803cc38db786a662d70826a0131293b674 (patch) | |
tree | 052837808964f40501332d46f1f378ce0d88fb65 /python/rpm/__init__.py | |
parent | 410bf68fd41a6b8c98e48ca77e093f2f6c6bda75 (diff) | |
download | librpm-tizen-aa2ae3803cc38db786a662d70826a0131293b674.tar.gz librpm-tizen-aa2ae3803cc38db786a662d70826a0131293b674.tar.bz2 librpm-tizen-aa2ae3803cc38db786a662d70826a0131293b674.zip |
Avoid unnecessary dup'ing of file descriptors on header list operations
- convert to rpm.fd on python side already add use internal helper
which only accepts rpm.fd type to avoid having to dup around on
every item
Diffstat (limited to 'python/rpm/__init__.py')
-rw-r--r-- | python/rpm/__init__.py | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/python/rpm/__init__.py b/python/rpm/__init__.py index 49a4c774a..82e5f4667 100644 --- a/python/rpm/__init__.py +++ b/python/rpm/__init__.py @@ -28,18 +28,11 @@ def headerLoad(*args, **kwds): warnings.warn("Use rpm.hdr() instead.", DeprecationWarning, stacklevel=2) return hdr(*args, **kwds) -def _fdno(fd): - if hasattr(fd, "fileno"): - return fd.fileno() - else: - return fd - -def readHeaderListFromFD(fd, retrofit = True): - fdno = _fdno(fd) +def _doHeaderListFromFD(rpm_fd, retrofit): hlist = [] while 1: try: - h = hdr(fdno) + h = hdr(rpm_fd) if retrofit: h.convert(HEADERCONV_RETROFIT_V3) hlist.append(h) @@ -47,18 +40,24 @@ def readHeaderListFromFD(fd, retrofit = True): break return hlist + +def readHeaderListFromFD(file_desc, retrofit = True): + if not isinstance(file_desc, fd): + file_desc = fd(file_desc) + return _doHeaderListFromFD(file_desc, retrofit) -def readHeaderListFromFile(path): - f = open(path) - hlist = readHeaderListFromFD(f) +def readHeaderListFromFile(path, retrofit = True): + f = fd(path) + hlist = _doHeaderListFromFD(f, retrofit) f.close() return hlist -def readHeaderFromFD(fd): - fdno = _fdno(fd) - offset = os.lseek(fdno, 0, os.SEEK_CUR) +def readHeaderFromFD(file_desc): + if not isinstance(file_desc, fd): + file_desc = fd(file_desc) + offset = os.lseek(file_desc.fileno(), 0, os.SEEK_CUR) try: - h = hdr(fdno) + h = hdr(file_desc) except _rpm.error: h = None offset = None |