Index: src/mlx/web.py
===================================================================
--- src/mlx/web.py	(revision 908)
+++ src/mlx/web.py	(revision 919)
@@ -1,16 +1,16 @@
 
-import const
-import util
-from rpc import Registration
-import rpc
-import rpccommon
-
-from common import MAVA_BASE_URL
-from pirep import PIREP
+from . import const
+from . import util
+from .rpc import Registration
+from . import rpc
+from . import rpccommon
+
+from .common import MAVA_BASE_URL
+from .pirep import PIREP
 
 import threading
 import sys
-import urllib
-import urllib2
+import urllib.request, urllib.parse, urllib.error
+import urllib.request, urllib.error, urllib.parse
 import hashlib
 import time
@@ -19,6 +19,6 @@
 import traceback
 import xml.sax
-import xmlrpclib
-import HTMLParser
+import xmlrpc.client
+import html.parser
 
 #---------------------------------------------------------------------------------------
@@ -73,6 +73,5 @@
                       "TU5"  : const.AIRCRAFT_T154,
                       "YK4"  : const.AIRCRAFT_YK40,
-                      "146"  : const.AIRCRAFT_B462,
-                      "IL6"  : const.AIRCRAFT_IL62 }
+                      "146"  : const.AIRCRAFT_B462 }
 
     TYPE2TYPECODE = { const.AIRCRAFT_B736  : "736",
@@ -93,6 +92,5 @@
                       const.AIRCRAFT_T154  : "TU5",
                       const.AIRCRAFT_YK40  : "YK4",
-                      const.AIRCRAFT_B462  : "146",
-                      const.AIRCRAFT_IL62  : "IL6" }
+                      const.AIRCRAFT_B462  : "146" }
 
     checkFlightTypes = [ const.AIRCRAFT_B736, const.AIRCRAFT_B737,
@@ -130,6 +128,4 @@
 
         flight.numPassengers = 0
-        flight.numCockpitCrew = 2
-        flight.numCabinCrew = 2
         flight.numCrew = 2
         flight.bagWeight = 0
@@ -164,5 +160,5 @@
 
         date = readline(f)
-        print "web.BookedFlight.readFromWeb: date:", date
+        print("web.BookedFlight.readFromWeb: date:", date)
         if date=="0000-00-00": date = "0001-01-01"
 
@@ -237,6 +233,6 @@
 
                 if not lineOK:
-                    print "web.BookedFlight.readFromFile: line %d is invalid" % \
-                          (lineNumber,)
+                    print("web.BookedFlight.readFromFile: line %d is invalid" % \
+                          (lineNumber,))
 
             line = f.readline()
@@ -250,11 +246,8 @@
                                                             arrivalTime)
 
-        self.numCockpitCrew = self.numCrew
-        self.numCabinCrew = 0
-
         d = dir(self)
         for attribute in ["callsign", "departureICAO", "arrivalICAO",
-                          "aircraftType", "tailNumber", "numPassengers",
-                          "numCrew", "numCockpitCrew", "numCabinCrew",
+                          "aircraftType", "tailNumber",
+                          "numPassengers", "numCrew",
                           "bagWeight", "cargoWeight", "mailWeight",
                           "route", "departureTime", "arrivalTime"]:
@@ -286,10 +279,8 @@
 
         self.aircraftType = \
-          self._decodeAircraftICAOType(bookedFlightData["aircraftType"])
+          self._decodeAircraftType(bookedFlightData["aircraftType"])
         self.tailNumber = bookedFlightData["tailNumber"]
         self.numPassengers = int(bookedFlightData["numPassengers"])
-        self.numCockpitCrew = int(bookedFlightData["numCockpitCrew"])
-        self.numCabinCrew = int(bookedFlightData["numCabinCrew"])
-        self.numCrew = self.numCockpitCrew + self.numCabinCrew
+        self.numCrew = int(bookedFlightData["numCrew"])
         self.bagWeight = int(bookedFlightData["bagWeight"])
         self.cargoWeight = int(bookedFlightData["cargoWeight"])
