[python-debian/master 20/36] Cope with the absence of a file class in Python 3.
Colin Watson
cjwatson at canonical.com
Mon Oct 8 07:41:22 UTC 2012
---
lib/debian/deb822.py | 16 +++++++++++++++-
1 files changed, 15 insertions(+), 1 deletions(-)
diff --git a/lib/debian/deb822.py b/lib/debian/deb822.py
index 0761c6e..2efa56f 100644
--- a/lib/debian/deb822.py
+++ b/lib/debian/deb822.py
@@ -54,6 +54,20 @@ except ImportError:
_mapping_mixin = DictMixin
_mutable_mapping_mixin = DictMixin
+if sys.version >= '3':
+ import io
+ def _is_real_file(f):
+ if not isinstance(f, io.IOBase):
+ return False
+ try:
+ f.fileno()
+ return True
+ except (AttributeError, io.UnsupportedOperation):
+ return False
+else:
+ def _is_real_file(f):
+ return isinstance(f, file) and hasattr(f, 'fileno')
+
GPGV_DEFAULT_KEYRINGS = frozenset(['/usr/share/keyrings/debian-keyring.gpg'])
GPGV_EXECUTABLE = '/usr/bin/gpgv'
@@ -335,7 +349,7 @@ class Deb822(Deb822Dict):
necessary in order to properly interpret the strings.)
"""
- if _have_apt_pkg and use_apt_pkg and isinstance(sequence, file):
+ if _have_apt_pkg and use_apt_pkg and _is_real_file(sequence):
parser = apt_pkg.TagFile(sequence)
for section in parser:
paragraph = cls(fields=fields,
--
1.7.2.5
More information about the pkg-python-debian-commits
mailing list