summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorfumihiko kakuma <kakuma@valinux.co.jp>2015-06-24 14:05:18 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-06-25 12:23:31 +0900
commit267bcda006d753f7a55ae2dc7eed58d65c280be0 (patch)
tree1c419448ecc9aae73e113b090f7efbcf05ee5e7f
parentf65ecadfaaba12d494610c33c0408fd64ed0f737 (diff)
python3: Use six.text_type instead of unicode
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 <kakuma@valinux.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/lib/ovs/vsctl.py3
-rw-r--r--ryu/lib/stringify.py11
-rw-r--r--ryu/ofproto/ofproto_v1_2_parser.py3
-rw-r--r--ryu/ofproto/ofproto_v1_3_parser.py3
-rw-r--r--ryu/ofproto/ofproto_v1_4_parser.py3
-rw-r--r--ryu/ofproto/ofproto_v1_5_parser.py3
-rw-r--r--ryu/services/protocols/bgp/operator/command.py3
-rw-r--r--ryu/services/protocols/bgp/utils/logs.py3
-rw-r--r--ryu/tests/switch/tester.py3
9 files changed, 22 insertions, 13 deletions
diff --git a/ryu/lib/ovs/vsctl.py b/ryu/lib/ovs/vsctl.py
index 2714f64e..8670eb35 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 816c7a00..3c5bf5ee 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 9c1041d1..fc14662c 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 52cad96d..52eb2f8b 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 21f80bb9..0417b2bb 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 b8aaa2a6..b5a28f4e 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 6d271d3e..fbcb720b 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 6d94ce19..aa07d5c1 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 885f29f4..815ea279 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)