@@ -299,26 +290,26 @@
     def writeIntoFile(self, f):
         """Write the flight into a file."""
-        print >> f, "callsign=%s" % (self.callsign,)
+        print("callsign=%s" % (self.callsign,), file=f)
         date = self.departureTime.date()
-        print >> f, "date=%04d-%02d-%0d" % (date.year, date.month, date.day)
-        print >> f, "dep_airport=%s" % (self.departureICAO,)
-        print >> f, "dest_airport=%s" % (self.arrivalICAO,)
-        print >> f, "planecode=%s" % \
-              (BookedFlight.TYPE2TYPECODE[self.aircraftType],)
-        print >> f, "planetype=%s" % (self.aircraftTypeName,)
-        print >> f, "tail_nr=%s" % (self.tailNumber,)
-        print >> f, "passenger=%d" % (self.numPassengers,)
-        print >> f, "crew=%d" % (self.numCrew,)
-        print >> f, "bag=%d" % (self.bagWeight,)
-        print >> f, "cargo=%d" % (self.cargoWeight,)
-        print >> f, "mail=%d" % (self.mailWeight,)
-        print >> f, "flight_route=%s" % (self.route,)
+        print("date=%04d-%02d-%0d" % (date.year, date.month, date.day), file=f)
+        print("dep_airport=%s" % (self.departureICAO,), file=f)
+        print("dest_airport=%s" % (self.arrivalICAO,), file=f)
+        print("planecode=%s" % \
+              (BookedFlight.TYPE2TYPECODE[self.aircraftType],), file=f)
+        print("planetype=%s" % (self.aircraftTypeName,), file=f)
+        print("tail_nr=%s" % (self.tailNumber,), file=f)
+        print("passenger=%d" % (self.numPassengers,), file=f)
+        print("crew=%d" % (self.numCrew,), file=f)
+        print("bag=%d" % (self.bagWeight,), file=f)
+        print("cargo=%d" % (self.cargoWeight,), file=f)
+        print("mail=%d" % (self.mailWeight,), file=f)
+        print("flight_route=%s" % (self.route,), file=f)
         departureTime = self.departureTime
-        print >> f, "departure_time=%02d\\:%02d\\:%02d" % \
-              (departureTime.hour, departureTime.minute, departureTime.second)
+        print("departure_time=%02d\\:%02d\\:%02d" % \
+              (departureTime.hour, departureTime.minute, departureTime.second), file=f)
         arrivalTime = self.arrivalTime
-        print >> f, "arrival_time=%02d\\:%02d\\:%02d" % \
-              (arrivalTime.hour, arrivalTime.minute, arrivalTime.second)
-        print >> f, "foglalas_id=%s" % ("0" if self.id is None else self.id,)
+        print("arrival_time=%02d\\:%02d\\:%02d" % \
+              (arrivalTime.hour, arrivalTime.minute, arrivalTime.second), file=f)
+        print("foglalas_id=%s" % ("0" if self.id is None else self.id,), file=f)
 
     def _readAircraftType(self, f):
@@ -333,11 +324,4 @@
         if typeCode in self.TYPECODE2TYPE:
             return self.TYPECODE2TYPE[typeCode]
-        else:
-            raise Exception("Invalid aircraft type code: '" + typeCode + "'")
-
-    def _decodeAircraftICAOType(self, typeCode):
-        """Decode the aircraft type from the given typeCode."""
-        if typeCode in const.icao2Type:
-            return const.icao2Type[typeCode]
         else:
             raise Exception("Invalid aircraft type code: '" + typeCode + "'")
@@ -380,5 +364,5 @@
 
         except:
-            print >> sys.stderr, "Plane string is invalid: '" + s + "'"
+            print("Plane string is invalid: '" + s + "'", file=sys.stderr)
             self.tailNumber = None
 
@@ -486,9 +470,9 @@
 #------------------------------------------------------------------------------
 
-class PilotsWebNOTAMsParser(HTMLParser.HTMLParser):
+class PilotsWebNOTAMsParser(html.parser.HTMLParser):
     """XML handler for the NOTAM query results on the PilotsWeb website."""
     def __init__(self):
         """Construct the handler."""
