mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
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 "<stdin>", line 1, in <module> 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.
This commit is contained in:
committed by
Richard W.M. Jones
parent
0d0b551130
commit
8f250c00c8
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user