This is the partial patch to supporting python 3.
unicode was removed in python 3. So we use six.text_type instead of unicode.

Signed-off-by: Fumihiko Kakuma <[email protected]>
---
 ryu/lib/ovs/vsctl.py                           |  3 ++-
 ryu/lib/stringify.py                           | 11 ++++++-----
 ryu/ofproto/ofproto_v1_2_parser.py             |  3 ++-
 ryu/ofproto/ofproto_v1_3_parser.py             |  3 ++-
 ryu/ofproto/ofproto_v1_4_parser.py             |  3 ++-
 ryu/ofproto/ofproto_v1_5_parser.py             |  3 ++-
 ryu/services/protocols/bgp/operator/command.py |  3 ++-
 ryu/services/protocols/bgp/utils/logs.py       |  3 ++-
 ryu/tests/switch/tester.py                     |  3 ++-
 9 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/ryu/lib/ovs/vsctl.py b/ryu/lib/ovs/vsctl.py
index 2714f64..8670eb3 100644
--- a/ryu/lib/ovs/vsctl.py
+++ b/ryu/lib/ovs/vsctl.py
@@ -19,6 +19,7 @@ import itertools
 import logging
 import operator
 import os
+import six
 import sys
 import weakref
 
@@ -761,7 +762,7 @@ class VSCtlContext(object):
             for ovsrec_row in self.idl.tables[
                     vsctl_row_id.table].rows.values():
                 name = getattr(ovsrec_row, vsctl_row_id.name_column)
