From: Alexander Else Date: Mon, 1 Jul 2013 07:02:19 +0000 (+1000) Subject: fixes StringIO unicode handling in python 2.7 X-Git-Tag: collectd-5.4.0~24^2 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=0bdc3011ce40cbbd23dd62aff56a150d5b921fb9;p=collectd.git fixes StringIO unicode handling in python 2.7 --- diff --git a/contrib/collectd_network.py b/contrib/collectd_network.py index 9af0fb00..9c1e9fb1 100644 --- a/contrib/collectd_network.py +++ b/contrib/collectd_network.py @@ -17,10 +17,15 @@ Collectd network protocol implementation. """ import socket,struct,sys -try: - from io import StringIO -except ImportError: - from cStringIO import StringIO +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