Signed-off-by: IWAMOTO Toshihiro <[email protected]>
---
 ryu/utils.py | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/ryu/utils.py b/ryu/utils.py
index c4be973..4a5bc44 100644
--- a/ryu/utils.py
+++ b/ryu/utils.py
@@ -33,6 +33,7 @@
 import inspect
 import logging
 import os
+import six
 import sys
 import re
 
@@ -99,19 +100,25 @@ def round_up(x, y):
 
 
 def _str_to_hex(data):
-    """Convert string into array of hexes to be printed."""
+    """Convert str into array of hexes to be printed. (Python2 only)"""
     return ' '.join(hex(ord(char)) for char in data)
 
 
 def _bytearray_to_hex(data):
-    """Convert bytearray into array of hexes to be printed."""
+    """Convert bytearray into array of hexes to be printed.
+    In Python3, this function works for binary_types, too.
+    """
     return ' '.join(hex(byte) for byte in data)
 
 
 def hex_array(data):
-    """Convert string or bytearray into array of hexes to be printed."""
-    to_hex = {str: _str_to_hex,
-              bytearray: _bytearray_to_hex}
+    """Convert binary_type or bytearray into array of hexes to be printed."""
+    if six.PY3:
+        to_hex = {six.binary_type: _bytearray_to_hex,
+                  bytearray: _bytearray_to_hex}
+    else:
+        to_hex = {six.binary_type: _str_to_hex,
+                  bytearray: _bytearray_to_hex}
     try:
         return to_hex[type(data)](data)
     except KeyError:
-- 
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