@cryptotaxi247 / netdata-1 / commits / 37babce63

Fix buffer handling to accomodate python 2 and 3.

Austin S. Hemmelgarn committed Jun 5, 2018 at 15:01 UTC 37babce6355b303d813a9a4cd6eadbddfdcea873
1 file changed +7 -1
python.d/python_modules/third_party/boinc_client.py
+7 -1
@@ -12,6 +12,7 @@
12
13 import hashlib
14 import socket
15 +import sys
16 import time
17 from functools import total_ordering
18 from xml.etree import ElementTree
@@ -82,7 +83,10 @@ class Rpc(object):
83
84 # pack request
85 end = '\003'
85 - req = "<boinc_gui_rpc_request>\n{0}\n</boinc_gui_rpc_request>\n{1}".format(ElementTree.tostring(request).replace(' />', '/>'), end)
86 + if sys.version_info[0] < 3:
87 + req = "<boinc_gui_rpc_request>\n{0}\n</boinc_gui_rpc_request>\n{1}".format(ElementTree.tostring(request).replace(' />', '/>'), end)
88 + else:
89 + req = "<boinc_gui_rpc_request>\n{0}\n</boinc_gui_rpc_request>\n{1}".format(ElementTree.tostring(request, encoding='unicode').replace(' />', '/>'), end).encode()
90
91 try:
92 self.sock.sendall(req)
@@ -95,6 +99,8 @@ class Rpc(object):
99 buf = self.sock.recv(8192)
100 if not buf:
101 raise socket.error("No data from socket")
102 + if sys.version_info[0] >= 3:
103 + buf = buf.decode()
104 except socket.error:
105 raise
106 n = buf.find(end)