diff --git a/mininet/moduledeps.py b/mininet/moduledeps.py index 862c1f64d38833645f53a5bf5bcfd73334acec15..860c21c98b48bec98b2c38bed359f4c57f663140 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 cff2bd5f03e0b4e6cca26dd9122f4059e52595cd..6defddba2babbc9786036e93223a46fb88ba4e01 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 5fb0a3407f44102ba0474e2814a047204bc9dd43..b4ef54dd569d0dd16f760f0bacb93debce2796a9 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 0c76a9995d174ffe57ff0a30c59eb8e360c5cbff..1fbc5826d274e0c0f7dfbdc041747dd1cffef49c 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