pcs/fix-libcurl-issues-in-python3.patch
2017-02-22 13:25:59 +01:00

108 lines
4.0 KiB
Diff

From 44d20a50848a4a915f85087f8521413dad7df159 Mon Sep 17 00:00:00 2001
From: Tomas Jelinek <tojeline@redhat.com>
Date: Tue, 21 Feb 2017 16:37:57 +0100
Subject: [PATCH] fix libcurl issues in python3
---
pcs/lib/external.py | 21 ++++++++++-----------
pcs/test/test_lib_external.py | 5 ++---
pcs/utils.py | 19 +++++++++----------
3 files changed, 21 insertions(+), 24 deletions(-)
diff --git a/pcs/lib/external.py b/pcs/lib/external.py
index 0b2b5edc..5e3133dd 100644
--- a/pcs/lib/external.py
+++ b/pcs/lib/external.py
@@ -572,18 +572,17 @@ class NodeCommunicator(object):
"""
def __debug_callback(data_type, debug_data):
prefixes = {
- pycurl.DEBUG_TEXT: "* ",
- pycurl.DEBUG_HEADER_IN: "< ",
- pycurl.DEBUG_HEADER_OUT: "> ",
- pycurl.DEBUG_DATA_IN: "<< ",
- pycurl.DEBUG_DATA_OUT: ">> ",
+ pycurl.DEBUG_TEXT: b"* ",
+ pycurl.DEBUG_HEADER_IN: b"< ",
+ pycurl.DEBUG_HEADER_OUT: b"> ",
+ pycurl.DEBUG_DATA_IN: b"<< ",
+ pycurl.DEBUG_DATA_OUT: b">> ",
}
if data_type in prefixes:
- debug_output.write("{prefix}{data}{suffix}".format(
- prefix=prefixes[data_type],
- data=debug_data,
- suffix="" if debug_data.endswith("\n") else "\n"
- ).encode("utf-8"))
+ debug_output.write(prefixes[data_type])
+ debug_output.write(debug_data)
+ if not debug_data.endswith(b"\n"):
+ debug_output.write(b"\n")
output = io.BytesIO()
debug_output = io.BytesIO()
@@ -681,7 +680,7 @@ class NodeCommunicator(object):
else:
raise NodeConnectionException(host, request, reason)
finally:
- debug_data = debug_output.getvalue().decode("utf-8")
+ debug_data = debug_output.getvalue().decode("utf-8", "ignore")
self._logger.debug(
(
"Communication debug info for calling: {url}\n"
diff --git a/pcs/test/test_lib_external.py b/pcs/test/test_lib_external.py
index e8b0dc34..3868b0f2 100644
--- a/pcs/test/test_lib_external.py
+++ b/pcs/test/test_lib_external.py
@@ -506,8 +506,8 @@ class NodeCommunicatorTest(TestCase):
},
expected_response_data.encode("utf-8"),
[
- (pycurl.DEBUG_TEXT, "text"),
- (pycurl.DEBUG_DATA_OUT, "data out")
+ (pycurl.DEBUG_TEXT, b"text"),
+ (pycurl.DEBUG_DATA_OUT, b"data out")
]
)
mock_pycurl_init.return_value = mock_pycurl_obj
@@ -1952,4 +1952,3 @@ class IsProxySetTest(TestCase):
"no_proxy": "*",
"all_proxy": "test.proxy",
}))
-
diff --git a/pcs/utils.py b/pcs/utils.py
index 8190fa82..858cb3c1 100644
--- a/pcs/utils.py
+++ b/pcs/utils.py
@@ -346,18 +346,17 @@ def sendHTTPRequest(
def __debug_callback(data_type, debug_data):
prefixes = {
- pycurl.DEBUG_TEXT: "* ",
- pycurl.DEBUG_HEADER_IN: "< ",
- pycurl.DEBUG_HEADER_OUT: "> ",
- pycurl.DEBUG_DATA_IN: "<< ",
- pycurl.DEBUG_DATA_OUT: ">> ",
+ pycurl.DEBUG_TEXT: b"* ",
+ pycurl.DEBUG_HEADER_IN: b"< ",
+ pycurl.DEBUG_HEADER_OUT: b"> ",
+ pycurl.DEBUG_DATA_IN: b"<< ",
+ pycurl.DEBUG_DATA_OUT: b">> ",
}
if data_type in prefixes:
- debug_output.write("{prefix}{data}{suffix}".format(
- prefix=prefixes[data_type],
- data=debug_data,
- suffix="" if debug_data.endswith("\n") else "\n"
- ).encode("utf-8"))
+ debug_output.write(prefixes[data_type])
+ debug_output.write(debug_data)
+ if not debug_data.endswith(b"\n"):
+ debug_output.write(b"\n")
output = BytesIO()
debug_output = BytesIO()
--
2.11.0