Ignore:
Timestamp:
03/24/19 08:15:59 (5 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
python3
Phase:
public
Message:

Ran 2to3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/pyuipc_sim.py

    r877 r919  
    11
    2 import const
     2from . import const
    33
    44import cmd
     
    99import sys
    1010import struct
    11 import cPickle
     11import pickle
    1212import math
    1313
     
    342342        try:
    343343            return self._read(offset, type)
    344         except Exception, e:
    345             print "failed to read offset %04x: %s" % (offset, str(e))
     344        except Exception as e:
     345            print("failed to read offset %04x: %s" % (offset, str(e)))
    346346            raise FSUIPCException(ERR_DATA)
    347347
     
    414414            return 1 if self.overspeed else 0
    415415        elif offset==0x0560:       # Latitude
    416             return long(self.latitude * 10001750.0 * 65536.0 * 65536.0 / 90.0)
     416            return int(self.latitude * 10001750.0 * 65536.0 * 65536.0 / 90.0)
    417417        elif offset==0x0568:       # Longitude
    418             return long(self.longitude * 65536.0 * 65536.0 * 65536.0 * 65536.0 / 360.0)
     418            return int(self.longitude * 65536.0 * 65536.0 * 65536.0 * 65536.0 / 360.0)
    419419        elif offset==0x0570:       # Altitude
    420             return long(self.altitude * const.FEETTOMETRES * 65536.0 * 65536.0)
     420            return int(self.altitude * const.FEETTOMETRES * 65536.0 * 65536.0)
    421421        elif offset==0x0578:       # Pitch
    422422            return int(self.pitch * 65536.0 * 65536.0 / 360.0)
     
    584584                    return value
    585585                else:
    586                     print "Unhandled offset: %04x" % (offset,)
     586                    print("Unhandled offset: %04x" % (offset,))
    587587                    raise FSUIPCException(ERR_DATA)
    588588            else:
    589                 print "Unhandled offset: %04x" % (offset,)
     589                print("Unhandled offset: %04x" % (offset,))
    590590                raise FSUIPCException(ERR_DATA)
    591591        elif offset==0x32fa:       # Message duration
     
    616616            return 0 if self.xpdrC else 1
    617617        else:
    618             print "Unhandled offset: %04x" % (offset,)
     618            print("Unhandled offset: %04x" % (offset,))
    619619            raise FSUIPCException(ERR_DATA)
    620620
     
    623623        try:
    624624            return self._write(offset, value, type)
    625         except TypeError, e:
     625        except TypeError as e:
    626626            raise e
    627         except Exception, e:
    628             print "failed to write offset %04x: %s" % (offset, str(e))
     627        except Exception as e:
     628            print("failed to write offset %04x: %s" % (offset, str(e)))
    629629            raise FSUIPCException(ERR_DATA)
    630630
     
    852852                    hotkey[3] = (value>>24) & 0xff
    853853                else:
    854                     print "Unhandled offset: %04x for type '%s'" % (offset, type)
     854                    print("Unhandled offset: %04x for type '%s'" % (offset, type))
    855855                    raise FSUIPCException(ERR_DATA)
    856856            else:
    857                 print "Unhandled offset: %04x for type '%s'" % (offset, type)
     857                print("Unhandled offset: %04x for type '%s'" % (offset, type))
    858858                raise FSUIPCException(ERR_DATA)
    859859        elif offset==0x32fa:       # Message duration
     
    882882            self.xpdrC = value==0
    883883        else:
    884             print "Unhandled offset: %04x" % (offset,)
     884            print("Unhandled offset: %04x" % (offset,))
    885885            raise FSUIPCException(ERR_DATA)
    886886
     
    10391039                (length,) = struct.unpack("I", clientSocket.recv(4))
    10401040                data = clientSocket.recv(length)
    1041                 (call, args) = cPickle.loads(data)
     1041                (call, args) = pickle.loads(data)
    10421042                exception = None
    10431043
     
    10611061                    else:
    10621062                        break
    1063                 except Exception, e:
     1063                except Exception as e:
    10641064                    exception = e
    10651065
    10661066                if exception is None:
    1067                     data = cPickle.dumps((RESULT_RETURNED, result))
     1067                    data = pickle.dumps((RESULT_RETURNED, result))
    10681068                else:
    1069                     data = cPickle.dumps((RESULT_EXCEPTION, str(exception)))
     1069                    data = pickle.dumps((RESULT_EXCEPTION, str(exception)))
    10701070                clientSocket.send(struct.pack("I", len(data)) + data)
    1071         except Exception, e:
    1072             print >> sys.stderr, "pyuipc_sim.Server._process: failed with exception:", str(e)
     1071        except Exception as e:
     1072            print("pyuipc_sim.Server._process: failed with exception:", str(e), file=sys.stderr)
    10731073        finally:
    10741074            try:
     
    11121112    def quit(self):
    11131113        """Quit from the simulator."""
    1114         data = cPickle.dumps((CALL_QUIT, None))
     1114        data = pickle.dumps((CALL_QUIT, None))
    11151115        self._socket.send(struct.pack("I", len(data)) + data)
    11161116
    11171117    def _call(self, command, data):
    11181118        """Perform a call with the given command and data."""
    1119         data = cPickle.dumps((command, [data]))
     1119        data = pickle.dumps((command, [data]))
    11201120        self._socket.send(struct.pack("I", len(data)) + data)
    11211121        (length,) = struct.unpack("I", self._socket.recv(4))
    11221122        data = self._socket.recv(length)
    1123         (resultCode, result) = cPickle.loads(data)
     1123        (resultCode, result) = pickle.loads(data)
    11241124        if resultCode==RESULT_RETURNED:
    11251125            return result
     
    12341234                                           lambda value: value * 90.0 /
    12351235                                           10001750.0 / 65536.0 / 65536.0,
    1236                                            lambda word: long(float(word) *
     1236                                           lambda word: int(float(word) *
    12371237                                                             10001750.0 *
    12381238                                                             65536.0 * 65536.0 / 90.0))
     
    12401240                                            lambda value: value * 360.0 /
    12411241                                            65536.0 / 65536.0 / 65536.0 / 65536.0,
    1242                                             lambda word: long(float(word) *
     1242                                            lambda word: int(float(word) *
    12431243                                                              65536.0 * 65536.0 *
    12441244                                                              65536.0 * 65536.0 /
     
    13001300                                           const.FEETTOMETRES / 65536.0 /
    13011301                                           65536.0,
    1302                                            lambda word: long(float(word) *
     1302                                           lambda word: int(float(word) *
    13031303                                                             const.FEETTOMETRES *
    13041304                                                             65536.0 * 65536.0))
     
    14871487            self._valueHandlers["hotkey%d" % (i,)] = ([(0x3210 + i*4, "u")],
    14881488                                                      lambda value: "0x%08x" % (value,),
    1489                                                       lambda word: long(word, 16))
     1489                                                      lambda word: int(word, 16))
    14901490
    14911491        self._valueHandlers["cog"] = ([(0x2ef8, "f")], lambda value: value,
     
    15371537        """Handle unhandle commands."""
    15381538        if line=="EOF":
    1539             print
     1539            print()
    15401540            return self.do_quit("")
    15411541        else:
     
    15481548        for name in names:
    15491549            if name not in self._valueHandlers:
    1550                 print >> sys.stderr, "Unknown variable: " + name
     1550                print("Unknown variable: " + name, file=sys.stderr)
    15511551                return False
    15521552            valueHandler = self._valueHandlers[name]
     
    15651565                                        else thisResults)
    15661566
    1567                 print name + "=" + str(value)
     1567                print(name + "=" + str(value))
    15681568
    15691569                index += numResults
    15701570                i+=1
    1571         except Exception, e:
    1572             print >> sys.stderr, "Failed to read data: " + str(e)
     1571        except Exception as e:
     1572            print("Failed to read data: " + str(e), file=sys.stderr)
    15731573
    15741574        return False
     
    15761576    def help_get(self):
    15771577        """Print help for the get command."""
    1578         print "get <variable> [<variable>...]"
     1578        print("get <variable> [<variable>...]")
    15791579
    15801580    def complete_get(self, text, line, begidx, endidx):
     
    16081608            words = argument.split("=")
    16091609            if len(words)!=2:
    1610                 print >> sys.stderr, "Invalid argument: " + argument
     1610                print("Invalid argument: " + argument, file=sys.stderr)
    16111611                return False
    16121612
    16131613            (name, value) = words
    16141614            if name not in self._valueHandlers:
    1615                 print >> sys.stderr, "Unknown variable: " + name
     1615                print("Unknown variable: " + name, file=sys.stderr)
    16161616                return False
    16171617
     
    16251625                    data.append((offset, type, values[index]))
    16261626                    index += 1
    1627             except Exception, e:
    1628                 print >> sys.stderr, "Invalid value '%s' for variable %s: %s" % \
    1629                       (value, name, str(e))
     1627            except Exception as e:
     1628                print("Invalid value '%s' for variable %s: %s" % \
     1629                      (value, name, str(e)), file=sys.stderr)
    16301630                return False
    16311631
    16321632        try:
    16331633            self._client.write(data)
    1634             print "Data written"
    1635         except Exception, e:
    1636             print >> sys.stderr, "Failed to write data: " + str(e)
     1634            print("Data written")
     1635        except Exception as e:
     1636            print("Failed to write data: " + str(e), file=sys.stderr)
    16371637
    16381638        return False
     
    16401640    def help_set(self):
    16411641        """Print help for the set command."""
    1642         print "set <variable>=<value> [<variable>=<value>...]"
     1642        print("set <variable>=<value> [<variable>=<value>...]")
    16431643
    16441644    def complete_set(self, text, line, begidx, endidx):
     
    16541654            value = int(args)
    16551655            self._client.setVersion(value)
    1656             print "Emulating version %d" % (value,)
    1657         except Exception, e:
    1658             print >> sys.stderr, "Failed to set the version: " + str(e)
     1656            print("Emulating version %d" % (value,))
     1657        except Exception as e:
     1658            print("Failed to set the version: " + str(e), file=sys.stderr)
    16591659
    16601660    def help_setversion(self, usage = False):
    16611661        """Help for the setversion command"""
    1662         if usage: print "Usage:",
    1663         print "setversion <number>"
     1662        if usage: print("Usage:", end=' ')
     1663        print("setversion <number>")
    16641664
    16651665    def do_close(self, args):
     
    16671667        try:
    16681668            self._client.close()
    1669             print "Connection closed"
    1670         except Exception, e:
    1671             print >> sys.stderr, "Failed to close the connection: " + str(e)
     1669            print("Connection closed")
     1670        except Exception as e:
     1671            print("Failed to close the connection: " + str(e), file=sys.stderr)
    16721672
    16731673    def do_failopen(self, args):
     
    16761676            value = self.str2bool(args)
    16771677            self._client.failOpen(value)
    1678             print "Opening will%s fail" % ("" if value else " not",)
    1679         except Exception, e:
    1680             print >> sys.stderr, "Failed to set open failure: " + str(e)
     1678            print("Opening will%s fail" % ("" if value else " not",))
     1679        except Exception as e:
     1680            print("Failed to set open failure: " + str(e), file=sys.stderr)
    16811681
    16821682    def help_failopen(self, usage = False):
    16831683        """Help for the failopen command"""
    1684         if usage: print "Usage:",
    1685         print "failopen yes|no"
     1684        if usage: print("Usage:", end=' ')
     1685        print("failopen yes|no")
    16861686
    16871687    def complete_failopen(self, text, line, begidx, endidx):
Note: See TracChangeset for help on using the changeset viewer.