Ignore:
Timestamp:
03/24/19 08:15:59 (5 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
python3
hg-Phase:
(<MercurialRepository 1 'hg:/home/ivaradi/mlx/hg' '/'>, 'public')
Message:

Ran 2to3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/web.py

    r859 r919  
    11
    2 import const
    3 import util
    4 from rpc import Registration
    5 import rpc
    6 import rpccommon
    7 
    8 from common import MAVA_BASE_URL
    9 from pirep import PIREP
     2from . import const
     3from . import util
     4from .rpc import Registration
     5from . import rpc
     6from . import rpccommon
     7
     8from .common import MAVA_BASE_URL
     9from .pirep import PIREP
    1010
    1111import threading
    1212import sys
    13 import urllib
    14 import urllib2
     13import urllib.request, urllib.parse, urllib.error
     14import urllib.request, urllib.error, urllib.parse
    1515import hashlib
    1616import time
     
    1919import traceback
    2020import xml.sax
    21 import xmlrpclib
    22 import HTMLParser
     21import xmlrpc.client
     22import html.parser
    2323
    2424#---------------------------------------------------------------------------------------
     
    160160
    161161        date = readline(f)
    162         print "web.BookedFlight.readFromWeb: date:", date
     162        print("web.BookedFlight.readFromWeb: date:", date)
    163163        if date=="0000-00-00": date = "0001-01-01"
    164164
     
    233233
    234234                if not lineOK:
    235                     print "web.BookedFlight.readFromFile: line %d is invalid" % \
    236                           (lineNumber,)
     235                    print("web.BookedFlight.readFromFile: line %d is invalid" % \
     236                          (lineNumber,))
    237237
    238238            line = f.readline()
     
    290290    def writeIntoFile(self, f):
    291291        """Write the flight into a file."""
    292         print >> f, "callsign=%s" % (self.callsign,)
     292        print("callsign=%s" % (self.callsign,), file=f)
    293293        date = self.departureTime.date()
    294         print >> f, "date=%04d-%02d-%0d" % (date.year, date.month, date.day)
    295         print >> f, "dep_airport=%s" % (self.departureICAO,)
    296         print >> f, "dest_airport=%s" % (self.arrivalICAO,)
    297         print >> f, "planecode=%s" % \
    298               (BookedFlight.TYPE2TYPECODE[self.aircraftType],)
    299         print >> f, "planetype=%s" % (self.aircraftTypeName,)
    300         print >> f, "tail_nr=%s" % (self.tailNumber,)
    301         print >> f, "passenger=%d" % (self.numPassengers,)
    302         print >> f, "crew=%d" % (self.numCrew,)
    303         print >> f, "bag=%d" % (self.bagWeight,)
    304         print >> f, "cargo=%d" % (self.cargoWeight,)
    305         print >> f, "mail=%d" % (self.mailWeight,)
    306         print >> f, "flight_route=%s" % (self.route,)
     294        print("date=%04d-%02d-%0d" % (date.year, date.month, date.day), file=f)
     295        print("dep_airport=%s" % (self.departureICAO,), file=f)
     296        print("dest_airport=%s" % (self.arrivalICAO,), file=f)
     297        print("planecode=%s" % \
     298              (BookedFlight.TYPE2TYPECODE[self.aircraftType],), file=f)
     299        print("planetype=%s" % (self.aircraftTypeName,), file=f)
     300        print("tail_nr=%s" % (self.tailNumber,), file=f)
     301        print("passenger=%d" % (self.numPassengers,), file=f)
     302        print("crew=%d" % (self.numCrew,), file=f)
     303        print("bag=%d" % (self.bagWeight,), file=f)
     304        print("cargo=%d" % (self.cargoWeight,), file=f)
     305        print("mail=%d" % (self.mailWeight,), file=f)
     306        print("flight_route=%s" % (self.route,), file=f)
    307307        departureTime = self.departureTime
    308         print >> f, "departure_time=%02d\\:%02d\\:%02d" % \
    309               (departureTime.hour, departureTime.minute, departureTime.second)
     308        print("departure_time=%02d\\:%02d\\:%02d" % \
     309              (departureTime.hour, departureTime.minute, departureTime.second), file=f)
    310310        arrivalTime = self.arrivalTime
    311         print >> f, "arrival_time=%02d\\:%02d\\:%02d" % \
    312               (arrivalTime.hour, arrivalTime.minute, arrivalTime.second)
    313         print >> f, "foglalas_id=%s" % ("0" if self.id is None else self.id,)
     311        print("arrival_time=%02d\\:%02d\\:%02d" % \
     312              (arrivalTime.hour, arrivalTime.minute, arrivalTime.second), file=f)
     313        print("foglalas_id=%s" % ("0" if self.id is None else self.id,), file=f)
    314314
    315315    def _readAircraftType(self, f):
     
    364364
    365365        except:
    366             print >> sys.stderr, "Plane string is invalid: '" + s + "'"
     366            print("Plane string is invalid: '" + s + "'", file=sys.stderr)
    367367            self.tailNumber = None
    368368
     
    470470#------------------------------------------------------------------------------
    471471
    472 class PilotsWebNOTAMsParser(HTMLParser.HTMLParser):
     472class PilotsWebNOTAMsParser(html.parser.HTMLParser):
    473473    """XML handler for the NOTAM query results on the PilotsWeb website."""
    474474    def __init__(self):
    475475        """Construct the handler."""
    476         HTMLParser.HTMLParser.__init__(self)
     476        html.parser.HTMLParser.__init__(self)
    477477
    478478        self._notams = []
     
    513513        try:
    514514            notam = self._parseCurrentNOTAM2()
    515         except Exception, e:
    516             print "Error parsing current NOTAM: " + str(e)
     515        except Exception as e:
     516            print("Error parsing current NOTAM: " + str(e))
    517517
    518518        if notam is None:
    519             print "Could not parse NOTAM: " + self._currentNOTAM
     519            print("Could not parse NOTAM: " + self._currentNOTAM)
    520520            if self._currentNOTAM:
    521521                self._notams.append(self._currentNOTAM + "\n")
     
    526526        """Parse the current NOTAM, if possible, and return a NOTAM object."""
    527527        lines = self._currentNOTAM.splitlines()
    528         lines = map(lambda line: line.strip(), lines)
     528        lines = [line.strip() for line in lines]
    529529
    530530        if len(lines)<4:
     
    579579        """Parse the current NOTAM with a second, more flexible method."""
    580580        lines = self._currentNOTAM.splitlines()
    581         lines = map(lambda line: line.strip(), lines)
     581        lines = [line.strip() for line in lines]
    582582
    583583        if not lines:
     
    592592                lines = lines[:-1]
    593593
    594         lines = map(lambda line: line.strip(), lines)
     594        lines = [line.strip() for line in lines]
    595595        contents = " ".join(lines).split()
    596596
     
    653653        """Get a representation of the result."""
    654654        s = "<Result:"
    655         for (key, value) in self.__dict__.iteritems():
    656             s += " " + key + "=" + unicode(value)
     655        for (key, value) in self.__dict__.items():
     656            s += " " + key + "=" + str(value)
    657657        s += ">"
    658658        return s
     
    688688            result = self.run()
    689689            returned = True
    690         except Exception, e:
     690        except Exception as e:
    691691            traceback.print_exc()
    692692            result = e
     
    695695        try:
    696696            self._callback(returned, result)
    697         except Exception, e:
    698             print >> sys.stderr, "web.Handler.Request.perform: callback throwed an exception: " + util.utf2unicode(str(e))
     697        except Exception as e:
     698            print("web.Handler.Request.perform: callback throwed an exception: " + util.utf2unicode(str(e)), file=sys.stderr)
    699699            #traceback.print_exc()
    700700
     
    769769        result = Result()
    770770
    771         f = urllib2.urlopen(url, timeout = 10.0)
     771        f = urllib.request.urlopen(url, timeout = 10.0)
    772772
    773773        status = readline(f)
     
    880880        url = MAVA_BASE_URL + "/onlinegates_get.php"
    881881
    882         f = urllib2.urlopen(url, timeout = 10.0)
     882        f = urllib.request.urlopen(url, timeout = 10.0)
    883883        result = Result()
    884884        result.fleet = Fleet(f)
     
    922922        gateNumber = self._gateNumber if self._gateNumber else ""
    923923
    924         data = urllib.urlencode([("lajstrom", self._tailNumber),
     924        data = urllib.parse.urlencode([("lajstrom", self._tailNumber),
    925925                                 ("status", status),
    926926                                 ("kapu", gateNumber)])
    927927
    928         f = urllib2.urlopen(url, data, timeout = 10.0)
     928        f = urllib.request.urlopen(url, data, timeout = 10.0)
    929929        line = readline(f)
    930930
     
    983983            url = "http://notams.euroutepro.com/notams.xml"
    984984
    985             f = urllib2.urlopen(url, timeout = 10.0)
     985            f = urllib.request.urlopen(url, timeout = 10.0)
    986986            try:
    987987                xmlParser.parse(f)
     
    10121012              (icao.upper(),)
    10131013
    1014             f = urllib2.urlopen(url, timeout = 10.0)
     1014            f = urllib.request.urlopen(url, timeout = 10.0)
    10151015            try:
    10161016                data = f.read(16384)
     
    10231023            return parser.getNOTAMs()
    10241024
    1025         except Exception, e:
     1025        except Exception as e:
    10261026            traceback.print_exc()
    1027             print "mlx.web.GetNOTAMs.getPilotsWebNOTAMs: failed to get NOTAMs for '%s': %s" % \
    1028                   (icao, str(e))
     1027            print("mlx.web.GetNOTAMs.getPilotsWebNOTAMs: failed to get NOTAMs for '%s': %s" % \
     1028                  (icao, str(e)))
    10291029            return None
    10301030
     
    10421042        """Perform the retrieval opf the METARs."""
    10431043        url = "http://www.aviationweather.gov/adds/dataserver_current/httpparam?"
    1044         data = urllib.urlencode([ ("dataSource" , "metars"),
     1044        data = urllib.parse.urlencode([ ("dataSource" , "metars"),
    10451045                                  ("requestType",  "retrieve"),
    10461046                                  ("format", "csv"),
     
    10491049                                  ("mostRecentForEachStation", "constraint")])
    10501050        url += data
    1051         f = urllib2.urlopen(url, timeout = 10.0)
     1051        f = urllib.request.urlopen(url, timeout = 10.0)
    10521052        try:
    10531053            result = Result()
     
    11281128        data["insdate"] = datetime.date.today().strftime("%Y-%m-%d")
    11291129
    1130         postData = urllib.urlencode(data)
    1131         f = urllib2.urlopen(url, postData, timeout = 10.0)
     1130        postData = urllib.parse.urlencode(data)
     1131        f = urllib.request.urlopen(url, postData, timeout = 10.0)
    11321132        try:
    11331133            result = Result()
    11341134            line = f.readline().strip()
    1135             print "PIREP result from website:", line
     1135            print("PIREP result from website:", line)
    11361136            result.success = line=="OK"
    11371137            result.alreadyFlown = line=="MARVOLT"
     
    11781178    def run(self):
    11791179        """Perform the sending of the ACARS."""
    1180         print "Sending the online ACARS"
     1180        print("Sending the online ACARS")
    11811181
    11821182        url = MAVA_BASE_URL  + "/acars2/acarsonline.php"
     
    12041204        data["event"] = acars.getEventText()
    12051205
    1206         f = urllib2.urlopen(url, urllib.urlencode(data), timeout = 10.0)
     1206        f = urllib.request.urlopen(url, urllib.parse.urlencode(data), timeout = 10.0)
    12071207        try:
    12081208            result = Result()
     
    12231223    def run(self):
    12241224        """Perform the sending of the ACARS."""
    1225         print "Sending the online ACARS via JSON-RPC"
     1225        print("Sending the online ACARS via JSON-RPC")
    12261226
    12271227        self._client.updateOnlineACARS(self._acars)
     
    12431243    def run(self):
    12441244        """Perform the sending of the bug report."""
    1245         serverProxy = xmlrpclib.ServerProxy("http://mlx.varadiistvan.hu/rpc")
     1245        serverProxy = xmlrpc.client.ServerProxy("http://mlx.varadiistvan.hu/rpc")
    12461246
    12471247        result = Result()
     
    12541254        result.ticketID = serverProxy.ticket.create(self._summary, self._description,
    12551255                                                    attributes, True)
    1256         print "Created ticket with ID:", result.ticketID
     1256        print("Created ticket with ID:", result.ticketID)
    12571257        result.success = True
    12581258
     
    12881288
    12891289        pirepData = self._client.getPIREP(self._flightID)
    1290         print "pirepData:", pirepData
     1290        print("pirepData:", pirepData)
    12911291
    12921292        bookedFlight = BookedFlight(self._flightID)
     
    15121512
    15131513    def callback(returned, result):
    1514         print returned, unicode(result)
     1514        print(returned, str(result))
    15151515
    15161516    handler = Handler()
Note: See TracChangeset for help on using the changeset viewer.