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>
This commit is contained in:
parent
f65ecadfaa
commit
267bcda006
@ -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"' %
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 = ''
|
||||
|
@ -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
|
||||
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user