From 8f250c00c8b028a614815f63b2713748504d7ef9 Mon Sep 17 00:00:00 2001 From: Nir Soffer Date: Tue, 28 Aug 2018 23:50:56 +0300 Subject: [PATCH] v2v: rhv-upload-plugin: Use BrokenPipeError With python 3, we have a nicer way to handle socket.error with errno set to EPIPE (or ESHUTDOWN). This is also more correct since in some cases (that I could not reproduce yet with v2v), using e[0] with BrokenPipeError will fail with: >>> OSError(errno.EPIPE, "Broken pipe")[0] Traceback (most recent call last): File "", line 1, in TypeError: 'BrokenPipeError' object is not subscriptable For python 2 e[0] seems to work, but is leftover from historic python version that used to raise a tuple instead of socket.error instance. In python 2.7 library code e.args[0] is used. If we ever port this to python 2 this is the best form. --- v2v/rhv-upload-plugin.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/v2v/rhv-upload-plugin.py b/v2v/rhv-upload-plugin.py index b5dd5521d..5cd6d5cab 100644 --- a/v2v/rhv-upload-plugin.py +++ b/v2v/rhv-upload-plugin.py @@ -17,7 +17,6 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import builtins -import errno import json import logging import socket @@ -361,9 +360,8 @@ def pwrite(h, buf, offset): try: http.send(buf) - except socket.error as e: - if e[0] != errno.EPIPE: - raise + except BrokenPipeError: + pass r = http.getresponse() if r.status != 200: @@ -425,9 +423,8 @@ def emulate_zero(h, count, offset): http.send(buf) count -= len(buf) http.send(buffer(buf, 0, count)) - except socket.error as e: - if e[0] != errno.EPIPE: - raise + except BrokenPipeError: + pass r = http.getresponse() if r.status != 200: