Index: src/mlx/fsuipc.py
===================================================================
--- src/mlx/fsuipc.py	(revision 1015)
+++ src/mlx/fsuipc.py	(revision 1017)
@@ -1,8 +1,8 @@
 
-from . import fs
-from . import const
-from . import util
-from . import acft
-from .watchdog import Watchdog
+import fs
+import const
+import util
+import acft
+from watchdog import Watchdog
 
 import threading
@@ -13,10 +13,9 @@
 import codecs
 import math
-from functools import total_ordering
 
 if os.name == "nt" and "FORCE_PYUIPC_SIM" not in os.environ:
     import pyuipc
 else:
-    from . import pyuipc_sim as pyuipc
+    import pyuipc_sim as pyuipc
 
 #------------------------------------------------------------------------------
@@ -105,6 +104,6 @@
         try:
             return fun()
-        except Exception as e:
-            print(util.utf2unicode(str(e)), file=sys.stderr)
+        except Exception, e:
+            print >> sys.stderr, util.utf2unicode(str(e))
             return None
 
@@ -134,5 +133,5 @@
             try:
                 values = pyuipc.read(data)
-            except TypeError as e:
+            except TypeError, e:
                 exception = e
 
@@ -175,5 +174,5 @@
                 try:
                     pyuipc.write(self._data)
-                except TypeError as e:
+                except TypeError, e:
                     exception = e
 
@@ -198,5 +197,4 @@
                 Handler._callSafe(lambda: self._callback(None, self._extra))
 
-    @total_ordering
     class PeriodicRequest(object):
         """A periodic request."""
@@ -252,15 +250,8 @@
             pass
 
-        def __eq__(self, other):
-            """Equality comparison by the firing times"""
-            return self._nextFire == other._nextFire
-
-        def __ne__(self, other):
-            """Non-equality comparison by the firing times"""
-            return self._nextFire != other._nextFire
-
-        def __lt__(self, other):
-            """Less-than comparison by the firing times"""
-            return self._nextFire < other._nextFire
+        def __cmp__(self, other):
+            """Compare two periodic requests. They are ordered by their next
+            firing times."""
+            return cmp(self._nextFire, other._nextFire)
 
     def __init__(self, connectionListener,
@@ -429,8 +420,8 @@
                 self._connected = True
                 return attempts
-            except Exception as e:
-                print("fsuipc.Handler._connect: connection failed: " + \
+            except Exception, e:
+                print "fsuipc.Handler._connect: connection failed: " + \
                       util.utf2unicode(str(e)) + \
-                      " (attempts: %d)" % (attempts,))
+                      " (attempts: %d)" % (attempts,)
                 if attempts<self.NUM_CONNECTATTEMPTS:
                     time.sleep(self.CONNECT_INTERVAL)
@@ -463,5 +454,5 @@
     def _disconnect(self):
         """Disconnect from the flight simulator."""
-        print("fsuipc.Handler._disconnect")
+        print "fsuipc.Handler._disconnect"
         if self._connected:
             pyuipc.close()
@@ -488,16 +479,16 @@
             try:
                 if not request.process(time):
-                    print("fsuipc.Handler._processRequest: FSUIPC returned invalid data too many times, reconnecting")
+                    print "fsuipc.Handler._processRequest: FSUIPC returned invalid data too many times, reconnecting"
                     needReconnect = True
             except TypeError as e:
-                print("fsuipc.Handler._processRequest: type error: " + \
+                print "fsuipc.Handler._processRequest: type error: " + \
                       util.utf2unicode(str(e)) + \
                       ("." if request.unimportant else
-                       (", reconnecting (attempts=%d)." % (attempts,))))
+                       (", reconnecting (attempts=%d)." % (attempts,)))
                 needReconnect = not request.unimportant
             except Exception as e:
-                print("fsuipc.Handler._processRequest: FSUIPC connection failed (" + \
+                print "fsuipc.Handler._processRequest: FSUIPC connection failed (" + \
                       util.utf2unicode(str(e)) + \
-                      "), reconnecting (attempts=%d)." % (attempts,))
+                      "), reconnecting (attempts=%d)." % (attempts,)
                 needReconnect = True
 
@@ -657,4 +648,5 @@
         self._hotkeyCallback = None
 
+        self._latin1decoder = codecs.getdecoder("iso-8859-1")
         self._fuelCallback = None
 
