Index: trunk/src/VBox/Frontends/VBoxShell/vboxshell.py
===================================================================
--- trunk/src/VBox/Frontends/VBoxShell/vboxshell.py	(revision 59795)
+++ trunk/src/VBox/Frontends/VBoxShell/vboxshell.py	(revision 59798)
@@ -2,4 +2,5 @@
 # -*- coding: utf-8 -*-
 # $Id$
+
 """
 VirtualBox Python Shell.
@@ -19,7 +20,9 @@
 """
 
+from __future__ import print_function
+
 __copyright__ = \
 """
-Copyright (C) 2009-2015 Oracle Corporation
+Copyright (C) 2009-2016 Oracle Corporation
 
 This file is part of VirtualBox Open Source Edition (OSE), as
@@ -34,5 +37,6 @@
 
 
-import os, sys
+import os
+import sys
 import traceback
 import shlex
@@ -42,5 +46,4 @@
 from optparse import OptionParser
 from pprint import pprint
-
 
 
@@ -152,5 +155,5 @@
                             matches.append(word)
 
-            except Exception, e:
+            except Exception as e:
                 printErr(self.ctx, e)
                 if g_fVerbose:
@@ -164,5 +167,5 @@
 
     comps = {}
-    for (key, _value) in cmds.items():
+    for (key, _value) in list(cmds.items()):
         comps[key] = None
     completer = CompleterNG(comps, ctx)
@@ -189,5 +192,5 @@
     try:
         while not progress.completed:
-            print "%s %%\r" % (colored(str(progress.percent), 'red')),
+            print("%s %%\r" % (colored(str(progress.percent), 'red')), end="")
             sys.stdout.flush()
             progress.waitForCompletion(wait)
@@ -197,22 +200,22 @@
         return 1
     except KeyboardInterrupt:
-        print "Interrupted."
+        print("Interrupted.")
         ctx['interrupt'] = True
         if progress.cancelable:
-            print "Canceling task..."
+            print("Canceling task...")
             progress.cancel()
         return 0
 
 def printErr(_ctx, e):
-    oVBoxMgr = _ctx['global'];
+    oVBoxMgr = _ctx['global']
     if oVBoxMgr.errIsOurXcptKind(e):
-        print colored('%s: %s' % (oVBoxMgr.xcptToString(e), oVBoxMgr.xcptGetMessage(e)), 'red');
-    else:
-        print colored(str(e), 'red')
+        print(colored('%s: %s' % (oVBoxMgr.xcptToString(e), oVBoxMgr.xcptGetMessage(e)), 'red'))
+    else:
+        print(colored(str(e), 'red'))
 
 def reportError(_ctx, progress):
     errorinfo = progress.errorInfo
     if errorinfo:
-        print colored("Error in module '%s': %s" % (errorinfo.component, errorinfo.text), 'red')
+        print(colored("Error in module '%s': %s" % (errorinfo.component, errorinfo.text), 'red'))
 
 def colCat(_ctx, strg):
@@ -241,5 +244,5 @@
     mach = vbox.createMachine("", name, [], kind, "")
     mach.saveSettings()
-    print "created machine with UUID", mach.id
+    print("created machine with UUID", mach.id)
     vbox.registerMachine(mach)
     # update cache
@@ -248,5 +251,5 @@
 def removeVm(ctx, mach):
     uuid = mach.id
-    print "removing machine ", mach.name, "with UUID", uuid
+    print("removing machine ", mach.name, "with UUID", uuid)
     cmdClosedVm(ctx, mach, detachVmDevice, ["ALL"])
     disks = mach.unregister(ctx['global'].constants.CleanupMode_Full)
@@ -254,5 +257,5 @@
         progress = mach.deleteConfig(disks)
         if progressBar(ctx, progress, 100) and int(progress.resultCode) == 0:
-            print "Success!"
+            print("Success!")
         else:
             reportError(ctx, progress)
@@ -271,5 +274,5 @@
             try:
                 perf.setup(['*'], [mach], 10, 15)
-            except Exception, e:
+            except Exception as e:
                 printErr(ctx, e)
                 if g_fVerbose:
@@ -324,17 +327,17 @@
         return
     for metric in ctx['perf'].query(["*"], [mach]):
-        print metric['name'], metric['values_as_string']
+        print(metric['name'], metric['values_as_string'])
 
 def guestExec(ctx, machine, console, cmds):
-    exec cmds
+    exec(cmds)
 
 def printMouseEvent(_ctx, mev):
-    print "Mouse : mode=%d x=%d y=%d z=%d w=%d buttons=%x" % (mev.mode, mev.x, mev.y, mev.z, mev.w, mev.buttons)
+    print("Mouse : mode=%d x=%d y=%d z=%d w=%d buttons=%x" % (mev.mode, mev.x, mev.y, mev.z, mev.w, mev.buttons))
 
 def printKbdEvent(ctx, kev):
-    print "Kbd: ", ctx['global'].getArray(kev, 'scancodes')
+    print("Kbd: ", ctx['global'].getArray(kev, 'scancodes'))
 
 def printMultiTouchEvent(ctx, mtev):
-    print "MultiTouch : contacts=%d time=%d" % (mtev.contactCount, mtev.scanTime)
+    print("MultiTouch : contacts=%d time=%d" % (mtev.contactCount, mtev.scanTime))
     xPositions = ctx['global'].getArray(mtev, 'xPositions')
     yPositions = ctx['global'].getArray(mtev, 'yPositions')
@@ -343,22 +346,22 @@
 
     for i in range(0, mtev.contactCount):
-        print "  [%d] %d,%d %d %d" % (i, xPositions[i], yPositions[i], contactIds[i], contactFlags[i])
+        print("  [%d] %d,%d %d %d" % (i, xPositions[i], yPositions[i], contactIds[i], contactFlags[i]))
 
 def monitorSource(ctx, eventSource, active, dur):
     def handleEventImpl(event):
         evtype = event.type
-        print "got event: %s %s" % (str(evtype), asEnumElem(ctx, 'VBoxEventType', evtype))
+        print("got event: %s %s" % (str(evtype), asEnumElem(ctx, 'VBoxEventType', evtype)))
         if evtype == ctx['global'].constants.VBoxEventType_OnMachineStateChanged:
             scev = ctx['global'].queryInterface(event, 'IMachineStateChangedEvent')
             if scev:
-                print "machine state event: mach=%s state=%s" % (scev.machineId, scev.state)
+                print("machine state event: mach=%s state=%s" % (scev.machineId, scev.state))
         elif  evtype == ctx['global'].constants.VBoxEventType_OnSnapshotTaken:
             stev = ctx['global'].queryInterface(event, 'ISnapshotTakenEvent')
             if stev:
-                print "snapshot taken event: mach=%s snap=%s" % (stev.machineId, stev.snapshotId)
+                print("snapshot taken event: mach=%s snap=%s" % (stev.machineId, stev.snapshotId))
         elif  evtype == ctx['global'].constants.VBoxEventType_OnGuestPropertyChanged:
             gpcev = ctx['global'].queryInterface(event, 'IGuestPropertyChangedEvent')
             if gpcev:
-                print "guest property change: name=%s value=%s" % (gpcev.name, gpcev.value)
+                print("guest property change: name=%s value=%s" % (gpcev.name, gpcev.value))
         elif  evtype == ctx['global'].constants.VBoxEventType_OnMousePointerShapeChanged:
             psev = ctx['global'].queryInterface(event, 'IMousePointerShapeChangedEvent')
@@ -366,7 +369,7 @@
                 shape = ctx['global'].getArray(psev, 'shape')
                 if shape is None:
-                    print "pointer shape event - empty shape"
+                    print("pointer shape event - empty shape")
                 else:
-                    print "pointer shape event: w=%d h=%d shape len=%d" % (psev.width, psev.height, len(shape))
+                    print("pointer shape event: w=%d h=%d shape len=%d" % (psev.width, psev.height, len(shape)))
         elif evtype == ctx['global'].constants.VBoxEventType_OnGuestMouse:
             mev = ctx['global'].queryInterface(event, 'IGuestMouseEvent')
@@ -441,5 +444,5 @@
     def handleEventImpl(event):
         evtype = event.type
-        #print "got event: %s %s" % (str(evtype), asEnumElem(ctx, 'VBoxEventType', evtype))
+        #print("got event: %s %s" % (str(evtype), asEnumElem(ctx, 'VBoxEventType', evtype)))
         if evtype == ctx['global'].constants.VBoxEventType_OnGuestMouse:
             mev = ctx['global'].queryInterface(event, 'IGuestMouseEvent')
@@ -489,5 +492,5 @@
 
     header = demo.readline()
-    print "Header is", header
+    print("Header is", header)
     basere = re.compile(r'(?P<s>\d+): (?P<t>[km]) (?P<p>.*)')
     mre = re.compile(r'(?P<a>\d+) (?P<x>-*\d+) (?P<y>-*\d+) (?P<z>-*\d+) (?P<w>-*\d+) (?P<b>-*\d+)')
@@ -515,5 +518,5 @@
             if rtype == 'k':
                 codes = kre.findall(params)
-                #print "KBD:", codes
+                #print("KBD:", codes)
                 kbd.putScancodes(codes)
             elif rtype == 'm':
@@ -523,8 +526,8 @@
                     if mdict['a'] == '1':
                         # absolute
-                        #print "MA: ", mdict['x'], mdict['y'], mdict['z'], mdict['b']
+                        #print("MA: ", mdict['x'], mdict['y'], mdict['z'], mdict['b'])
                         mouse.putMouseEventAbsolute(int(mdict['x']), int(mdict['y']), int(mdict['z']), int(mdict['w']), int(mdict['b']))
                     else:
-                        #print "MR: ", mdict['x'], mdict['y'], mdict['b']
+                        #print("MR: ", mdict['x'], mdict['y'], mdict['b'])
                         mouse.putMouseEvent(int(mdict['x']), int(mdict['y']), int(mdict['z']), int(mdict['w']), int(mdict['b']))
 
@@ -559,5 +562,5 @@
         h = fbh
 
-    print "Saving screenshot (%d x %d) screen %d in %s..." % (w, h, screen, f)
+    print("Saving screenshot (%d x %d) screen %d in %s..." % (w, h, screen, f))
     data = display.takeScreenShotToArray(screen, w, h, ctx['const'].BitmapFormat_RGBA)
     size = (w, h)
@@ -586,5 +589,5 @@
         h = fbh
 
-    print "Saving screenshot (%d x %d) screen %d in %s..." % (w, h, screen, f)
+    print("Saving screenshot (%d x %d) screen %d in %s..." % (w, h, screen, f))
     data = display.takeScreenShotToArray(screen, w, h, ctx['const'].BitmapFormat_PNG)
     pngfile = open(f, 'wb')
@@ -594,5 +597,5 @@
 def teleport(ctx, _session, console, args):
     if args[0].find(":") == -1:
-        print "Use host:port format for teleport target"
+        print("Use host:port format for teleport target")
         return
     (host, port) = args[0].split(":")
@@ -608,8 +611,8 @@
 
     port = int(port)
-    print "Teleporting to %s:%d..." % (host, port)
+    print("Teleporting to %s:%d..." % (host, port))
     progress = console.teleport(host, port, passwd, maxDowntime)
     if progressBar(ctx, progress, 100) and int(progress.resultCode) == 0:
-        print "Success!"
+        print("Success!")
     else:
         reportError(ctx, progress)
@@ -632,8 +635,8 @@
     all_stats = ctx['const'].all_values('GuestStatisticType')
     cpu = 0
-    for s in all_stats.keys():
+    for s in list(all_stats.keys()):
         try:
             val = guest.getStatistic( cpu, all_stats[s])
-            print "%s: %d" % (s, val)
+            print("%s: %d" % (s, val))
         except:
             # likely not implemented
@@ -642,10 +645,10 @@
 def plugCpu(_ctx, machine, _session, args):
     cpu = int(args[0])
-    print "Adding CPU %d..." % (cpu)
+    print("Adding CPU %d..." % (cpu))
     machine.hotPlugCPU(cpu)
 
 def unplugCpu(_ctx, machine, _session, args):
     cpu = int(args[0])
-    print "Removing CPU %d..." % (cpu)
+    print("Removing CPU %d..." % (cpu))
     machine.hotUnplugCPU(cpu)
 
@@ -661,31 +664,31 @@
 
 def printHostUsbDev(ctx, ud):
-    print "  %s: %s (vendorId=%d productId=%d serial=%s) %s" % (ud.id, colored(ud.product, 'blue'), ud.vendorId, ud.productId, ud.serialNumber, asEnumElem(ctx, 'USBDeviceState', ud.state))
+    print("  %s: %s (vendorId=%d productId=%d serial=%s) %s" % (ud.id, colored(ud.product, 'blue'), ud.vendorId, ud.productId, ud.serialNumber, asEnumElem(ctx, 'USBDeviceState', ud.state)))
 
 def printUsbDev(_ctx, ud):
-    print "  %s: %s (vendorId=%d productId=%d serial=%s)" % (ud.id,  colored(ud.product, 'blue'), ud.vendorId, ud.productId, ud.serialNumber)
+    print("  %s: %s (vendorId=%d productId=%d serial=%s)" % (ud.id,  colored(ud.product, 'blue'), ud.vendorId, ud.productId, ud.serialNumber))
 
 def printSf(ctx, sf):
-    print "    name=%s host=%s %s %s" % (sf.name, colPath(ctx, sf.hostPath), cond(sf.accessible, "accessible", "not accessible"), cond(sf.writable, "writable", "read-only"))
+    print("    name=%s host=%s %s %s" % (sf.name, colPath(ctx, sf.hostPath), cond(sf.accessible, "accessible", "not accessible"), cond(sf.writable, "writable", "read-only")))
 
 def ginfo(ctx, console, _args):
     guest = console.guest
     if guest.additionsRunLevel != ctx['const'].AdditionsRunLevelType_None:
-        print "Additions active, version %s" % (guest.additionsVersion)
-        print "Support seamless: %s" % (getFacilityStatus(ctx, guest, ctx['const'].AdditionsFacilityType_Seamless))
-        print "Support graphics: %s" % (getFacilityStatus(ctx, guest, ctx['const'].AdditionsFacilityType_Graphics))
-        print "Balloon size: %d" % (guest.memoryBalloonSize)
-        print "Statistic update interval: %d" % (guest.statisticsUpdateInterval)
-    else:
-        print "No additions"
+        print("Additions active, version %s" % (guest.additionsVersion))
+        print("Support seamless: %s" % (getFacilityStatus(ctx, guest, ctx['const'].AdditionsFacilityType_Seamless)))
+        print("Support graphics: %s" % (getFacilityStatus(ctx, guest, ctx['const'].AdditionsFacilityType_Graphics)))
+        print("Balloon size: %d" % (guest.memoryBalloonSize))
+        print("Statistic update interval: %d" % (guest.statisticsUpdateInterval))
+    else:
+        print("No additions")
     usbs = ctx['global'].getArray(console, 'USBDevices')
-    print "Attached USB:"
+    print("Attached USB:")
     for ud in usbs:
         printUsbDev(ctx, ud)
     rusbs = ctx['global'].getArray(console, 'remoteUSBDevices')
-    print "Remote USB:"
+    print("Remote USB:")
     for ud in rusbs:
         printHostUsbDev(ctx, ud)
-    print "Transient shared folders:"
+    print("Transient shared folders:")
     sfs = rusbs = ctx['global'].getArray(console, 'sharedFolders')
     for sf in sfs:
@@ -698,5 +701,5 @@
         session = ctx['global'].getSessionObject(vbox)
         mach.lockMachine(session, ctx['global'].constants.LockType_Shared)
-    except Exception, e:
+    except Exception as e:
         printErr(ctx, "Session to '%s' not open: %s" % (mach.name, str(e)))
         if g_fVerbose:
@@ -704,5 +707,5 @@
         return
     if session.state != ctx['const'].SessionState_Locked:
-        print "Session to '%s' in wrong state: %s" % (mach.name, session.state)
+        print("Session to '%s' in wrong state: %s" % (mach.name, session.state))
         session.unlockMachine()
         return
@@ -710,5 +713,5 @@
     # in Webservices) functionality
     if ctx['remote'] and cmd == 'some_local_only_command':
-        print 'Trying to use local only functionality, ignored'
+        print('Trying to use local only functionality, ignored')
         session.unlockMachine()
         return
@@ -734,5 +737,5 @@
     except KeyboardInterrupt:
         ctx['interrupt'] = True
-    except Exception, e:
+    except Exception as e:
         printErr(ctx, e)
         if g_fVerbose:
@@ -747,5 +750,5 @@
     try:
         cmd(ctx, mach, args)
-    except Exception, e:
+    except Exception as e:
         save = False
         printErr(ctx, e)
@@ -755,5 +758,5 @@
         try:
             mach.saveSettings()
-        except Exception, e:
+        except Exception as e:
             printErr(ctx, e)
             if g_fVerbose:
@@ -767,5 +770,5 @@
     try:
         cmd(ctx, mach, session.console, args)
-    except Exception, e:
+    except Exception as e:
         save = False
         printErr(ctx, e)
@@ -777,8 +780,5 @@
 
 def machById(ctx, uuid):
-    try:
-        mach = ctx['vb'].getMachine(uuid)
-    except:
-        mach = ctx['vb'].findMachine(uuid)
+    mach = ctx['vb'].findMachine(uuid)
     return mach
 
@@ -899,10 +899,10 @@
 def argsToMach(ctx, args):
     if len(args) < 2:
-        print "usage: %s [vmname|uuid]" % (args[0])
+        print("usage: %s [vmname|uuid]" % (args[0]))
         return None
     uuid = args[1]
     mach = machById(ctx, uuid)
     if mach == None:
-        print "Machine '%s' is unknown, use list command to find available machines" % (uuid)
+        print("Machine '%s' is unknown, use list command to find available machines" % (uuid))
     return mach
 
@@ -912,10 +912,10 @@
     else:
         spec = ""
-    print "    %s: %s%s" % (colored(cmd, 'blue'), h, spec)
+    print("    %s: %s%s" % (colored(cmd, 'blue'), h, spec))
 
 def helpCmd(_ctx, args):
     if len(args) == 1:
-        print "Help page:"
-        names = commands.keys()
+        print("Help page:")
+        names = list(commands.keys())
         names.sort()
         for i in names:
@@ -925,5 +925,5 @@
         c = commands.get(cmd)
         if c == None:
-            print "Command '%s' not known" % (cmd)
+            print("Command '%s' not known" % (cmd))
         else:
             helpSingleCmd(cmd, c[0], c[2])
@@ -932,5 +932,5 @@
 def asEnumElem(ctx, enum, elem):
     enumVals = ctx['const'].all_values(enum)
-    for e in enumVals.keys():
+    for e in list(enumVals.keys()):
         if str(elem) == str(enumVals[e]):
             return colored(e, 'green')
@@ -948,6 +948,6 @@
             else:
                 tele = "    "
-                print "%sMachine '%s' [%s], machineState=%s, sessionState=%s" % (tele, colVm(ctx, mach.name), mach.id, asEnumElem(ctx, "MachineState", mach.state), asEnumElem(ctx, "SessionState", mach.sessionState))
-        except Exception, e:
+                print("%sMachine '%s' [%s], machineState=%s, sessionState=%s" % (tele, colVm(ctx, mach.name), mach.id, asEnumElem(ctx, "MachineState", mach.state), asEnumElem(ctx, "SessionState", mach.sessionState)))
+        except Exception as e:
             printErr(ctx, e)
             if g_fVerbose:
@@ -956,6 +956,6 @@
 
 def infoCmd(ctx, args):
-    if (len(args) < 2):
-        print "usage: info [vmname|uuid]"
+    if len(args) < 2:
+        print("usage: info [vmname|uuid]")
         return 0
     mach = argsToMach(ctx, args)
@@ -963,109 +963,109 @@
         return 0
     vmos = ctx['vb'].getGuestOSType(mach.OSTypeId)
-    print " One can use setvar <mach> <var> <value> to change variable, using name in []."
-    print "  Name [name]: %s" % (colVm(ctx, mach.name))
-    print "  Description [description]: %s" % (mach.description)
-    print "  ID [n/a]: %s" % (mach.id)
-    print "  OS Type [via OSTypeId]: %s" % (vmos.description)
-    print "  Firmware [firmwareType]: %s (%s)" % (asEnumElem(ctx, "FirmwareType", mach.firmwareType), mach.firmwareType)
-    print
-    print "  CPUs [CPUCount]: %d" % (mach.CPUCount)
-    print "  RAM [memorySize]: %dM" % (mach.memorySize)
-    print "  VRAM [VRAMSize]: %dM" % (mach.VRAMSize)
-    print "  Monitors [monitorCount]: %d" % (mach.monitorCount)
-    print "  Chipset [chipsetType]: %s (%s)" % (asEnumElem(ctx, "ChipsetType", mach.chipsetType), mach.chipsetType)
-    print
-    print "  Clipboard mode [clipboardMode]: %s (%s)" % (asEnumElem(ctx, "ClipboardMode", mach.clipboardMode), mach.clipboardMode)
-    print "  Machine status [n/a]: %s (%s)" % (asEnumElem(ctx, "SessionState", mach.sessionState), mach.sessionState)
-    print
+    print(" One can use setvar <mach> <var> <value> to change variable, using name in [].")
+    print("  Name [name]: %s" % (colVm(ctx, mach.name)))
+    print("  Description [description]: %s" % (mach.description))
+    print("  ID [n/a]: %s" % (mach.id))
+    print("  OS Type [via OSTypeId]: %s" % (vmos.description))
+    print("  Firmware [firmwareType]: %s (%s)" % (asEnumElem(ctx, "FirmwareType", mach.firmwareType), mach.firmwareType))
+    print()
+    print("  CPUs [CPUCount]: %d" % (mach.CPUCount))
+    print("  RAM [memorySize]: %dM" % (mach.memorySize))
+    print("  VRAM [VRAMSize]: %dM" % (mach.VRAMSize))
+    print("  Monitors [monitorCount]: %d" % (mach.monitorCount))
+    print("  Chipset [chipsetType]: %s (%s)" % (asEnumElem(ctx, "ChipsetType", mach.chipsetType), mach.chipsetType))
+    print()
+    print("  Clipboard mode [clipboardMode]: %s (%s)" % (asEnumElem(ctx, "ClipboardMode", mach.clipboardMode), mach.clipboardMode))
+    print("  Machine status [n/a]: %s (%s)" % (asEnumElem(ctx, "SessionState", mach.sessionState), mach.sessionState))
+    print()
     if mach.teleporterEnabled:
-        print "  Teleport target on port %d (%s)" % (mach.teleporterPort, mach.teleporterPassword)
-        print
+        print("  Teleport target on port %d (%s)" % (mach.teleporterPort, mach.teleporterPassword))
+        print()
     bios = mach.BIOSSettings
-    print "  ACPI [BIOSSettings.ACPIEnabled]: %s" % (asState(bios.ACPIEnabled))
-    print "  APIC [BIOSSettings.IOAPICEnabled]: %s" % (asState(bios.IOAPICEnabled))
+    print("  ACPI [BIOSSettings.ACPIEnabled]: %s" % (asState(bios.ACPIEnabled)))
+    print("  APIC [BIOSSettings.IOAPICEnabled]: %s" % (asState(bios.IOAPICEnabled)))
     hwVirtEnabled = mach.getHWVirtExProperty(ctx['global'].constants.HWVirtExPropertyType_Enabled)
-    print "  Hardware virtualization [guest win machine.setHWVirtExProperty(ctx[\\'const\\'].HWVirtExPropertyType_Enabled, value)]: " + asState(hwVirtEnabled)
+    print("  Hardware virtualization [guest win machine.setHWVirtExProperty(ctx[\\'const\\'].HWVirtExPropertyType_Enabled, value)]: " + asState(hwVirtEnabled))
     hwVirtVPID = mach.getHWVirtExProperty(ctx['const'].HWVirtExPropertyType_VPID)
-    print "  VPID support [guest win machine.setHWVirtExProperty(ctx[\\'const\\'].HWVirtExPropertyType_VPID, value)]: " + asState(hwVirtVPID)
+    print("  VPID support [guest win machine.setHWVirtExProperty(ctx[\\'const\\'].HWVirtExPropertyType_VPID, value)]: " + asState(hwVirtVPID))
     hwVirtNestedPaging = mach.getHWVirtExProperty(ctx['const'].HWVirtExPropertyType_NestedPaging)
-    print "  Nested paging [guest win machine.setHWVirtExProperty(ctx[\\'const\\'].HWVirtExPropertyType_NestedPaging, value)]: " + asState(hwVirtNestedPaging)
-
-    print "  Hardware 3d acceleration [accelerate3DEnabled]: " + asState(mach.accelerate3DEnabled)
-    print "  Hardware 2d video acceleration [accelerate2DVideoEnabled]: " + asState(mach.accelerate2DVideoEnabled)
-
-    print "  Use universal time [RTCUseUTC]: %s" % (asState(mach.RTCUseUTC))
-    print "  HPET [HPETEnabled]: %s" % (asState(mach.HPETEnabled))
+    print("  Nested paging [guest win machine.setHWVirtExProperty(ctx[\\'const\\'].HWVirtExPropertyType_NestedPaging, value)]: " + asState(hwVirtNestedPaging))
+
+    print("  Hardware 3d acceleration [accelerate3DEnabled]: " + asState(mach.accelerate3DEnabled))
+    print("  Hardware 2d video acceleration [accelerate2DVideoEnabled]: " + asState(mach.accelerate2DVideoEnabled))
+
+    print("  Use universal time [RTCUseUTC]: %s" % (asState(mach.RTCUseUTC)))
+    print("  HPET [HPETEnabled]: %s" % (asState(mach.HPETEnabled)))
     if mach.audioAdapter.enabled:
-        print "  Audio [via audioAdapter]: chip %s; host driver %s" % (asEnumElem(ctx, "AudioControllerType", mach.audioAdapter.audioController), asEnumElem(ctx, "AudioDriverType",  mach.audioAdapter.audioDriver))
-    print "  CPU hotplugging [CPUHotPlugEnabled]: %s" % (asState(mach.CPUHotPlugEnabled))
-
-    print "  Keyboard [keyboardHIDType]: %s (%s)" % (asEnumElem(ctx, "KeyboardHIDType", mach.keyboardHIDType), mach.keyboardHIDType)
-    print "  Pointing device [pointingHIDType]: %s (%s)" % (asEnumElem(ctx, "PointingHIDType", mach.pointingHIDType), mach.pointingHIDType)
-    print "  Last changed [n/a]: " + time.asctime(time.localtime(long(mach.lastStateChange)/1000))
+        print("  Audio [via audioAdapter]: chip %s; host driver %s" % (asEnumElem(ctx, "AudioControllerType", mach.audioAdapter.audioController), asEnumElem(ctx, "AudioDriverType",  mach.audioAdapter.audioDriver)))
+    print("  CPU hotplugging [CPUHotPlugEnabled]: %s" % (asState(mach.CPUHotPlugEnabled)))
+
+    print("  Keyboard [keyboardHIDType]: %s (%s)" % (asEnumElem(ctx, "KeyboardHIDType", mach.keyboardHIDType), mach.keyboardHIDType))
+    print("  Pointing device [pointingHIDType]: %s (%s)" % (asEnumElem(ctx, "PointingHIDType", mach.pointingHIDType), mach.pointingHIDType))
+    print("  Last changed [n/a]: " + time.asctime(time.localtime(mach.lastStateChange/1000)))
     # OSE has no VRDE
     try:
-        print "  VRDE server [VRDEServer.enabled]: %s" % (asState(mach.VRDEServer.enabled))
+        print("  VRDE server [VRDEServer.enabled]: %s" % (asState(mach.VRDEServer.enabled)))
     except:
         pass
 
-    print
-    print colCat(ctx, "  USB Controllers:")
+    print()
+    print(colCat(ctx, "  USB Controllers:"))
     for oUsbCtrl in ctx['global'].getArray(mach, 'USBControllers'):
-        print "    '%s': type %s  standard: %#x" \
-            % (oUsbCtrl.name, asEnumElem(ctx, "USBControllerType", oUsbCtrl.type), oUsbCtrl.USBStandard);
-
-    print
-    print colCat(ctx, "  I/O subsystem info:")
-    print "   Cache enabled [IOCacheEnabled]: %s" % (asState(mach.IOCacheEnabled))
-    print "   Cache size [IOCacheSize]: %dM" % (mach.IOCacheSize)
+        print("    '%s': type %s  standard: %#x" \
+            % (oUsbCtrl.name, asEnumElem(ctx, "USBControllerType", oUsbCtrl.type), oUsbCtrl.USBStandard))
+
+    print()
+    print(colCat(ctx, "  I/O subsystem info:"))
+    print("   Cache enabled [IOCacheEnabled]: %s" % (asState(mach.IOCacheEnabled)))
+    print("   Cache size [IOCacheSize]: %dM" % (mach.IOCacheSize))
 
     controllers = ctx['global'].getArray(mach, 'storageControllers')
     if controllers:
-        print
-        print colCat(ctx, "  Storage Controllers:")
+        print()
+        print(colCat(ctx, "  Storage Controllers:"))
     for controller in controllers:
-        print "    '%s': bus %s type %s" % (controller.name, asEnumElem(ctx, "StorageBus", controller.bus), asEnumElem(ctx, "StorageControllerType", controller.controllerType))
+        print("    '%s': bus %s type %s" % (controller.name, asEnumElem(ctx, "StorageBus", controller.bus), asEnumElem(ctx, "StorageControllerType", controller.controllerType)))
 
     attaches = ctx['global'].getArray(mach, 'mediumAttachments')
     if attaches:
-        print
-        print colCat(ctx, "  Media:")
+        print()
+        print(colCat(ctx, "  Media:"))
     for a in attaches:
-        print "   Controller: '%s' port/device: %d:%d type: %s (%s):" % (a.controller, a.port, a.device, asEnumElem(ctx, "DeviceType", a.type), a.type)
+        print("   Controller: '%s' port/device: %d:%d type: %s (%s):" % (a.controller, a.port, a.device, asEnumElem(ctx, "DeviceType", a.type), a.type))
         medium = a.medium
         if a.type == ctx['global'].constants.DeviceType_HardDisk:
-            print "   HDD:"
-            print "    Id: %s" % (medium.id)
-            print "    Location: %s" % (colPath(ctx, medium.location))
-            print "    Name: %s" % (medium.name)
-            print "    Format: %s" % (medium.format)
+            print("   HDD:")
+            print("    Id: %s" % (medium.id))
+            print("    Location: %s" % (colPath(ctx, medium.location)))
+            print("    Name: %s" % (medium.name))
+            print("    Format: %s" % (medium.format))
 
         if a.type == ctx['global'].constants.DeviceType_DVD:
-            print "   DVD:"
+            print("   DVD:")
             if medium:
-                print "    Id: %s" % (medium.id)
-                print "    Name: %s" % (medium.name)
+                print("    Id: %s" % (medium.id))
+                print("    Name: %s" % (medium.name))
                 if medium.hostDrive:
-                    print "    Host DVD %s" % (colPath(ctx, medium.location))
+                    print("    Host DVD %s" % (colPath(ctx, medium.location)))
                     if a.passthrough:
-                        print "    [passthrough mode]"
+                        print("    [passthrough mode]")
                 else:
-                    print "    Virtual image at %s" % (colPath(ctx, medium.location))
-                    print "    Size: %s" % (medium.size)
+                    print("    Virtual image at %s" % (colPath(ctx, medium.location)))
+                    print("    Size: %s" % (medium.size))
 
         if a.type == ctx['global'].constants.DeviceType_Floppy:
-            print "   Floppy:"
+            print("   Floppy:")
             if medium:
-                print "    Id: %s" % (medium.id)
-                print "    Name: %s" % (medium.name)
+                print("    Id: %s" % (medium.id))
+                print("    Name: %s" % (medium.name))
                 if medium.hostDrive:
-                    print "    Host floppy %s" % (colPath(ctx, medium.location))
+                    print("    Host floppy %s" % (colPath(ctx, medium.location)))
                 else:
-                    print "    Virtual image at %s" % (colPath(ctx, medium.location))
-                    print "    Size: %s" % (medium.size)
-
-    print
-    print colCat(ctx, "  Shared folders:")
+                    print("    Virtual image at %s" % (colPath(ctx, medium.location)))
+                    print("    Size: %s" % (medium.size))
+
+    print()
+    print(colCat(ctx, "  Shared folders:"))
     for sf in ctx['global'].getArray(mach, 'sharedFolders'):
         printSf(ctx, sf)
@@ -1075,5 +1075,5 @@
 def startCmd(ctx, args):
     if len(args) < 2:
-        print "usage: start name <frontend>"
+        print("usage: start name <frontend>")
         return 0
     mach = argsToMach(ctx, args)
@@ -1088,6 +1088,6 @@
 
 def createVmCmd(ctx, args):
-    if (len(args) != 3):
-        print "usage: createvm name ostype"
+    if len(args) != 3:
+        print("usage: createvm name ostype")
         return 0
     name = args[1]
@@ -1096,5 +1096,5 @@
         ctx['vb'].getGuestOSType(oskind)
     except Exception:
-        print 'Unknown OS type:', oskind
+        print('Unknown OS type:', oskind)
         return 0
     createVm(ctx, name, oskind)
@@ -1102,6 +1102,6 @@
 
 def ginfoCmd(ctx, args):
-    if (len(args) < 2):
-        print "usage: ginfo [vmname|uuid]"
+    if len(args) < 2:
+        print("usage: ginfo [vmname|uuid]")
         return 0
     mach = argsToMach(ctx, args)
@@ -1113,5 +1113,5 @@
 def execInGuest(ctx, console, args, env, user, passwd, tmo, inputPipe=None, outputPipe=None):
     if len(args) < 1:
-        print "exec in guest needs at least program name"
+        print("exec in guest needs at least program name")
         return
     guest = console.guest
@@ -1119,11 +1119,11 @@
     # shall contain program name as argv[0]
     gargs = args
-    print "executing %s with args %s as %s" % (args[0], gargs, user)
+    print("executing %s with args %s as %s" % (args[0], gargs, user))
     flags = 0
     if inputPipe is not None:
         flags = 1 # set WaitForProcessStartOnly
-    print args[0]
+    print(args[0])
     process = guestSession.processCreate(args[0], gargs, env, [], tmo)
-    print "executed with pid %d" % (process.PID)
+    print("executed with pid %d" % (process.PID))
     if pid != 0:
         try:
@@ -1161,10 +1161,10 @@
 
         except KeyboardInterrupt:
-            print "Interrupted."
+            print("Interrupted.")
             ctx['interrupt'] = True
             if progress.cancelable:
                 progress.cancel()
         (_reason, code, _flags) = guest.getProcessStatus(pid)
-        print "Exit code: %d" % (code)
+        print("Exit code: %d" % (code))
         return 0
     else:
@@ -1175,5 +1175,5 @@
     dst = args[1]
     flags = 0
-    print "Copying host %s to guest %s" % (src, dst)
+    print("Copying host %s to guest %s" % (src, dst))
     progress = console.guest.copyToGuest(src, dst, user, passwd, flags)
     progressBar(ctx, progress)
@@ -1196,5 +1196,5 @@
     user = getpass.getuser()
     user_inp = nh_raw_input("User (%s): " % (user))
-    if len (user_inp) > 0:
+    if len(user_inp) > 0:
         user = user_inp
     passwd = getpass.getpass()
@@ -1203,6 +1203,6 @@
 
 def gexecCmd(ctx, args):
-    if (len(args) < 2):
-        print "usage: gexec [vmname|uuid] command args"
+    if len(args) < 2:
+        print("usage: gexec [vmname|uuid] command args")
         return 0
     mach = argsToMach(ctx, args)
@@ -1217,6 +1217,6 @@
 
 def gcopyCmd(ctx, args):
-    if (len(args) < 2):
-        print "usage: gcopy [vmname|uuid] host_path guest_path"
+    if len(args) < 2:
+        print("usage: gcopy [vmname|uuid] host_path guest_path")
         return 0
     mach = argsToMach(ctx, args)
@@ -1236,6 +1236,6 @@
 
 def gpipeCmd(ctx, args):
-    if (len(args) < 4):
-        print "usage: gpipe [vmname|uuid] hostProgram guestProgram, such as gpipe linux  '/bin/uname -a' '/bin/sh -c \"/usr/bin/tee; /bin/uname -a\"'"
+    if len(args) < 4:
+        print("usage: gpipe [vmname|uuid] hostProgram guestProgram, such as gpipe linux  '/bin/uname -a' '/bin/sh -c \"/usr/bin/tee; /bin/uname -a\"'")
         return 0
     mach = argsToMach(ctx, args)
@@ -1309,6 +1309,6 @@
 
 def guestCmd(ctx, args):
-    if (len(args) < 3):
-        print "usage: guest name commands"
+    if len(args) < 3:
+        print("usage: guest name commands")
         return 0
     mach = argsToMach(ctx, args)
@@ -1322,6 +1322,6 @@
 
 def screenshotCmd(ctx, args):
-    if (len(args) < 2):
-        print "usage: screenshot vm <file> <width> <height> <monitor>"
+    if len(args) < 2:
+        print("usage: screenshot vm <file> <width> <height> <monitor>")
         return 0
     mach = argsToMach(ctx, args)
@@ -1332,6 +1332,6 @@
 
 def teleportCmd(ctx, args):
-    if (len(args) < 3):
-        print "usage: teleport name host:port <password>"
+    if len(args) < 3:
+        print("usage: teleport name host:port <password>")
         return 0
     mach = argsToMach(ctx, args)
@@ -1351,6 +1351,6 @@
 
 def openportalCmd(ctx, args):
-    if (len(args) < 3):
-        print "usage: openportal name port <password>"
+    if len(args) < 3:
+        print("usage: openportal name port <password>")
         return 0
     mach = argsToMach(ctx, args)
@@ -1358,5 +1358,5 @@
         return 0
     port = int(args[2])
-    if (len(args) > 3):
+    if len(args) > 3:
         passwd = args[3]
     else:
@@ -1368,6 +1368,6 @@
 
 def closeportalCmd(ctx, args):
-    if (len(args) < 2):
-        print "usage: closeportal name"
+    if len(args) < 2:
+        print("usage: closeportal name")
         return 0
     mach = argsToMach(ctx, args)
@@ -1379,6 +1379,6 @@
 
 def gueststatsCmd(ctx, args):
-    if (len(args) < 2):
-        print "usage: gueststats name <check interval>"
+    if len(args) < 2:
+        print("usage: gueststats name <check interval>")
         return 0
     mach = argsToMach(ctx, args)
@@ -1392,13 +1392,13 @@
     cpu = args[1]
     if plug:
-        print "Adding CPU %d..." % (cpu)
+        print("Adding CPU %d..." % (cpu))
         mach.hotPlugCPU(cpu)
     else:
-        print "Removing CPU %d..." % (cpu)
+        print("Removing CPU %d..." % (cpu))
         mach.hotUnplugCPU(cpu)
 
 def plugcpuCmd(ctx, args):
-    if (len(args) < 2):
-        print "usage: plugcpu name cpuid"
+    if len(args) < 2:
+        print("usage: plugcpu name cpuid")
         return 0
     mach = argsToMach(ctx, args)
@@ -1413,6 +1413,6 @@
 
 def unplugcpuCmd(ctx, args):
-    if (len(args) < 2):
-        print "usage: unplugcpu name cpuid"
+    if len(args) < 2:
+        print("usage: unplugcpu name cpuid")
         return 0
     mach = argsToMach(ctx, args)
@@ -1428,10 +1428,10 @@
 def setvar(_ctx, _mach, args):
     expr = 'mach.'+args[0]+' = '+args[1]
-    print "Executing", expr
-    exec expr
+    print("Executing", expr)
+    exec(expr)
 
 def setvarCmd(ctx, args):
-    if (len(args) < 4):
-        print "usage: setvar [vmname|uuid] expr value"
+    if len(args) < 4:
+        print("usage: setvar [vmname|uuid] expr value")
         return 0
     mach = argsToMach(ctx, args)
@@ -1444,10 +1444,10 @@
     key = args[0]
     value = args[1]
-    print "%s: setting %s to %s" % (mach.name, key, value if value else None)
+    print("%s: setting %s to %s" % (mach.name, key, value if value else None))
     mach.setExtraData(key, value)
 
 def setExtraDataCmd(ctx, args):
-    if (len(args) < 3):
-        print "usage: setextra [vmname|uuid|global] key <value>"
+    if len(args) < 3:
+        print("usage: setextra [vmname|uuid|global] key <value>")
         return 0
     key = args[2]
@@ -1467,9 +1467,9 @@
 
 def printExtraKey(obj, key, value):
-    print "%s: '%s' = '%s'" % (obj, key, value)
+    print("%s: '%s' = '%s'" % (obj, key, value))
 
 def getExtraDataCmd(ctx, args):
-    if (len(args) < 2):
-        print "usage: getextra [vmname|uuid|global] <key>"
+    if len(args) < 2:
+        print("usage: getextra [vmname|uuid|global] <key>")
         return 0
     if len(args) == 3:
@@ -1498,15 +1498,15 @@
 
 def aliasCmd(ctx, args):
-    if (len(args) == 3):
+    if len(args) == 3:
         aliases[args[1]] = args[2]
         return 0
 
-    for (key, value) in aliases.items():
-        print "'%s' is an alias for '%s'" % (key, value)
+    for (key, value) in list(aliases.items()):
+        print("'%s' is an alias for '%s'" % (key, value))
     return 0
 
 def verboseCmd(ctx, args):
     global g_fVerbose
-    if (len(args) > 1):
+    if len(args) > 1:
         g_fVerbose = (args[1]=='on')
     else:
@@ -1516,5 +1516,5 @@
 def colorsCmd(ctx, args):
     global g_fHasColors
-    if (len(args) > 1):
+    if len(args) > 1:
         g_fHasColors = (args[1] == 'on')
     else:
@@ -1525,44 +1525,44 @@
     vbox = ctx['vb']
     try:
-        print "VirtualBox version %s" % (colored(vbox.version, 'blue'))
-    except Exception, e:
+        print("VirtualBox version %s" % (colored(vbox.version, 'blue')))
+    except Exception as e:
         printErr(ctx, e)
         if g_fVerbose:
             traceback.print_exc()
     props = vbox.systemProperties
-    print "Machines: %s" % (colPath(ctx, props.defaultMachineFolder))
-
-    #print "Global shared folders:"
+    print("Machines: %s" % (colPath(ctx, props.defaultMachineFolder)))
+
+    #print("Global shared folders:")
     #for ud in ctx['global'].getArray(vbox, 'sharedFolders'):
     #    printSf(ctx, sf)
     host = vbox.host
     cnt = host.processorCount
-    print colCat(ctx, "Processors:")
-    print "  available/online: %d/%d " % (cnt, host.processorOnlineCount)
+    print(colCat(ctx, "Processors:"))
+    print("  available/online: %d/%d " % (cnt, host.processorOnlineCount))
     for i in range(0, cnt):
-        print "  processor #%d speed: %dMHz %s" % (i, host.getProcessorSpeed(i), host.getProcessorDescription(i))
-
-    print colCat(ctx, "RAM:")
-    print "  %dM (free %dM)" % (host.memorySize, host.memoryAvailable)
-    print colCat(ctx, "OS:")
-    print "  %s (%s)" % (host.operatingSystem, host.OSVersion)
+        print("  processor #%d speed: %dMHz %s" % (i, host.getProcessorSpeed(i), host.getProcessorDescription(i)))
+
+    print(colCat(ctx, "RAM:"))
+    print("  %dM (free %dM)" % (host.memorySize, host.memoryAvailable))
+    print(colCat(ctx, "OS:"))
+    print("  %s (%s)" % (host.operatingSystem, host.OSVersion))
     if host.acceleration3DAvailable:
-        print colCat(ctx, "3D acceleration available")
-    else:
-        print colCat(ctx, "3D acceleration NOT available")
-
-    print colCat(ctx, "Network interfaces:")
+        print(colCat(ctx, "3D acceleration available"))
+    else:
+        print(colCat(ctx, "3D acceleration NOT available"))
+
+    print(colCat(ctx, "Network interfaces:"))
     for ni in ctx['global'].getArray(host, 'networkInterfaces'):
-        print "  %s (%s)" % (ni.name, ni.IPAddress)
-
-    print colCat(ctx, "DVD drives:")
+        print("  %s (%s)" % (ni.name, ni.IPAddress))
+
+    print(colCat(ctx, "DVD drives:"))
     for dd in ctx['global'].getArray(host, 'DVDDrives'):
-        print "  %s - %s" % (dd.name, dd.description)
-
-    print colCat(ctx, "Floppy drives:")
+        print("  %s - %s" % (dd.name, dd.description))
+
+    print(colCat(ctx, "Floppy drives:"))
     for dd in ctx['global'].getArray(host, 'floppyDrives'):
-        print "  %s - %s" % (dd.name, dd.description)
-
-    print colCat(ctx, "USB devices:")
+        print("  %s - %s" % (dd.name, dd.description))
+
+    print(colCat(ctx, "USB devices:"))
     for ud in ctx['global'].getArray(host, 'USBDevices'):
         printHostUsbDev(ctx, ud)
@@ -1570,11 +1570,11 @@
     if ctx['perf']:
         for metric in ctx['perf'].query(["*"], [host]):
-            print metric['name'], metric['values_as_string']
+            print(metric['name'], metric['values_as_string'])
 
     return 0
 
 def monitorGuestCmd(ctx, args):
-    if (len(args) < 2):
-        print "usage: monitorGuest name (duration)"
+    if len(args) < 2:
+        print("usage: monitorGuest name (duration)")
         return 0
     mach = argsToMach(ctx, args)
@@ -1589,6 +1589,6 @@
 
 def monitorGuestKbdCmd(ctx, args):
-    if (len(args) < 2):
-        print "usage: monitorGuestKbd name (duration)"
+    if len(args) < 2:
+        print("usage: monitorGuestKbd name (duration)")
         return 0
     mach = argsToMach(ctx, args)
@@ -1603,6 +1603,6 @@
 
 def monitorGuestMouseCmd(ctx, args):
-    if (len(args) < 2):
-        print "usage: monitorGuestMouse name (duration)"
+    if len(args) < 2:
+        print("usage: monitorGuestMouse name (duration)")
         return 0
     mach = argsToMach(ctx, args)
@@ -1617,6 +1617,6 @@
 
 def monitorGuestMultiTouchCmd(ctx, args):
-    if (len(args) < 2):
-        print "usage: monitorGuestMultiTouch name (duration)"
+    if len(args) < 2:
+        print("usage: monitorGuestMultiTouch name (duration)")
         return 0
     mach = argsToMach(ctx, args)
@@ -1631,6 +1631,6 @@
 
 def monitorVBoxCmd(ctx, args):
-    if (len(args) > 2):
-        print "usage: monitorVBox (duration)"
+    if len(args) > 2:
+        print("usage: monitorVBox (duration)")
         return 0
     dur = 5
@@ -1659,6 +1659,6 @@
 
 def portForwardCmd(ctx, args):
-    if (len(args) != 5):
-        print "usage: portForward <vm> <adapter> <hostPort> <guestPort>"
+    if len(args) != 5:
+        print("usage: portForward <vm> <adapter> <hostPort> <guestPort>")
         return 0
     mach = argsToMach(ctx, args)
@@ -1690,6 +1690,6 @@
 
 def showLogCmd(ctx, args):
-    if (len(args) < 2):
-        print "usage: showLog vm <num>"
+    if len(args) < 2:
+        print("usage: showLog vm <num>")
         return 0
     mach = argsToMach(ctx, args)
@@ -1698,5 +1698,5 @@
 
     log = 0
-    if (len(args) > 2):
+    if len(args) > 2:
         log = args[2]
 
@@ -1704,5 +1704,5 @@
     while True:
         data = mach.readLog(log, uOffset, 4096)
-        if (len(data) == 0):
+        if len(data) == 0:
             break
         # print adds either NL or space to chunks not ending with a NL
@@ -1713,6 +1713,6 @@
 
 def findLogCmd(ctx, args):
-    if (len(args) < 3):
-        print "usage: findLog vm pattern <num>"
+    if len(args) < 3:
+        print("usage: findLog vm pattern <num>")
         return 0
     mach = argsToMach(ctx, args)
@@ -1721,5 +1721,5 @@
 
     log = 0
-    if (len(args) > 3):
+    if len(args) > 3:
         log = args[3]
 
@@ -1729,5 +1729,5 @@
         # to reduce line splits on buffer boundary
         data = mach.readLog(log, uOffset, 512*1024)
-        if (len(data) == 0):
+        if len(data) == 0:
             break
         d = str(data).split("\n")
@@ -1737,5 +1737,5 @@
                 for mt in match:
                     s = s.replace(mt, colored(mt, 'red'))
-                print s
+                print(s)
         uOffset += len(data)
 
@@ -1744,6 +1744,6 @@
 
 def findAssertCmd(ctx, args):
-    if (len(args) < 2):
-        print "usage: findAssert vm <num>"
+    if len(args) < 2:
+        print("usage: findAssert vm <num>")
         return 0
     mach = argsToMach(ctx, args)
@@ -1752,5 +1752,5 @@
 
     log = 0
-    if (len(args) > 2):
+    if len(args) > 2:
         log = args[2]
 
@@ -1762,10 +1762,10 @@
         # to reduce line splits on buffer boundary
         data = mach.readLog(log, uOffset, 512*1024)
-        if (len(data) == 0):
+        if len(data) == 0:
             break
         d = str(data).split("\n")
         for s in d:
             if active:
-                print s
+                print(s)
                 if context == 0:
                     active = False
@@ -1777,5 +1777,5 @@
                 active = True
                 context = 50
-                print s
+                print(s)
         uOffset += len(data)
 
@@ -1785,6 +1785,6 @@
     expr = ' '.join(args[1:])
     try:
-        exec expr
-    except Exception, e:
+        exec(expr)
+    except Exception as e:
         printErr(ctx, e)
         if g_fVerbose:
@@ -1799,11 +1799,11 @@
 
 def runScriptCmd(ctx, args):
-    if (len(args) != 2):
-        print "usage: runScript <script>"
+    if len(args) != 2:
+        print("usage: runScript <script>")
         return 0
     try:
         lf = open(args[1], 'r')
-    except IOError, e:
-        print "cannot open:", args[1], ":", e
+    except IOError as e:
+        print("cannot open:", args[1], ":", e)
         return 0
 
@@ -1819,5 +1819,5 @@
                 break
 
-    except Exception, e:
+    except Exception as e:
         printErr(ctx, e)
         if g_fVerbose:
@@ -1827,6 +1827,6 @@
 
 def sleepCmd(ctx, args):
-    if (len(args) != 2):
-        print "usage: sleep <secs>"
+    if len(args) != 2:
+        print("usage: sleep <secs>")
         return 0
 
@@ -1840,6 +1840,6 @@
 
 def shellCmd(ctx, args):
-    if (len(args) < 2):
-        print "usage: shell <commands>"
+    if len(args) < 2:
+        print("usage: shell <commands>")
         return 0
     cmd = ' '.join(args[1:])
@@ -1854,23 +1854,23 @@
 
 def connectCmd(ctx, args):
-    if (len(args) > 4):
-        print "usage: connect url <username> <passwd>"
+    if len(args) > 4:
+        print("usage: connect url <username> <passwd>")
         return 0
 
     if ctx['vb'] is not None:
-        print "Already connected, disconnect first..."
-        return 0
-
-    if (len(args) > 1):
+        print("Already connected, disconnect first...")
+        return 0
+
+    if len(args) > 1:
         url = args[1]
     else:
         url = None
 
-    if (len(args) > 2):
+    if len(args) > 2:
         user = args[2]
     else:
         user = ""
 
-    if (len(args) > 3):
+    if len(args) > 3:
         passwd = args[3]
     else:
@@ -1881,6 +1881,6 @@
     ctx['vb'] = vbox
     try:
-        print "Running VirtualBox version %s" % (vbox.version)
-    except Exception, e:
+        print("Running VirtualBox version %s" % (vbox.version))
+    except Exception as e:
         printErr(ctx, e)
         if g_fVerbose:
@@ -1890,10 +1890,10 @@
 
 def disconnectCmd(ctx, args):
-    if (len(args) != 1):
-        print "usage: disconnect"
+    if len(args) != 1:
+        print("usage: disconnect")
         return 0
 
     if ctx['vb'] is None:
-        print "Not connected yet."
+        print("Not connected yet.")
         return 0
 
@@ -1909,5 +1909,5 @@
 def reconnectCmd(ctx, args):
     if ctx['wsinfo'] is None:
-        print "Never connected..."
+        print("Never connected...")
         return 0
 
@@ -1920,6 +1920,6 @@
     ctx['vb'] = ctx['global'].platform.connect(url, user, passwd)
     try:
-        print "Running VirtualBox version %s" % (ctx['vb'].version)
-    except Exception, e:
+        print("Running VirtualBox version %s" % (ctx['vb'].version))
+    except Exception as e:
         printErr(ctx, e)
         if g_fVerbose:
@@ -1929,5 +1929,5 @@
 def exportVMCmd(ctx, args):
     if len(args) < 3:
-        print "usage: exportVm <machine> <path> <format> <license>"
+        print("usage: exportVm <machine> <path> <format> <license>")
         return 0
     mach = argsToMach(ctx, args)
@@ -1935,9 +1935,9 @@
         return 0
     path = args[2]
-    if (len(args) > 3):
+    if len(args) > 3:
         fmt = args[3]
     else:
         fmt = "ovf-1.0"
-    if (len(args) > 4):
+    if len(args) > 4:
         lic = args[4]
     else:
@@ -1949,5 +1949,5 @@
     progress = app.write(fmt, path)
     if (progressBar(ctx, progress) and int(progress.resultCode) == 0):
-        print "Exported to %s in format %s" % (path, fmt)
+        print("Exported to %s in format %s" % (path, fmt))
     else:
         reportError(ctx, progress)
@@ -2053,5 +2053,5 @@
     extCode = extScancodes.get(ch, [])
     if len(extCode) == 0:
-        print "bad ext", ch
+        print("bad ext", ch)
     return extCode
 
@@ -2125,5 +2125,5 @@
 def typeGuestCmd(ctx, args):
     if len(args) < 3:
-        print "usage: typeGuest <machine> <text> <charDelay>"
+        print("usage: typeGuest <machine> <text> <charDelay>")
         return 0
     mach = argsToMach(ctx, args)
@@ -2161,29 +2161,29 @@
         verbose = False
     hdds = ctx['global'].getArray(ctx['vb'], 'hardDisks')
-    print colCat(ctx, "Hard disks:")
+    print(colCat(ctx, "Hard disks:"))
     for hdd in hdds:
         if hdd.state != ctx['global'].constants.MediumState_Created:
             hdd.refreshState()
-        print "   %s (%s)%s %s [logical %s]" % (colPath(ctx, hdd.location), hdd.format, optId(verbose, hdd.id), colSizeM(ctx, asSize(hdd.size, True)), colSizeM(ctx, asSize(hdd.logicalSize, True)))
+        print("   %s (%s)%s %s [logical %s]" % (colPath(ctx, hdd.location), hdd.format, optId(verbose, hdd.id), colSizeM(ctx, asSize(hdd.size, True)), colSizeM(ctx, asSize(hdd.logicalSize, True))))
 
     dvds = ctx['global'].getArray(ctx['vb'], 'DVDImages')
-    print colCat(ctx, "CD/DVD disks:")
+    print(colCat(ctx, "CD/DVD disks:"))
     for dvd in dvds:
         if dvd.state != ctx['global'].constants.MediumState_Created:
             dvd.refreshState()
-        print "   %s (%s)%s %s" % (colPath(ctx, dvd.location), dvd.format, optId(verbose, dvd.id), colSizeM(ctx, asSize(dvd.size, True)))
+        print("   %s (%s)%s %s" % (colPath(ctx, dvd.location), dvd.format, optId(verbose, dvd.id), colSizeM(ctx, asSize(dvd.size, True))))
 
     floppys = ctx['global'].getArray(ctx['vb'], 'floppyImages')
-    print colCat(ctx, "Floppy disks:")
+    print(colCat(ctx, "Floppy disks:"))
     for floppy in floppys:
         if floppy.state != ctx['global'].constants.MediumState_Created:
             floppy.refreshState()
-        print "   %s (%s)%s %s" % (colPath(ctx, floppy.location), floppy.format, optId(verbose, floppy.id), colSizeM(ctx, asSize(floppy.size, True)))
+        print("   %s (%s)%s %s" % (colPath(ctx, floppy.location), floppy.format, optId(verbose, floppy.id), colSizeM(ctx, asSize(floppy.size, True))))
 
     return 0
 
 def listUsbCmd(ctx, args):
-    if (len(args) > 1):
-        print "usage: listUsb"
+    if len(args) > 1:
+        print("usage: listUsb")
         return 0
 
@@ -2202,6 +2202,6 @@
 
 def createHddCmd(ctx, args):
-    if (len(args) < 3):
-        print "usage: createHdd sizeM location type"
+    if len(args) < 3:
+        print("usage: createHdd sizeM location type")
         return 0
 
@@ -2216,7 +2216,7 @@
     progress = hdd.createBaseStorage(size, (ctx['global'].constants.MediumVariant_Standard, ))
     if progressBar(ctx,progress) and hdd.id:
-        print "created HDD at %s as %s" % (colPath(ctx,hdd.location), hdd.id)
-    else:
-       print "cannot create disk (file %s exist?)" % (loc)
+        print("created HDD at %s as %s" % (colPath(ctx,hdd.location), hdd.id))
+    else:
+       print("cannot create disk (file %s exist?)" % (loc))
        reportError(ctx,progress)
        return 0
@@ -2225,6 +2225,6 @@
 
 def registerHddCmd(ctx, args):
-    if (len(args) < 2):
-        print "usage: registerHdd location"
+    if len(args) < 2:
+        print("usage: registerHdd location")
         return 0
 
@@ -2236,5 +2236,5 @@
     parentId = ""
     hdd = vbox.openMedium(loc, ctx['global'].constants.DeviceType_HardDisk, ctx['global'].constants.AccessMode_ReadWrite, False)
-    print "registered HDD as %s" % (hdd.id)
+    print("registered HDD as %s" % (hdd.id))
     return 0
 
@@ -2244,6 +2244,6 @@
 
 def attachHddCmd(ctx, args):
-    if (len(args) < 3):
-        print "usage: attachHdd vm hdd controller port:slot"
+    if len(args) < 3:
+        print("usage: attachHdd vm hdd controller port:slot")
         return 0
 
@@ -2256,5 +2256,5 @@
         hdd = vbox.openMedium(loc, ctx['global'].constants.DeviceType_HardDisk, ctx['global'].constants.AccessMode_ReadWrite, False)
     except:
-        print "no HDD with path %s registered" % (loc)
+        print("no HDD with path %s registered" % (loc))
         return 0
     if len(args) > 3:
@@ -2279,6 +2279,6 @@
 
 def detachHddCmd(ctx, args):
-    if (len(args) < 3):
-        print "usage: detachHdd vm hdd"
+    if len(args) < 3:
+        print("usage: detachHdd vm hdd")
         return 0
 
@@ -2291,5 +2291,5 @@
         hdd = vbox.openMedium(loc, ctx['global'].constants.DeviceType_HardDisk, ctx['global'].constants.AccessMode_ReadWrite, False)
     except:
-        print "no HDD with path %s registered" % (loc)
+        print("no HDD with path %s registered" % (loc))
         return 0
 
@@ -2298,11 +2298,11 @@
 
 def unregisterHddCmd(ctx, args):
-    if (len(args) < 2):
-        print "usage: unregisterHdd path <vmunreg>"
+    if len(args) < 2:
+        print("usage: unregisterHdd path <vmunreg>")
         return 0
 
     vbox = ctx['vb']
     loc = args[1]
-    if (len(args) > 2):
+    if len(args) > 2:
         vmunreg = int(args[2])
     else:
@@ -2311,5 +2311,5 @@
         hdd = vbox.openMedium(loc, ctx['global'].constants.DeviceType_HardDisk, ctx['global'].constants.AccessMode_ReadWrite, False)
     except:
-        print "no HDD with path %s registered" % (loc)
+        print("no HDD with path %s registered" % (loc))
         return 0
 
@@ -2318,8 +2318,8 @@
         try:
             for mach in machs:
-                print "Trying to detach from %s" % (mach)
+                print("Trying to detach from %s" % (mach))
                 detachMedium(ctx, mach, hdd)
-        except Exception, e:
-            print 'failed: ', e
+        except Exception as e:
+            print('failed: ', e)
             return 0
     hdd.close()
@@ -2327,6 +2327,6 @@
 
 def removeHddCmd(ctx, args):
-    if (len(args) != 2):
-        print "usage: removeHdd path"
+    if len(args) != 2:
+        print("usage: removeHdd path")
         return 0
 
@@ -2336,5 +2336,5 @@
         hdd = vbox.openMedium(loc, ctx['global'].constants.DeviceType_HardDisk, ctx['global'].constants.AccessMode_ReadWrite, False)
     except:
-        print "no HDD with path %s registered" % (loc)
+        print("no HDD with path %s registered" % (loc))
         return 0
 
@@ -2345,6 +2345,6 @@
 
 def registerIsoCmd(ctx, args):
-    if (len(args) < 2):
-        print "usage: registerIso location"
+    if len(args) < 2:
+        print("usage: registerIso location")
         return 0
 
@@ -2352,10 +2352,10 @@
     loc = args[1]
     iso = vbox.openMedium(loc, ctx['global'].constants.DeviceType_DVD, ctx['global'].constants.AccessMode_ReadOnly, False)
-    print "registered ISO as %s" % (iso.id)
+    print("registered ISO as %s" % (iso.id))
     return 0
 
 def unregisterIsoCmd(ctx, args):
-    if (len(args) != 2):
-        print "usage: unregisterIso path"
+    if len(args) != 2:
+        print("usage: unregisterIso path")
         return 0
 
@@ -2365,15 +2365,15 @@
         dvd = vbox.openMedium(loc, ctx['global'].constants.DeviceType_DVD, ctx['global'].constants.AccessMode_ReadOnly, False)
     except:
-        print "no DVD with path %s registered" % (loc)
+        print("no DVD with path %s registered" % (loc))
         return 0
 
     progress = dvd.close()
-    print "Unregistered ISO at %s" % (colPath(ctx, loc))
+    print("Unregistered ISO at %s" % (colPath(ctx, loc)))
 
     return 0
 
 def removeIsoCmd(ctx, args):
-    if (len(args) != 2):
-        print "usage: removeIso path"
+    if len(args) != 2:
+        print("usage: removeIso path")
         return 0
 
@@ -2383,10 +2383,10 @@
         dvd = vbox.openMedium(loc, ctx['global'].constants.DeviceType_DVD, ctx['global'].constants.AccessMode_ReadOnly, False)
     except:
-        print "no DVD with path %s registered" % (loc)
+        print("no DVD with path %s registered" % (loc))
         return 0
 
     progress = dvd.deleteStorage()
     if progressBar(ctx, progress):
-        print "Removed ISO at %s" % (colPath(ctx, dvd.location))
+        print("Removed ISO at %s" % (colPath(ctx, dvd.location)))
     else:
         reportError(ctx, progress)
@@ -2394,6 +2394,6 @@
 
 def attachIsoCmd(ctx, args):
-    if (len(args) < 3):
-        print "usage: attachIso vm iso controller port:slot"
+    if len(args) < 3:
+        print("usage: attachIso vm iso controller port:slot")
         return 0
 
@@ -2406,5 +2406,5 @@
         dvd = vbox.openMedium(loc, ctx['global'].constants.DeviceType_DVD, ctx['global'].constants.AccessMode_ReadOnly, False)
     except:
-        print "no DVD with path %s registered" % (loc)
+        print("no DVD with path %s registered" % (loc))
         return 0
     if len(args) > 3:
@@ -2417,6 +2417,6 @@
 
 def detachIsoCmd(ctx, args):
-    if (len(args) < 3):
-        print "usage: detachIso vm iso"
+    if len(args) < 3:
+        print("usage: detachIso vm iso")
         return 0
 
@@ -2429,5 +2429,5 @@
         dvd = vbox.openMedium(loc, ctx['global'].constants.DeviceType_DVD, ctx['global'].constants.AccessMode_ReadOnly, False)
     except:
-        print "no DVD with path %s registered" % (loc)
+        print("no DVD with path %s registered" % (loc))
         return 0
 
@@ -2436,6 +2436,6 @@
 
 def mountIsoCmd(ctx, args):
-    if (len(args) < 3):
-        print "usage: mountIso vm iso controller port:slot"
+    if len(args) < 3:
+        print("usage: mountIso vm iso controller port:slot")
         return 0
 
@@ -2448,5 +2448,5 @@
         dvd = vbox.openMedium(loc, ctx['global'].constants.DeviceType_DVD, ctx['global'].constants.AccessMode_ReadOnly, False)
     except:
-        print "no DVD with path %s registered" % (loc)
+        print("no DVD with path %s registered" % (loc))
         return 0
 
@@ -2463,6 +2463,6 @@
 
 def unmountIsoCmd(ctx, args):
-    if (len(args) < 2):
-        print "usage: unmountIso vm controller port:slot"
+    if len(args) < 2:
+        print("usage: unmountIso vm controller port:slot")
         return 0
 
@@ -2490,6 +2490,6 @@
 
 def attachCtrCmd(ctx, args):
-    if (len(args) < 4):
-        print "usage: attachCtr vm cname bus <type>"
+    if len(args) < 4:
+        print("usage: attachCtr vm cname bus <type>")
         return 0
 
@@ -2497,5 +2497,5 @@
         ctrltype = enumFromString(ctx, 'StorageControllerType', args[4])
         if ctrltype == None:
-            print "Controller type %s unknown" % (args[4])
+            print("Controller type %s unknown" % (args[4]))
             return 0
     else:
@@ -2507,5 +2507,5 @@
     bus = enumFromString(ctx, 'StorageBus', args[3])
     if bus is None:
-        print "Bus type %s unknown" % (args[3])
+        print("Bus type %s unknown" % (args[3]))
         return 0
     name = args[2]
@@ -2514,6 +2514,6 @@
 
 def detachCtrCmd(ctx, args):
-    if (len(args) < 3):
-        print "usage: detachCtr vm name"
+    if len(args) < 3:
+        print("usage: detachCtr vm name")
         return 0
 
@@ -2526,5 +2526,5 @@
 
 def usbctr(ctx, mach, console, args):
-    if (args[0]):
+    if args[0]:
         console.attachUSBDevice(args[1], "")
     else:
@@ -2532,6 +2532,6 @@
 
 def attachUsbCmd(ctx, args):
-    if (len(args) < 3):
-        print "usage: attachUsb vm deviceuid"
+    if len(args) < 3:
+        print("usage: attachUsb vm deviceuid")
         return 0
 
@@ -2544,6 +2544,6 @@
 
 def detachUsbCmd(ctx, args):
-    if (len(args) < 3):
-        print "usage: detachUsb vm deviceuid"
+    if len(args) < 3:
+        print("usage: detachUsb vm deviceuid")
         return 0
 
@@ -2557,6 +2557,6 @@
 
 def guiCmd(ctx, args):
-    if (len(args) > 1):
-        print "usage: gui"
+    if len(args) > 1:
+        print("usage: gui")
         return 0
 
@@ -2572,6 +2572,6 @@
 
 def shareFolderCmd(ctx, args):
-    if (len(args) < 4):
-        print "usage: shareFolder vm path name <writable> <persistent>"
+    if len(args) < 4:
+        print("usage: shareFolder vm path name <writable> <persistent>")
         return 0
 
@@ -2596,6 +2596,6 @@
 
 def unshareFolderCmd(ctx, args):
-    if (len(args) < 3):
-        print "usage: unshareFolder vm name"
+    if len(args) < 3:
+        print("usage: unshareFolder vm name")
         return 0
 
@@ -2617,7 +2617,7 @@
 def snapshotCmd(ctx, args):
     if (len(args) < 2 or args[1] == 'help'):
-        print "Take snapshot:    snapshot vm take name <description>"
-        print "Restore snapshot: snapshot vm restore name"
-        print "Merge snapshot:   snapshot vm merge name"
+        print("Take snapshot:    snapshot vm take name <description>")
+        print("Restore snapshot: snapshot vm restore name")
+        print("Merge snapshot:   snapshot vm merge name")
         return 0
 
@@ -2627,9 +2627,9 @@
     cmd = args[2]
     if cmd == 'take':
-        if (len(args) < 4):
-            print "usage: snapshot vm take name <description>"
+        if len(args) < 4:
+            print("usage: snapshot vm take name <description>")
             return 0
         name = args[3]
-        if (len(args) > 4):
+        if len(args) > 4:
             desc = args[4]
         else:
@@ -2639,6 +2639,6 @@
 
     if cmd == 'restore':
-        if (len(args) < 4):
-            print "usage: snapshot vm restore name"
+        if len(args) < 4:
+            print("usage: snapshot vm restore name")
             return 0
         name = args[3]
@@ -2648,6 +2648,6 @@
 
     if cmd == 'restorecurrent':
-        if (len(args) < 4):
-            print "usage: snapshot vm restorecurrent"
+        if len(args) < 4:
+            print("usage: snapshot vm restorecurrent")
             return 0
         snap = mach.currentSnapshot()
@@ -2656,6 +2656,6 @@
 
     if cmd == 'delete':
-        if (len(args) < 4):
-            print "usage: snapshot vm delete name"
+        if len(args) < 4:
+            print("usage: snapshot vm delete name")
             return 0
         name = args[3]
@@ -2664,5 +2664,5 @@
         return 0
 
-    print "Command '%s' is unknown" % (cmd)
+    print("Command '%s' is unknown" % (cmd))
     return 0
 
@@ -2683,5 +2683,5 @@
         first = 0
         msg = ''
-        for aliasmode, aliaskey in alias.iteritems():
+        for aliasmode, aliaskey in list(alias.items()):
             if first == 0:
                 first = 1
@@ -2689,8 +2689,7 @@
                 msg += ', '
             if int(nat.aliasMode) & aliaskey:
-                msg += '%d: %s' % (aliasmode, 'on')
+                msg += '%s: %s' % (aliasmode, 'on')
             else:
-                msg += '%d: %s' % (aliasmode, 'off')
-        msg += ')'
+                msg += '%s: %s' % (aliasmode, 'off')
         return (0, [msg])
     else:
@@ -2698,7 +2697,7 @@
         if 'default' not in args:
             for a in range(1, len(args)):
-                if not alias.has_key(args[a]):
-                    print 'Invalid alias mode: ' + args[a]
-                    print natAlias.__doc__
+                if args[a] not in alias:
+                    print('Invalid alias mode: ' + args[a])
+                    print(natAlias.__doc__)
                     return (1, None)
                 nat.aliasMode = int(nat.aliasMode) | alias[args[a]]
@@ -2723,9 +2722,9 @@
     else:
         if args[1] < 16000:
-            print 'invalid mtu value (%s not in range [65 - 16000])' % (args[1])
+            print('invalid mtu value (%s not in range [65 - 16000])' % (args[1]))
             return (1, None)
         for i in range(2, len(args)):
             if not args[i].isdigit() or int(args[i]) < 8 or int(args[i]) > 1024:
-                print 'invalid %s parameter (%i not in range [8-1024])' % (i, args[i])
+                print('invalid %s parameter (%i not in range [8-1024])' % (i, args[i]))
                 return (1, None)
         a = [args[1]]
@@ -2735,5 +2734,5 @@
         else:
             for i in range(2, len(args)): a.append(args[i])
-        #print a
+        #print(a)
         nat.setNetworkSettings(int(a[0]), int(a[1]), int(a[2]), int(a[3]), int(a[4]))
     return (0, None)
@@ -2786,6 +2785,6 @@
         cmd = args[1]
         if len(args) != 3:
-            print 'invalid args:', args
-            print natTftp.__doc__
+            print('invalid args:', args)
+            print(natTftp.__doc__)
             return (1, None)
         if cmd == 'prefix': nat.TFTPPrefix = args[2]
@@ -2793,5 +2792,5 @@
         elif cmd == 'server': nat.TFTPNextServer = args[2]
         else:
-            print "invalid cmd:", cmd
+            print("invalid cmd:", cmd)
             return (1, None)
     return (0, None)
@@ -2818,13 +2817,13 @@
         pfcmd = {
             'simple': {
-                'validate': lambda: args[1] in pfcmd.keys() and args[2] in proto.keys() and len(args) == 5,
+                'validate': lambda: args[1] in list(pfcmd.keys()) and args[2] in list(proto.keys()) and len(args) == 5,
                 'func':lambda: nat.addRedirect('', proto[args[2]], '', int(args[3]), '', int(args[4]))
             },
             'no_name': {
-                'validate': lambda: args[1] in pfcmd.keys() and args[2] in proto.keys() and len(args) == 7,
+                'validate': lambda: args[1] in list(pfcmd.keys()) and args[2] in list(proto.keys()) and len(args) == 7,
                 'func': lambda: nat.addRedirect('', proto[args[2]], args[3], int(args[4]), args[5], int(args[6]))
             },
             'ex': {
-                'validate': lambda: args[1] in pfcmd.keys() and args[2] in proto.keys() and len(args) == 8,
+                'validate': lambda: args[1] in list(pfcmd.keys()) and args[2] in list(proto.keys()) and len(args) == 8,
                 'func': lambda: nat.addRedirect(args[3], proto[args[2]], args[4], int(args[5]), args[6], int(args[7]))
             },
@@ -2836,6 +2835,6 @@
 
         if not pfcmd[args[1]]['validate']():
-            print 'invalid port-forwarding or args of sub command ', args[1]
-            print natPortForwarding.__doc__
+            print('invalid port-forwarding or args of sub command ', args[1])
+            print(natPortForwarding.__doc__)
             return (1, None)
 
@@ -2856,5 +2855,5 @@
         (addr, mask) = args[1].split('/')
         if addr.count('.') > 3 or int(mask) < 0 or int(mask) > 32:
-            print 'Invalid arguments'
+            print('Invalid arguments')
             return (1, None)
         nat.network = args[1]
@@ -2880,17 +2879,17 @@
     if len(args) < 2 or args[1] == 'help':
         if len(args) > 2:
-            print natcommands[args[2]].__doc__
+            print(natcommands[args[2]].__doc__)
         else:
-            print natCmd.__doc__
+            print(natCmd.__doc__)
         return 0
     if len(args) == 1 or len(args) < 4 or args[3] not in natcommands:
-        print natCmd.__doc__
+        print(natCmd.__doc__)
         return 0
     mach = ctx['argsToMach'](args)
     if mach == None:
-        print "please specify vm"
-        return 0
-    if len(args) < 3 or not args[2].isdigit() or int(args[2]) not in range(0, ctx['vb'].systemProperties.getMaxNetworkAdapters(mach.chipsetType)):
-        print 'please specify adapter num %d isn\'t in range [0-%d]' % (args[2], ctx['vb'].systemProperties.getMaxNetworkAdapters(mach.chipsetType))
+        print("please specify vm")
+        return 0
+    if len(args) < 3 or not args[2].isdigit() or int(args[2]) not in list(range(0, ctx['vb'].systemProperties.getMaxNetworkAdapters(mach.chipsetType))):
+        print('please specify adapter num %d isn\'t in range [0-%d]' % (args[2], ctx['vb'].systemProperties.getMaxNetworkAdapters(mach.chipsetType)))
         return 0
     nicnum = int(args[2])
@@ -2919,5 +2918,5 @@
         for r in report:
             msg ='%s nic%d %s: %s' % (mach.name, nicnum, func, r)
-            print msg
+            print(msg)
     return 0
 
@@ -2930,5 +2929,5 @@
         yesno = {'off' : 0, 'on' : 1}
         if args[1] not in yesno:
-            print '%s isn\'t acceptable, please choose %s' % (args[1], yesno.keys())
+            print('%s isn\'t acceptable, please choose %s' % (args[1], list(yesno.keys())))
             return (1, None)
         adapter.__setattr__(attr, yesno[args[1]])
@@ -2953,6 +2952,6 @@
     else:
         if not args[1].isdigit():
-            print '%s isn\'t a number' % (args[1])
-            print (1, None)
+            print('%s isn\'t a number' % (args[1]))
+            return (1, None)
         adapter.lineSpeed = int(args[1])
     return (0, None)
@@ -2976,5 +2975,5 @@
     if len(args) == 1:
         nictypes = ctx['const'].all_values('NetworkAdapterType')
-        for key in nictypes.keys():
+        for key in list(nictypes.keys()):
             if str(adapter.adapterType) == str(nictypes[key]):
                 return (0, str(key))
@@ -2982,6 +2981,6 @@
     else:
         nictypes = ctx['const'].all_values('NetworkAdapterType')
-        if args[1] not in nictypes.keys():
-            print '%s not in acceptable values (%s)' % (args[1], nictypes.keys())
+        if args[1] not in list(nictypes.keys()):
+            print('%s not in acceptable values (%s)' % (args[1], list(nictypes.keys())))
             return (1, None)
         adapter.adapterType = nictypes[args[1]]
@@ -3002,6 +3001,5 @@
             ctx['global'].constants.NetworkAttachmentType_Generic: ('Generic', ''),
         }
-        import types
-        if type(adapter.attachmentType) != types.IntType:
+        if type(adapter.attachmentType) != int:
             t = str(adapter.attachmentType)
         else:
@@ -3037,9 +3035,9 @@
                 'f': lambda: ctx['global'].constants.NetworkAttachmentType_Generic}
         }
-        if args[1] not in nicAttachmentType.keys():
-            print '%s not in acceptable values (%s)' % (args[1], nicAttachmentType.keys())
+        if args[1] not in list(nicAttachmentType.keys()):
+            print('%s not in acceptable values (%s)' % (args[1], list(nicAttachmentType.keys())))
             return (1, None)
         if not nicAttachmentType[args[1]]['v']():
-            print nicAttachmentType.__doc__
+            print(nicAttachmentType.__doc__)
             return (1, None)
         nicAttachmentType[args[1]]['p']()
@@ -3067,17 +3065,17 @@
         if len(args) == 3 \
            and args[2] in niccomand:
-            print niccomand[args[2]].__doc__
+            print(niccomand[args[2]].__doc__)
         else:
-            print nicCmd.__doc__
+            print(nicCmd.__doc__)
         return 0
 
     vm = ctx['argsToMach'](args)
     if vm is None:
-        print 'please specify vm'
+        print('please specify vm')
         return 0
 
     if    len(args) < 3 \
-       or int(args[2]) not in range(0, ctx['vb'].systemProperties.getMaxNetworkAdapters(vm.chipsetType)):
-        print 'please specify adapter num %d isn\'t in range [0-%d]'% (args[2], ctx['vb'].systemProperties.getMaxNetworkAdapters(vm.chipsetType))
+       or int(args[2]) not in list(range(0, ctx['vb'].systemProperties.getMaxNetworkAdapters(vm.chipsetType))):
+        print('please specify adapter num %d isn\'t in range [0-%d]'% (args[2], ctx['vb'].systemProperties.getMaxNetworkAdapters(vm.chipsetType)))
         return 0
     nicnum = int(args[2])
@@ -3092,5 +3090,5 @@
         vm.saveSettings()
     if report is not None:
-        print '%s nic %d %s: %s' % (vm.name, nicnum, args[3], report)
+        print('%s nic %d %s: %s' % (vm.name, nicnum, args[3], report))
     session.unlockMachine()
     return 0
@@ -3099,5 +3097,5 @@
 def promptCmd(ctx, args):
     if    len(args) < 2:
-        print "Current prompt: '%s'" % (ctx['prompt'])
+        print("Current prompt: '%s'" % (ctx['prompt']))
         return 0
 
@@ -3107,5 +3105,5 @@
 def foreachCmd(ctx, args):
     if len(args) < 3:
-        print "usage: foreach scope command, where scope is XPath-like expression //vms/vm[@CPUCount='2']"
+        print("usage: foreach scope command, where scope is XPath-like expression //vms/vm[@CPUCount='2']")
         return 0
 
@@ -3117,5 +3115,5 @@
             e.apply(cmd)
     except:
-        print "Error executing"
+        print("Error executing")
         traceback.print_exc()
     return 0
@@ -3123,5 +3121,5 @@
 def foreachvmCmd(ctx, args):
     if len(args) < 2:
-        print "foreachvm command <args>"
+        print("foreachvm command <args>")
         return 0
     cmdargs = args[1:]
@@ -3133,6 +3131,6 @@
 
 def recordDemoCmd(ctx, args):
-    if (len(args) < 3):
-        print "usage: recordDemo vm filename (duration)"
+    if len(args) < 3:
+        print("usage: recordDemo vm filename (duration)")
         return 0
     mach = argsToMach(ctx, args)
@@ -3147,6 +3145,6 @@
 
 def playbackDemoCmd(ctx, args):
-    if (len(args) < 3):
-        print "usage: playbackDemo vm filename (duration)"
+    if len(args) < 3:
+        print("usage: playbackDemo vm filename (duration)")
         return 0
     mach = argsToMach(ctx, args)
@@ -3169,12 +3167,12 @@
     for a in assigned:
         if a.isPhysicalDevice:
-            print "%s: assigned host device %s guest %s" % (colDev(ctx, a.name), pciAddr(ctx, a.hostAddress), pciAddr(ctx, a.guestAddress))
+            print("%s: assigned host device %s guest %s" % (colDev(ctx, a.name), pciAddr(ctx, a.hostAddress), pciAddr(ctx, a.guestAddress)))
 
     atts = ctx['global'].getArray(console, 'attachedPCIDevices')
     for a in atts:
         if a.isPhysicalDevice:
-            print "%s: physical, guest %s, host %s" % (colDev(ctx, a.name), pciAddr(ctx, a.guestAddress), pciAddr(ctx, a.hostAddress))
+            print("%s: physical, guest %s, host %s" % (colDev(ctx, a.name), pciAddr(ctx, a.guestAddress), pciAddr(ctx, a.hostAddress)))
         else:
-            print "%s: virtual, guest %s" % (colDev(ctx, a.name), pciAddr(ctx, a.guestAddress))
+            print("%s: virtual, guest %s" % (colDev(ctx, a.name), pciAddr(ctx, a.guestAddress)))
     return
 
@@ -3188,6 +3186,6 @@
 
 def lspciCmd(ctx, args):
-    if (len(args) < 2):
-        print "usage: lspci vm"
+    if len(args) < 2:
+        print("usage: lspci vm")
         return 0
     mach = argsToMach(ctx, args)
@@ -3198,6 +3196,6 @@
 
 def attachpciCmd(ctx, args):
-    if (len(args) < 3):
-        print "usage: attachpci vm hostpci <guestpci>"
+    if len(args) < 3:
+        print("usage: attachpci vm hostpci <guestpci>")
         return 0
     mach = argsToMach(ctx, args)
@@ -3206,11 +3204,11 @@
     hostaddr = parsePci(args[2])
     if hostaddr == -1:
-        print "invalid host PCI %s, accepted format 01:02.3 for bus 1, device 2, function 3" % (args[2])
-        return 0
-
-    if (len(args) > 3):
+        print("invalid host PCI %s, accepted format 01:02.3 for bus 1, device 2, function 3" % (args[2]))
+        return 0
+
+    if len(args) > 3:
         guestaddr = parsePci(args[3])
         if guestaddr == -1:
-            print "invalid guest PCI %s, accepted format 01:02.3 for bus 1, device 2, function 3" % (args[3])
+            print("invalid guest PCI %s, accepted format 01:02.3 for bus 1, device 2, function 3" % (args[3]))
             return 0
     else:
@@ -3220,6 +3218,6 @@
 
 def detachpciCmd(ctx, args):
-    if (len(args) < 3):
-        print "usage: detachpci vm hostpci"
+    if len(args) < 3:
+        print("usage: detachpci vm hostpci")
         return 0
     mach = argsToMach(ctx, args)
@@ -3228,5 +3226,5 @@
     hostaddr = parsePci(args[2])
     if hostaddr == -1:
-        print "invalid host PCI %s, accepted format 01:02.3 for bus 1, device 2, function 3" % (args[2])
+        print("invalid host PCI %s, accepted format 01:02.3 for bus 1, device 2, function 3" % (args[2]))
         return 0
 
@@ -3235,6 +3233,6 @@
 
 def gotoCmd(ctx, args):
-    if (len(args) < 2):
-        print "usage: goto line"
+    if len(args) < 2:
+        print("usage: goto line")
         return 0
 
@@ -3273,5 +3271,5 @@
             'verbose':['Toggle verbosity', verboseCmd, 0],
             'setvar':['Set VMs variable: setvar Fedora BIOSSettings.ACPIEnabled True', setvarCmd, 0],
-            'eval':['Evaluate arbitrary Python construction: eval \'for m in getMachines(ctx): print m.name, "has", m.memorySize, "M"\'', evalCmd, 0],
+            'eval':['Evaluate arbitrary Python construction: eval \'for m in getMachines(ctx): print(m.name, "has", m.memorySize, "M")\'', evalCmd, 0],
             'quit':['Exits', quitCmd, 0],
             'host':['Show host information', hostCmd, 0],
@@ -3329,5 +3327,5 @@
             'prompt' : ['Control shell prompt', promptCmd, 0],
             'foreachvm' : ['Perform command for each VM', foreachvmCmd, 0],
-            'foreach' : ['Generic "for each" construction, using XPath-like notation: foreach //vms/vm[@OSTypeId=\'MacOS\'] "print obj.name"', foreachCmd, 0],
+            'foreach' : ['Generic "for each" construction, using XPath-like notation: foreach //vms/vm[@OSTypeId=\'MacOS\'] "print(obj.name)"', foreachCmd, 0],
             'recordDemo':['Record demo: recordDemo Win32 file.dmo 10', recordDemoCmd, 0],
             'playbackDemo':['Playback demo: playbackDemo Win32 file.dmo 10', playbackDemoCmd, 0],
@@ -3344,9 +3342,9 @@
     ci = commands.get(c, None)
     if ci == None:
-        print "Unknown command: '%s', type 'help' for list of known commands" % (c)
+        print("Unknown command: '%s', type 'help' for list of known commands" % (c))
         return 0
     if ctx['remote'] and ctx['vb'] is None:
         if c not in ['connect', 'reconnect', 'help', 'quit']:
-            print "First connect to remote server with %s command." % (colored('connect', 'blue'))
+            print("First connect to remote server with %s command." % (colored('connect', 'blue')))
             return 0
     return ci[1](ctx, args)
@@ -3354,5 +3352,5 @@
 
 def runCommand(ctx, cmd):
-    if len(cmd) == 0: return 0
+    if not cmd: return 0
     args = split_no_quotes(cmd)
     if len(args) == 0: return 0
@@ -3364,5 +3362,5 @@
 #
 # def runTestCmd(ctx, args):
-#    print "Testy test", ctx['vb']
+#    print("Testy test", ctx['vb'])
 #    return 0
 #
@@ -3381,11 +3379,11 @@
     d = {}
     try:
-        execfile(filename, d, d)
-        for (k, v) in d['commands'].items():
+        exec(compile(open(filename).read(), filename, 'exec'), d, d)
+        for (k, v) in list(d['commands'].items()):
             if g_fVerbose:
-                print "customize: adding \"%s\" - %s" % (k, v[0])
+                print("customize: adding \"%s\" - %s" % (k, v[0]))
             cmds[k] = [v[0], v[1], filename]
     except:
-        print "Error loading user extensions from %s" % (filename)
+        print("Error loading user extensions from %s" % (filename))
         traceback.print_exc()
 
@@ -3423,6 +3421,6 @@
     if vbox is not None:
         try:
-            print "Running VirtualBox version %s" % (vbox.version)
-        except Exception, e:
+            print("Running VirtualBox version %s" % (vbox.version))
+        except Exception as e:
             printErr(ctx, e)
             if g_fVerbose:
@@ -3461,7 +3459,10 @@
                 cmd = 'runScript %s'% (g_sScriptFile)
             elif g_sCmd is not None:
-                cmd = it.next()
+                cmd = next(it)
             else:
-                cmd = raw_input(ctx['prompt'])
+                if sys.version_info[0] <= 2:
+                    cmd = raw_input(ctx['prompt'])
+                else:
+                    cmd = input(ctx['prompt'])
             done = runCommand(ctx, cmd)
             if done != 0: break
@@ -3469,10 +3470,10 @@
                 break
         except KeyboardInterrupt:
-            print '====== You can type quit or q to leave'
+            print('====== You can type quit or q to leave')
         except StopIteration:
             break
         except EOFError:
             break
-        except Exception, e:
+        except Exception as e:
             printErr(ctx, e)
             if g_fVerbose:
@@ -3536,11 +3537,11 @@
 
     if options.autopath:
-        asLocations = [ os.getcwd(), ];
-        try:    sScriptDir = os.path.dirname(os.path.abspath(__file__));
+        asLocations = [ os.getcwd(), ]
+        try:    sScriptDir = os.path.dirname(os.path.abspath(__file__))
         except: pass; # In case __file__ isn't there.
         else:
             if platform.system() in [ 'SunOS', ]:
-                asLocations.append(os.path.join(sScriptDir, 'amd64'));
-            asLocations.append(sScriptDir);
+                asLocations.append(os.path.join(sScriptDir, 'amd64'))
+            asLocations.append(sScriptDir)
 
 
@@ -3550,8 +3551,8 @@
                 if   os.path.isfile(os.path.join(sCurLoc, "VirtualBox")) \
                   or os.path.isfile(os.path.join(sCurLoc, "VirtualBox.exe")):
-                    print "Autodetected VBOX_PROGRAM_PATH as", sCurLoc
+                    print("Autodetected VBOX_PROGRAM_PATH as", sCurLoc)
                     os.environ["VBOX_PROGRAM_PATH"] = sCurLoc
                     sPath = sCurLoc
-                    break;
+                    break
         if sPath:
             sys.path.append(os.path.join(sPath, "sdk", "installer"))
@@ -3561,15 +3562,15 @@
             for sCurLoc in asLocations:
                 if os.path.isfile(os.path.join(sCurLoc, "sdk", "bindings", "VirtualBox.xidl")):
-                    sCurLoc = os.path.join(sCurLoc, "sdk");
-                    print "Autodetected VBOX_SDK_PATH as", sCurLoc
+                    sCurLoc = os.path.join(sCurLoc, "sdk")
+                    print("Autodetected VBOX_SDK_PATH as", sCurLoc)
                     os.environ["VBOX_SDK_PATH"] = sCurLoc
-                    sPath = sCurLoc;
-                    break;
+                    sPath = sCurLoc
+                    break
         if sPath:
-            sTmp = os.path.join(sCurLoc, 'sdk', 'bindings', 'xpcom', 'python');
+            sTmp = os.path.join(sCurLoc, 'bindings', 'xpcom', 'python')
             if os.path.isdir(sTmp):
-                sys.path.append(sTmp);
-            del sTmp;
-        del sPath, asLocations;
+                sys.path.append(sTmp)
+            del sTmp
+        del sPath, asLocations
 
 
