From 9a8bdfd765039ea3a2611befc709acdd1b62b2e9 Mon Sep 17 00:00:00 2001
From: Bob Lantz <rlantz@cs.stanford.edu>
Date: Sun, 23 Nov 2014 10:59:08 -0800
Subject: [PATCH] use isinstance( obj, basestring) to allow unicode strings

fixes #448
---
 mininet/moduledeps.py |  4 ++--
 mininet/net.py        | 10 +++++-----
 mininet/node.py       |  6 +++---
 mininet/util.py       |  2 +-
 4 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/mininet/moduledeps.py b/mininet/moduledeps.py
index 862c1f64..860c21c9 100644
--- a/mininet/moduledeps.py
+++ b/mininet/moduledeps.py
@@ -28,9 +28,9 @@ def moduleDeps( subtract=None, add=None ):
        add: string or list of module names to add, if not already loaded"""
     subtract = subtract if subtract is not None else []
     add = add if add is not None else []
-    if type( subtract ) is str:
+    if isinstance( subtract, basestring ):
         subtract = [ subtract ]
-    if type( add ) is str:
+    if isinstance( add, basestring ):
         add = [ add ]
     for mod in subtract:
         if mod in lsmod():
diff --git a/mininet/net.py b/mininet/net.py
index cff2bd5f..6defddba 100755
--- a/mininet/net.py
+++ b/mininet/net.py
@@ -338,8 +338,8 @@ def addLink( self, node1, node2, port1=None, port2=None,
             params: additional link params (optional)
             returns: link object"""
         # Accept node objects or names
-        node1 = node1 if type( node1 ) != str else self[ node1 ]
-        node2 = node2 if type( node2 ) != str else self[ node2 ]
+        node1 = node1 if not isinstance( node1, basestring ) else self[ node1 ]
+        node2 = node2 if not isinstance( node2, basestring ) else self[ node2 ]
         options = dict( params )
         # Port is optional
         if port1 is not None:
@@ -388,7 +388,7 @@ def buildFromTopo( self, topo=None ):
             # Add a default controller
             info( '*** Adding controller\n' )
             classes = self.controller
-            if type( classes ) is not list:
+            if not isinstance( classes, list ):
                 classes = [ classes ]
             for i, cls in enumerate( classes ):
                 # Allow Controller objects because nobody understands currying
@@ -808,9 +808,9 @@ def configLinkStatus( self, src, dst, status ):
         elif dst not in self.nameToNode:
             error( 'dst not in network: %s\n' % dst )
         else:
-            if type( src ) is str:
+            if isinstance( src, basestring ):
                 src = self.nameToNode[ src ]
-            if type( dst ) is str:
+            if isinstance( dst, basestring ):
                 dst = self.nameToNode[ dst ]
             connections = src.connectionsTo( dst )
             if len( connections ) == 0:
diff --git a/mininet/node.py b/mininet/node.py
index 5fb0a340..b4ef54dd 100644
--- a/mininet/node.py
+++ b/mininet/node.py
@@ -355,7 +355,7 @@ def popen( self, *args, **kwargs ):
             if type( args[ 0 ] ) is list:
                 # popen([cmd, arg1, arg2...])
                 cmd = args[ 0 ]
-            elif type( args[ 0 ] ) is str:
+            elif isinstance( args[ 0 ], basestring ):
                 # popen("cmd arg1 arg2...")
                 cmd = args[ 0 ].split()
             else:
@@ -432,7 +432,7 @@ def intf( self, intf='' ):
         """
         if not intf:
             return self.defaultIntf()
-        elif type( intf ) is str:
+        elif isinstance( intf, basestring):
             return self.nameToIntf[ intf ]
         else:
             return intf
@@ -484,7 +484,7 @@ def setDefaultRoute( self, intf=None ):
         """Set the default route to go through intf.
            intf: Intf or {dev <intfname> via <gw-ip> ...}"""
         # Note setParam won't call us if intf is none
-        if type( intf ) is str and ' ' in intf:
+        if isinstance( intf, basestring ) and ' ' in intf:
             params = intf
         else:
             params = 'dev %s' % intf
diff --git a/mininet/util.py b/mininet/util.py
index 0c76a999..1fbc5826 100644
--- a/mininet/util.py
+++ b/mininet/util.py
@@ -549,7 +549,7 @@ def waitListening( client=None, server='127.0.0.1', port=80, timeout=None ):
                 partial( quietRun, shell=True ) )
     if not run( 'which telnet' ):
         raise Exception('Could not find telnet' )
-    serverIP = server if type( server ) is str else server.IP()
+    serverIP = server if isinstance( server, basestring ) else server.IP()
     cmd = ( 'sh -c "echo A | telnet -e A %s %s"' %
            ( serverIP, port ) )
     time = 0
-- 
GitLab