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 <[email protected]>
---
 ryu/lib/stringify.py | 31 +++++++++++++++++++++++++------
 1 file changed, 25 insertions(+), 6 deletions(-)

diff --git a/ryu/lib/stringify.py b/ryu/lib/stringify.py
index 5d22979..7d08390 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 = {
-- 
2.1.4


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to