-        HTMLParser.HTMLParser.__init__(self)
+        html.parser.HTMLParser.__init__(self)
 
         self._notams = []
@@ -529,9 +513,9 @@
         try:
             notam = self._parseCurrentNOTAM2()
-        except Exception, e:
-            print "Error parsing current NOTAM: " + str(e)
+        except Exception as e:
+            print("Error parsing current NOTAM: " + str(e))
 
         if notam is None:
-            print "Could not parse NOTAM: " + self._currentNOTAM
+            print("Could not parse NOTAM: " + self._currentNOTAM)
             if self._currentNOTAM:
                 self._notams.append(self._currentNOTAM + "\n")
@@ -542,5 +526,5 @@
         """Parse the current NOTAM, if possible, and return a NOTAM object."""
         lines = self._currentNOTAM.splitlines()
-        lines = map(lambda line: line.strip(), lines)
+        lines = [line.strip() for line in lines]
 
         if len(lines)<4:
@@ -595,5 +579,5 @@
         """Parse the current NOTAM with a second, more flexible method."""
         lines = self._currentNOTAM.splitlines()
-        lines = map(lambda line: line.strip(), lines)
+        lines = [line.strip() for line in lines]
 
         if not lines:
@@ -608,5 +592,5 @@
                 lines = lines[:-1]
 
-        lines = map(lambda line: line.strip(), lines)
+        lines = [line.strip() for line in lines]
         contents = " ".join(lines).split()
 
@@ -669,6 +653,6 @@
         """Get a representation of the result."""
         s = "<Result:"
-        for (key, value) in self.__dict__.iteritems():
-            s += " " + key + "=" + unicode(value)
+        for (key, value) in self.__dict__.items():
+            s += " " + key + "=" + str(value)
         s += ">"
         return s
@@ -704,5 +688,5 @@
             result = self.run()
             returned = True
-        except Exception, e:
+        except Exception as e:
             traceback.print_exc()
             result = e
@@ -711,6 +695,6 @@
         try:
             self._callback(returned, result)
-        except Exception, e:
-            print >> sys.stderr, "web.Handler.Request.perform: callback throwed an exception: " + util.utf2unicode(str(e))
+        except Exception as e:
+            print("web.Handler.Request.perform: callback throwed an exception: " + util.utf2unicode(str(e)), file=sys.stderr)
             #traceback.print_exc()
 
@@ -785,5 +769,5 @@
         result = Result()
 
-        f = urllib2.urlopen(url, timeout = 10.0)
+        f = urllib.request.urlopen(url, timeout = 10.0)
 
         status = readline(f)
@@ -831,12 +815,8 @@
             result.types = loginResult[2]
             result.password = password
-
-            result.aircraftTypes = client.getTypes()
-
             flights = client.getFlights()
             result.flights = flights[0]
             result.reportedFlights = flights[1]
             result.rejectedFlights = flights[2]
-
             if result.rank=="STU":
                 reply = client.getEntryExamStatus()
@@ -900,5 +880,5 @@
         url = MAVA_BASE_URL + "/onlinegates_get.php"
 
-        f = urllib2.urlopen(url, timeout = 10.0)
+        f = urllib.request.urlopen(url, timeout = 10.0)
         result = Result()
         result.fleet = Fleet(f)
@@ -942,9 +922,9 @@
         gateNumber = self._gateNumber if self._gateNumber else ""
 