@@ -731,5 +723,5 @@
         duration is the number of seconds to keep the message displayed."""
 
-        print("fsuipc.Simulator.sendMessage:", message)
+        print "fsuipc.Simulator.sendMessage:", message
 
         if self._scroll:
@@ -739,7 +731,7 @@
 
         try:
-            message = bytes(str(message), "iso-8859-1")
-        except Exception as e:
-            print("fsuipc.Simulator.sendMessage: failed to convert the message to a string:", e)
+            message = str(message)
+        except Exception, e:
+            print "fsuipc.Simulator.sendMessage: failed to convert the message to a string:", e
 
         data = [(0x3380, -1 - len(message), message),
@@ -830,5 +822,5 @@
         assert not self._monitoringRequested
 
-        print("fsuipc.Simulator.disconnect", closingMessage, duration)
+        print "fsuipc.Simulator.disconnect", closingMessage, duration
 
         self._stopNormal()
@@ -895,8 +887,5 @@
         timestamp = Simulator._getTimestamp(data)
 
-        aircraftName = str(data[5], "iso-8859-1")
-        aircraftPath = str(data[6], "iso-8859-1")
-
-        createdNewModel = self._setAircraftName(timestamp, aircraftName, aircraftPath)
+        createdNewModel = self._setAircraftName(timestamp, data[5], data[6])
         if self._fuelCallback is not None:
             self._aircraftModel.getFuel(self._handler, self._fuelCallback)
@@ -957,10 +946,13 @@
 
         Return if a new model was created."""
+        name = self._latin1decoder(name)[0]
+        airPath = self._latin1decoder(airPath)[0]
+
         aircraftName = (name, airPath)
         if aircraftName==self._aircraftName:
             return False
 
-        print("fsuipc.Simulator: new aircraft name and air file path: %s, %s" % \
-              (name, airPath))
+        print "fsuipc.Simulator: new aircraft name and air file path: %s, %s" % \
+              (name, airPath)
 
         self._aircraftName = aircraftName
@@ -1096,14 +1088,13 @@
             self._handler.disconnect()
 
-    def _handleNumHotkeys(self, data, hotkeySet):
+    def _handleNumHotkeys(self, data, (id, generation)):
         """Handle the result of the query of the number of hotkeys"""
-        (id, generation) = hotkeySet
         with self._hotkeyLock:
             if id==self._hotkeySetID and generation==self._hotkeySetGeneration:
                 numHotkeys = data[0]
-                print("fsuipc.Simulator._handleNumHotkeys: numHotkeys:", numHotkeys)
+                print "fsuipc.Simulator._handleNumHotkeys: numHotkeys:", numHotkeys
                 data = [(0x3210 + i*4, "d") for i in range(0, numHotkeys)]
                 self._handler.requestRead(data, self._handleHotkeyTable,
-                                          hotkeySet)
+                                          (id, generation))
 
     def _setupHotkeys(self, data):
@@ -1144,11 +1135,10 @@
 
         for offset in oldHotkeyOffsets:
-            writeData.append((offset, "u", int(0)))
+            writeData.append((offset, "u", long(0)))
 
         return writeData
 
-    def _handleHotkeyTable(self, data, hotkeySet):
+    def _handleHotkeyTable(self, data, (id, generation)):
         """Handle the result of the query of the hotkey table."""
-        (id, generation) = hotkeySet
         with self._hotkeyLock:
             if id==self._hotkeySetID and generation==self._hotkeySetGeneration:
@@ -1156,9 +1146,8 @@
                 self._handler.requestWrite(writeData,
                                            self._handleHotkeysWritten,
-                                           hotkeySet)
-
-    def _handleHotkeysWritten(self, success, hotkeySet):
+                                           (id, generation))
+
+    def _handleHotkeysWritten(self, success, (id, generation)):
         """Handle the result of the hotkeys having been written."""
-        (id, generation) = hotkeySet
         with self._hotkeyLock:
             if success and id==self._hotkeySetID and \
@@ -1169,9 +1158,8 @@
                     self._handler.requestPeriodicRead(0.5, data,
                                                       self._handleHotkeys,
-                                                      hotkeySet)
-
-    def _handleHotkeys(self, data, hotkeySet):
+                                                      (id, generation))
+
+    def _handleHotkeys(self, data, (id, generation)):
         """Handle the hotkeys."""
-        (id, generation) = hotkeySet
         with self._hotkeyLock:
             if id!=self._hotkeySetID or generation!=self._hotkeySetGeneration:
@@ -1409,7 +1397,7 @@
 
         numNotchesM1 = len(self._flapsNotches) - 1
-        flapsIncrement = 16383 // numNotchesM1
+        flapsIncrement = 16383 / numNotchesM1
         flapsControl = data[self._monidx_flapsControl]
-        flapsIndex = flapsControl // flapsIncrement
+        flapsIndex = flapsControl / flapsIncrement
         if flapsIndex < numNotchesM1:
             if (flapsControl - (flapsIndex*flapsIncrement) >
@@ -1418,8 +1406,8 @@
         state.flapsSet = self._flapsNotches[flapsIndex]
         if state.flapsSet != self._flapsSet:
-            print("flapsControl: %d, flapsLeft: %d, flapsRight: %d, flapsAxis: %d, flapsIncrement: %d, flapsSet: %d, numNotchesM1: %d" % \
+            print "flapsControl: %d, flapsLeft: %d, flapsRight: %d, flapsAxis: %d, flapsIncrement: %d, flapsSet: %d, numNotchesM1: %d" % \
                   (flapsControl, data[self._monidx_flapsLeft],
                    data[self._monidx_flapsRight], data[self._monidx_flapsAxis],
-                   data[self._monidx_flapsIncrement], state.flapsSet, numNotchesM1))
+                   data[self._monidx_flapsIncrement], state.flapsSet, numNotchesM1)
             self._flapsSet = state.flapsSet
 
