X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=contrib%2Fcollectd_network.py;h=cb328f2b23a69166036793a6e40a12b96ac74e2e;hp=0a5d57e6cfe6030eec55df16fecb28b45a828c66;hb=de407dd4e036f73e9bd4658af9d71f504fc11109;hpb=b4c8f3f762d666742c774ab3b45815e5a416e5da diff --git a/contrib/collectd_network.py b/contrib/collectd_network.py index 0a5d57e6..cb328f2b 100644 --- a/contrib/collectd_network.py +++ b/contrib/collectd_network.py @@ -4,7 +4,7 @@ # # Copyright © 2009 Adrian Perez # -# Distributed under terms of the GPLv2 license. +# Distributed under terms of the GPLv2 license or newer. # # Frank Marien (frank@apsu.be) 6 Sep 2012 # - quick fixes for 5.1 binary protocol @@ -16,11 +16,16 @@ Collectd network protocol implementation. """ -import socket,struct,sys -try: - from io import StringIO -except ImportError: - from cStringIO import StringIO +import socket,struct +import platform +if platform.python_version() < '2.8.0': + # Python 2.7 and below io.StringIO does not like unicode + from StringIO import StringIO +else: + try: + from io import StringIO + except ImportError: + from cStringIO import StringIO from datetime import datetime from copy import deepcopy @@ -76,7 +81,7 @@ def decode_network_values(ptype, plen, buf): assert double.size == number.size result = [] - for dstype in buf[header.size+short.size:off]: + for dstype in [ord(x) for x in buf[header.size+short.size:off]]: if dstype == DS_TYPE_COUNTER: result.append((dstype, number.unpack_from(buf, off)[0])) off += valskip