summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorIWAMOTO Toshihiro <iwamoto@valinux.co.jp>2015-07-03 11:27:06 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-07-03 11:38:00 +0900
commit7da17ac94144dcdf264e63da54aa9c0142934e5d (patch)
treee4d567bdaf2af1d34c9f77c7ec3b489b52cd2e09
parent1bb849b3045e9d7adcf9e38a3b03a1e2972faf05 (diff)
python3: Store AsciiStringType class data as str
AsciiStringType data are mostly IP addresses and they must be text_type in python3 for text_to_bin to work. Also introduce AsciiStringListType, which is suitable for lists of IP addresses. Signed-off-by: IWAMOTO Toshihiro <iwamoto@valinux.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/lib/stringify.py31
1 files changed, 25 insertions, 6 deletions
diff --git a/ryu/lib/stringify.py b/ryu/lib/stringify.py
index 5d22979b..7d083900 100644
--- a/ryu/lib/stringify.py
+++ b/ryu/lib/stringify.py
@@ -60,10 +60,17 @@ class TypeDescr(object):
class AsciiStringType(TypeDescr):
@staticmethod
def encode(v):
+ # TODO: AsciiStringType data should probably be stored as
+ # text_type in class data. This isinstance() check exists
+ # because OFPDescStats violates this.
+ if six.PY3 and isinstance(v, six.text_type):
+ return v
return six.text_type(v, 'ascii')
@staticmethod
def decode(v):
+ if six.PY3:
+ return v
return v.encode('ascii')
@@ -77,6 +84,16 @@ class Utf8StringType(TypeDescr):
return v.encode('utf-8')
+class AsciiStringListType(TypeDescr):
+ @staticmethod
+ def encode(v):
+ return [AsciiStringType.encode(x) for x in v]
+
+ @staticmethod
+ def decode(v):
+ return [AsciiStringType.decode(x) for x in v]
+
+
class NXFlowSpecFieldType(TypeDescr):
# ("field_name", 0) <-> ["field_name", 0]
@@ -98,6 +115,7 @@ class NXFlowSpecFieldType(TypeDescr):
_types = {
'ascii': AsciiStringType,
'utf-8': Utf8StringType,
+ 'asciilist': AsciiStringListType,
'nx-flow-spec-field': NXFlowSpecFieldType, # XXX this should not be here
}
@@ -112,12 +130,13 @@ class StringifyMixin(object):
Currently the following types are implemented.
- ===== ==========
- Type Descrption
- ===== ==========
- ascii US-ASCII
- utf-8 UTF-8
- ===== ==========
+ ========= =============
+ Type Descrption
+ ========= =============
+ ascii US-ASCII
+ utf-8 UTF-8
+ asciilist list of ascii
+ ========= =============
Example::
_TYPE = {