odp-util: Format and scan multiple MPLS labels.
[cascardo/ovs.git] / python / ovs / socket_util.py
index 586c23a..9f46a55 100644 (file)
@@ -19,6 +19,9 @@ import random
 import socket
 import sys
 
+import six
+from six.moves import range
+
 import ovs.fatal_signal
 import ovs.poller
 import ovs.vlog
@@ -32,7 +35,7 @@ def make_short_name(long_name):
     long_name = os.path.abspath(long_name)
     long_dirname = os.path.dirname(long_name)
     tmpdir = os.getenv('TMPDIR', '/tmp')
-    for x in xrange(0, 1000):
+    for x in range(0, 1000):
         link_name = \
             '%s/ovs-un-py-%d-%d' % (tmpdir, random.randint(0, 10000), x)
         try:
@@ -242,7 +245,7 @@ def get_exception_errno(e):
     exception is documented as having two completely different forms of
     arguments: either a string or a (errno, string) tuple.  We only want the
     errno."""
-    if type(e.args) == tuple:
+    if isinstance(e.args, tuple):
         return e.args[0]
     else:
         return errno.EPROTO
@@ -273,6 +276,8 @@ def write_fully(fd, buf):
     bytes_written = 0
     if len(buf) == 0:
         return 0, 0
+    if sys.version_info[0] >= 3 and not isinstance(buf, six.binary_type):
+        buf = six.binary_type(buf, 'utf-8')
     while True:
         try:
             retval = os.write(fd, buf)