-        data = urllib.urlencode([("lajstrom", self._tailNumber),
+        data = urllib.parse.urlencode([("lajstrom", self._tailNumber),
                                  ("status", status),
                                  ("kapu", gateNumber)])
 
-        f = urllib2.urlopen(url, data, timeout = 10.0)
+        f = urllib.request.urlopen(url, data, timeout = 10.0)
         line = readline(f)
 
@@ -1003,5 +983,5 @@
             url = "http://notams.euroutepro.com/notams.xml"
 
-            f = urllib2.urlopen(url, timeout = 10.0)
+            f = urllib.request.urlopen(url, timeout = 10.0)
             try:
                 xmlParser.parse(f)
@@ -1032,5 +1012,5 @@
               (icao.upper(),)
 
-            f = urllib2.urlopen(url, timeout = 10.0)
+            f = urllib.request.urlopen(url, timeout = 10.0)
             try:
                 data = f.read(16384)
@@ -1043,8 +1023,8 @@
             return parser.getNOTAMs()
 
-        except Exception, e:
+        except Exception as e:
             traceback.print_exc()
-            print "mlx.web.GetNOTAMs.getPilotsWebNOTAMs: failed to get NOTAMs for '%s': %s" % \
-                  (icao, str(e))
+            print("mlx.web.GetNOTAMs.getPilotsWebNOTAMs: failed to get NOTAMs for '%s': %s" % \
+                  (icao, str(e)))
             return None
 
@@ -1062,5 +1042,5 @@
         """Perform the retrieval opf the METARs."""
         url = "http://www.aviationweather.gov/adds/dataserver_current/httpparam?"
-        data = urllib.urlencode([ ("dataSource" , "metars"),
+        data = urllib.parse.urlencode([ ("dataSource" , "metars"),
                                   ("requestType",  "retrieve"),
                                   ("format", "csv"),
@@ -1069,5 +1049,5 @@
                                   ("mostRecentForEachStation", "constraint")])
         url += data
-        f = urllib2.urlopen(url, timeout = 10.0)
+        f = urllib.request.urlopen(url, timeout = 10.0)
         try:
             result = Result()
@@ -1148,10 +1128,10 @@
         data["insdate"] = datetime.date.today().strftime("%Y-%m-%d")
 
-        postData = urllib.urlencode(data)
-        f = urllib2.urlopen(url, postData, timeout = 10.0)
+        postData = urllib.parse.urlencode(data)
+        f = urllib.request.urlopen(url, postData, timeout = 10.0)
         try:
             result = Result()
             line = f.readline().strip()
-            print "PIREP result from website:", line
+            print("PIREP result from website:", line)
             result.success = line=="OK"
             result.alreadyFlown = line=="MARVOLT"
@@ -1198,5 +1178,5 @@
     def run(self):
         """Perform the sending of the ACARS."""
-        print "Sending the online ACARS"
+        print("Sending the online ACARS")
 
         url = MAVA_BASE_URL  + "/acars2/acarsonline.php"
@@ -1224,5 +1204,5 @@
         data["event"] = acars.getEventText()
 
-        f = urllib2.urlopen(url, urllib.urlencode(data), timeout = 10.0)
+        f = urllib.request.urlopen(url, urllib.parse.urlencode(data), timeout = 10.0)
         try:
             result = Result()
@@ -1243,5 +1223,5 @@
     def run(self):
         """Perform the sending of the ACARS."""
-        print "Sending the online ACARS via JSON-RPC"
+        print("Sending the online ACARS via JSON-RPC")
 
         self._client.updateOnlineACARS(self._acars)
@@ -1263,5 +1243,5 @@
     def run(self):
         """Perform the sending of the bug report."""
-        serverProxy = xmlrpclib.ServerProxy("http://mlx.varadiistvan.hu/rpc")
+        serverProxy = xmlrpc.client.ServerProxy("http://mlx.varadiistvan.hu/rpc")
 
         result = Result()
@@ -1274,5 +1254,5 @@
         result.ticketID = serverProxy.ticket.create(self._summary, self._description,
                                                     attributes, True)
-        print "Created ticket with ID:", result.ticketID
+        print("Created ticket with ID:", result.ticketID)
         result.success = True
 
@@ -1308,5 +1288,5 @@
 
         pirepData = self._client.getPIREP(self._flightID)
-        print "pirepData:", pirepData
+        print("pirepData:", pirepData)
 
         bookedFlight = BookedFlight(self._flightID)
@@ -1532,5 +1512,5 @@
 
     def callback(returned, result):
-        print returned, unicode(result)
+        print(returned, str(result))
 
     handler = Handler()
