Code

Merge branch 'fix-stringio-python2.7' of git://github.com/aelse/collectd
authorFlorian Forster <octo@collectd.org>
Wed, 3 Jul 2013 16:21:08 +0000 (18:21 +0200)
committerFlorian Forster <octo@collectd.org>
Wed, 3 Jul 2013 16:21:08 +0000 (18:21 +0200)
1  2 
contrib/collectd_network.py

index dc6cdac4f997fecbaf2d68d5548195aa302dcfed,9c1e9fb1ba7aad1877ba90bb3cb5bf86315d1d06..809f19dee65d2ec89a030a762bacb5e98041d8aa
@@@ -17,10 -17,15 +17,15 @@@ Collectd network protocol implementatio
  """
  
  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
@@@ -76,7 -81,7 +81,7 @@@ def decode_network_values(ptype, plen, 
      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