@@ -1600,5 +1588,5 @@
         for (tank, level) in levels:
             offset = _tank2offset[tank]
-            value = int(level * 128.0 * 65536.0)
+            value = long(level * 128.0 * 65536.0)
             data.append( (offset, "u", value) )
 
@@ -1710,8 +1698,7 @@
     """A model handler for the PMDG Boeing 737NG model."""
     @staticmethod
-    def doesHandle(aircraft, aircraftName):
+    def doesHandle(aircraft, (name, airPath)):
         """Determine if this model handler handles the aircraft with the given
         name."""
-        (name, airPath) = aircraftName
         return aircraft.type in [const.AIRCRAFT_B736,
                                  const.AIRCRAFT_B737,
@@ -1743,6 +1730,6 @@
 
         if fsType==const.SIM_MSFSX or fsType==const.SIM_P3D:
-            print("%s detected, adding PMDG 737 NGX-specific offsets" % \
-                  ("FSX" if fsType==const.SIM_MSFSX else "P3D",))
+            print "%s detected, adding PMDG 737 NGX-specific offsets" % \
+                  ("FSX" if fsType==const.SIM_MSFSX else "P3D",)
             self._addOffsetWithIndexMember(data, 0x6500, "b",
                                            "_pmdgidx_lts_positionsw")
@@ -1754,5 +1741,5 @@
             self._addOffsetWithIndexMember(data, 0x65cd, "b", "_pmdgidx_xpdr")
         else:
-            print("FS9 detected, adding PMDG 737 NG-specific offsets")
+            print "FS9 detected, adding PMDG 737 NG-specific offsets"
             self._addOffsetWithIndexMember(data, 0x6202, "b", "_pmdgidx_switches")
             self._addOffsetWithIndexMember(data, 0x6216, "b", "_pmdgidx_xpdr")
@@ -1794,4 +1781,5 @@
         state.apHeading = data[self._pmdgidx_aphdg]
         state.apAltitude = data[self._pmdgidx_apalt]
+        state.elevatorTrim += 5.0
 
         gearControl = data[self._monidx_gearControl]
@@ -1799,5 +1787,5 @@
 
         if gearControl!=self._lastGearControl or noseGear!=self._lastNoseGear:
-            print("gearControl:", gearControl, " noseGear:", noseGear)
+            print "gearControl:", gearControl, " noseGear:", noseGear
             self._lastGearControl = gearControl
             self._lastNoseGear = noseGear
@@ -1846,8 +1834,7 @@
     """Model handler for the Dreamwings Dash 8-Q400."""
     @staticmethod
-    def doesHandle(aircraft, aircraftName):
+    def doesHandle(aircraft, (name, airPath)):
         """Determine if this model handler handles the aircraft with the given
         name."""
-        (name, airPath) = aircraftName
         return aircraft.type==const.AIRCRAFT_DH8D and \
             (name.find("Dreamwings")!=-1 or airPath.find("Dreamwings")!=-1) and \
@@ -1884,8 +1871,7 @@
     """Model handler for the Majestic Dash 8-Q400."""
     @staticmethod
-    def doesHandle(aircraft, aircraftName):
+    def doesHandle(aircraft, (name, airPath)):
         """Determine if this model handler handles the aircraft with the given
         name."""
-        (name, airPath) = aircraftName
         return aircraft.type==const.AIRCRAFT_DH8D and \
             (name.find("MJC8Q400")!=-1 or \
@@ -1963,8 +1949,7 @@
     """Model for the Digital Aviation F70 implementation on FS9."""
     @staticmethod
-    def doesHandle(aircraft, aircraftName):
+    def doesHandle(aircraft, (name, airPath)):
         """Determine if this model handler handles the aircraft with the given
         name."""
-        (name, airPath) = aircraftName
         return aircraft.type == const.AIRCRAFT_F70 and \
                (airPath.endswith("fokker70_2k4_v4.1.air") or
@@ -2153,9 +2138,8 @@
     """Project Tupolev Tu-154."""
     @staticmethod
-    def doesHandle(aircraft, aircraftName):
+    def doesHandle(aircraft, (name, airPath)):
         """Determine if this model handler handles the aircraft with the given
         name."""
-        (name, airPath) = aircraftName
-        print("PTT154Model.doesHandle", aircraft.type, name, airPath)
+        print "PTT154Model.doesHandle", aircraft.type, name, airPath
         return aircraft.type==const.AIRCRAFT_T154 and \
                (name.find("Tu-154")!=-1 or name.find("Tu154B")!=-1) and \
