Kinder, gentler Python 3 compatibility
Looking at trying to minimize code changes for Python 3. For now we are keeping byte str() in py2 and unicode str() in py3. It's a pain to rewrite all string code to usee u'' for py2 compatibility. However we may need to revisit this for pexpect(). Created compatibility wrappers in util.py: BaseString (replacement for basestring) decode() (optionally decode utf-8 for py3) encode() (optionally encode utf-8 for py3) Also we've switched from the .iter*() flavors to their static alternatives for py2 (note they are iterators in py3!) Changed util.errRun and clean.sh to call decode()
This commit is contained in:
+3
-3
@@ -104,7 +104,7 @@ from mininet.nodelib import NAT
|
||||
from mininet.link import Link, Intf
|
||||
from mininet.util import ( quietRun, fixLimits, numCores, ensureRoot,
|
||||
macColonHex, ipStr, ipParse, netParse, ipAdd,
|
||||
waitListening )
|
||||
waitListening, BaseString )
|
||||
from mininet.term import cleanUpScreens, makeTerms
|
||||
|
||||
# Mininet version: should be consistent with README and LICENSE
|
||||
@@ -383,8 +383,8 @@ class Mininet( object ):
|
||||
params: additional link params (optional)
|
||||
returns: link object"""
|
||||
# Accept node objects or names
|
||||
node1 = node1 if not isinstance( node1, basestring ) else self[ node1 ]
|
||||
node2 = node2 if not isinstance( node2, basestring ) 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:
|
||||
|
||||
Reference in New Issue
Block a user