From b5dbe188b005c8f1100ba9c6cb286612e01ee2cb Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 25 Apr 2011 00:37:52 +0100 Subject: Use try/except rather than getattr to test for fileno _make_stream_binary --- python/subunit/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'python') diff --git a/python/subunit/__init__.py b/python/subunit/__init__.py index 5387cae..146d2c1 100644 --- a/python/subunit/__init__.py +++ b/python/subunit/__init__.py @@ -1139,9 +1139,11 @@ def get_default_formatter(): def _make_stream_binary(stream): """Ensure that a stream will be binary safe. See _make_binary_on_windows.""" - if getattr(stream, 'fileno', None) is not None: - print (stream, type(stream)) - _make_binary_on_windows(stream.fileno()) + try: + fileno = stream.fileno() + except AttributeError: + return + _make_binary_on_windows(fileno) def _make_binary_on_windows(fileno): """Win32 mangles \r\n to \n and that breaks streams. See bug lp:505078.""" -- cgit v1.2.1 From 3b8a7992f73fce05f7cdfe0ecfbf57561eb91d54 Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 25 Apr 2011 00:38:27 +0100 Subject: Vary fileno attempt exception type to support Python 3 --- python/subunit/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'python') diff --git a/python/subunit/__init__.py b/python/subunit/__init__.py index 146d2c1..7e2f141 100644 --- a/python/subunit/__init__.py +++ b/python/subunit/__init__.py @@ -1137,11 +1137,16 @@ def get_default_formatter(): return sys.stdout +if sys.version_info > (3, 0): + from io import UnsupportedOperation as _NoFilenoError +else: + _NoFilenoError = AttributeError + def _make_stream_binary(stream): """Ensure that a stream will be binary safe. See _make_binary_on_windows.""" try: fileno = stream.fileno() - except AttributeError: + except _NoFilenoError: return _make_binary_on_windows(fileno) -- cgit v1.2.1 From fa32c611795141f3a01d5b993d7cd38ac3ecb9a5 Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 25 Apr 2011 00:39:31 +0100 Subject: Remove presumably erroneous _make_stream_binary call --- python/subunit/__init__.py | 1 - 1 file changed, 1 deletion(-) (limited to 'python') diff --git a/python/subunit/__init__.py b/python/subunit/__init__.py index 7e2f141..a49641c 100644 --- a/python/subunit/__init__.py +++ b/python/subunit/__init__.py @@ -1058,7 +1058,6 @@ class ProtocolTestCase(object): _make_stream_binary(stream) self._passthrough = passthrough self._forward = forward - _make_stream_binary(forward) def __call__(self, result=None): return self.run(result) -- cgit v1.2.1