use isinstance( obj, basestring) to allow unicode strings

fixes #448
This commit is contained in:
Bob Lantz
2014-11-23 10:59:08 -08:00
parent f0f9907b9d
commit 9a8bdfd765
4 changed files with 11 additions and 11 deletions
+2 -2
View File
@@ -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():
+5 -5
View File
@@ -338,8 +338,8 @@ class Mininet( object ):
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 @@ class Mininet( object ):
# 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 @@ class Mininet( object ):
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:
+3 -3
View File
@@ -355,7 +355,7 @@ class Node( object ):
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 @@ class Node( object ):
"""
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 @@ class Node( object ):
"""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
+1 -1
View File
@@ -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