-                assert type(name) in (list, str, unicode)
+                assert type(name) in (list, str, six.text_type)
                 if type(name) != list and name == record_id:
                     if (referrer):
                         vsctl_fatal('multiple rows in %s match "%s"' %
diff --git a/ryu/lib/stringify.py b/ryu/lib/stringify.py
index 816c7a0..3c5bf5e 100644
--- a/ryu/lib/stringify.py
+++ b/ryu/lib/stringify.py
@@ -19,6 +19,7 @@
 import base64
 import collections
 import inspect
+import six
 
 
 # Some arguments to __init__ is mungled in order to avoid name conflicts
@@ -59,7 +60,7 @@ class TypeDescr(object):
 class AsciiStringType(TypeDescr):
     @staticmethod
     def encode(v):
-        return unicode(v, 'ascii')
+        return six.text_type(v, 'ascii')
 
     @staticmethod
     def decode(v):
@@ -69,7 +70,7 @@ class AsciiStringType(TypeDescr):
 class Utf8StringType(TypeDescr):
     @staticmethod
     def encode(v):
-        return unicode(v, 'utf-8')
+        return six.text_type(v, 'utf-8')
 
     @staticmethod
     def decode(v):
@@ -154,7 +155,7 @@ class StringifyMixin(object):
         if len(dict_) != 1:
             return False
         k = list(dict_.keys())[0]
-        if not isinstance(k, (bytes, unicode)):
+        if not isinstance(k, (bytes, six.text_type)):
             return False
         for p in cls._class_prefixes:
             if k.startswith(p):
@@ -186,7 +187,7 @@ class StringifyMixin(object):
     @classmethod
     def _get_default_encoder(cls, encode_string):
         def _encode(v):
-            if isinstance(v, (bytes, unicode)):
+            if isinstance(v, (bytes, six.text_type)):
                 json_value = encode_string(v)
             elif isinstance(v, list):
                 json_value = map(_encode, v)
@@ -268,7 +269,7 @@ class StringifyMixin(object):
     @classmethod
     def _get_default_decoder(cls, decode_string):
         def _decode(json_value, **additional_args):
-            if isinstance(json_value, (bytes, unicode)):
+            if isinstance(json_value, (bytes, six.text_type)):
                 v = decode_string(json_value)
             elif isinstance(json_value, list):
                 v = map(_decode, json_value)
diff --git a/ryu/ofproto/ofproto_v1_2_parser.py 
b/ryu/ofproto/ofproto_v1_2_parser.py
index 9c1041d..fc14662 100644
--- a/ryu/ofproto/ofproto_v1_2_parser.py
+++ b/ryu/ofproto/ofproto_v1_2_parser.py
@@ -18,6 +18,7 @@
 Decoder/Encoder implementations of OpenFlow 1.2.
 """
 
+import six
 import struct
 import itertools
 
@@ -1481,7 +1482,7 @@ class OFPActionSetField(OFPAction):
             assert len(kwargs) == 1
             key = list(kwargs.keys())[0]
             value = kwargs[key]
-            assert isinstance(key, (str, unicode))
+            assert isinstance(key, (str, six.text_type))
             assert not isinstance(value, tuple)  # no mask
             self.key = key
             self.value = value
diff --git a/ryu/ofproto/ofproto_v1_3_parser.py 
b/ryu/ofproto/ofproto_v1_3_parser.py
index 52cad96..52eb2f8 100644
--- a/ryu/ofproto/ofproto_v1_3_parser.py
+++ b/ryu/ofproto/ofproto_v1_3_parser.py
@@ -40,6 +40,7 @@ The following extensions are not implemented yet.
     - EXT-192-v Vacancy events Extension
 """
 
+import six
 import struct
 import itertools
 
@@ -3063,7 +3064,7 @@ class OFPActionSetField(OFPAction):
             assert len(kwargs) == 1
             key = list(kwargs.keys())[0]
             value = kwargs[key]
-            assert isinstance(key, (str, unicode))
+            assert isinstance(key, (str, six.text_type))
             assert not isinstance(value, tuple)  # no mask
             self.key = key
             self.value = value
diff --git a/ryu/ofproto/ofproto_v1_4_parser.py 
b/ryu/ofproto/ofproto_v1_4_parser.py
index 21f80bb..0417b2b 100644
--- a/ryu/ofproto/ofproto_v1_4_parser.py
+++ b/ryu/ofproto/ofproto_v1_4_parser.py
@@ -18,6 +18,7 @@
 Decoder/Encoder implementations of OpenFlow 1.4.
 """
 
+import six
 import struct
 import itertools
 
@@ -5357,7 +5358,7 @@ class OFPActionSetField(OFPAction):
         assert len(kwargs) == 1
         key = list(kwargs.keys())[0]
         value = kwargs[key]
-        assert isinstance(key, (str, unicode))
+        assert isinstance(key, (str, six.text_type))
         assert not isinstance(value, tuple)  # no mask
         self.key = key
         self.value = value
diff --git a/ryu/ofproto/ofproto_v1_5_parser.py 
b/ryu/ofproto/ofproto_v1_5_parser.py
index b8aaa2a..b5a28f4 100644
--- a/ryu/ofproto/ofproto_v1_5_parser.py
+++ b/ryu/ofproto/ofproto_v1_5_parser.py
@@ -18,6 +18,7 @@
 Decoder/Encoder implementations of OpenFlow 1.5.
 """
 
+import six
 import struct
 import itertools
 
@@ -5467,7 +5468,7 @@ class OFPActionSetField(OFPAction):
         assert len(kwargs) == 1
         key = list(kwargs.keys())[0]
         value = kwargs[key]
-        assert isinstance(key, (str, unicode))
+        assert isinstance(key, (str, six.text_type))
         assert not isinstance(value, tuple)  # no mask
         self.key = key
         self.value = value
diff --git a/ryu/services/protocols/bgp/operator/command.py 
b/ryu/services/protocols/bgp/operator/command.py
index 6d271d3..fbcb720 100644
--- a/ryu/services/protocols/bgp/operator/command.py
+++ b/ryu/services/protocols/bgp/operator/command.py
@@ -3,6 +3,7 @@ import json
 import logging
 import pprint
 import re
+import six
 
 (STATUS_OK, STATUS_ERROR) = range(2)
 
@@ -109,7 +110,7 @@ class Command(object):
 
         if resp.status == STATUS_OK:
 
-            if type(resp.value) in (str, bool, int, float, unicode):
+            if type(resp.value) in (str, bool, int, float, six.text_type):
                 return str(resp.value)
 
             ret = ''
diff --git a/ryu/services/protocols/bgp/utils/logs.py 
b/ryu/services/protocols/bgp/utils/logs.py
index 6d94ce1..aa07d5c 100644
--- a/ryu/services/protocols/bgp/utils/logs.py
+++ b/ryu/services/protocols/bgp/utils/logs.py
@@ -1,5 +1,6 @@
 import json
 import logging
+import six
 import time
 
 from datetime import datetime
@@ -15,7 +16,7 @@ class ApgwFormatter(logging.Formatter):
             'timestamp': datetime.utcfromtimestamp(
                 time.time()
             ).strftime(self.LOG_TIME_FORMAT),
-            'msg': unicode(record.msg),
+            'msg': six.text_type(record.msg),
             'level': record.levelname
 
         }
diff --git a/ryu/tests/switch/tester.py b/ryu/tests/switch/tester.py
index 885f29f..815ea27 100644
--- a/ryu/tests/switch/tester.py
+++ b/ryu/tests/switch/tester.py
@@ -21,6 +21,7 @@ import math
 import netaddr
 import os
 import signal
+import six
 import sys
 import time
 import traceback
@@ -1326,7 +1327,7 @@ class TestFile(stringify.StringifyMixin):
             try:
                 json_list = json.loads(buf)
                 for test_json in json_list:
-                    if isinstance(test_json, unicode):
+                    if isinstance(test_json, six.text_type):
                         self.description = test_json
                     else:
                         self._normalize_test_json(test_json)
-- 
1.9.1


------------------------------------------------------------------------------
Monitor 25 network devices or servers for free with OpManager!
OpManager is web-based network management software that monitors 
network devices and physical & virtual servers, alerts via email & sms 
for fault. Monitor 25 devices for free with no restriction. Download now
http://ad.doubleclick.net/ddm/clk/292181274;119417398;o
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to