From f2779197b13fdbbd0d42e48215c51d24d86ee91b Mon Sep 17 00:00:00 2001 From: Diego Roversi Date: Thu, 12 Sep 2019 21:33:58 +0200 Subject: 2to3 of display module --- display/pclient.py | 86 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 42 deletions(-) (limited to 'display/pclient.py') diff --git a/display/pclient.py b/display/pclient.py index c6546ce..b7ade98 100644 --- a/display/pclient.py +++ b/display/pclient.py @@ -8,9 +8,9 @@ import time from common.msgstruct import * from common.pixmap import decodepixmap from common import hostchooser -import modes -from modes import KeyPressed, KeyReleased -import caching +from . import modes +from .modes import KeyPressed, KeyReleased +from . import caching #import psyco; psyco.full() @@ -44,13 +44,13 @@ class Icon: self.rect = None return self.pixmap elif attr in ('bmpcode', 'rect'): - raise KeyError, attr + raise KeyError(attr) elif attr == 'originalrect': self.originalrect = self.rect return self.originalrect - raise AttributeError, attr + raise AttributeError(attr) def clear(self): - if self.__dict__.has_key('pixmap'): + if 'pixmap' in self.__dict__: del self.pixmap class DataChunk(caching.Data): @@ -77,7 +77,7 @@ class DataChunk(caching.Data): DataChunk.TOTAL += lendata total = DataChunk.TOTAL >> 10 if total != prev: - print "downloaded %dkb of data from server" % total + print("downloaded %dkb of data from server" % total) self.store(position, data) try: self.pending.remove((0, position)) @@ -104,24 +104,24 @@ class Playfield: self.sockaddr = sockaddr try: self.s.setsockopt(SOL_IP, IP_TOS, 0x10) # IPTOS_LOWDELAY - except error, e: - print >> sys.stderr, "Cannot set IPTOS_LOWDELAY:", str(e) + except error as e: + print("Cannot set IPTOS_LOWDELAY:", str(e), file=sys.stderr) try: self.s.setsockopt(SOL_TCP, TCP_NODELAY, 1) - except error, e: - print >> sys.stderr, "Cannot set TCP_NODELAY:", str(e) + except error as e: + print("Cannot set TCP_NODELAY:", str(e), file=sys.stderr) initialbuf = "" while 1: t = self.s.recv(200) if not t and not hasattr(self.s, 'RECV_CAN_RETURN_EMPTY'): - raise error, "connexion closed" + raise error("connexion closed") initialbuf += t if len(initialbuf) >= len(MSG_WELCOME): head = initialbuf[:len(MSG_WELCOME)] tail = initialbuf[len(MSG_WELCOME):] if head != MSG_WELCOME: - raise error, "connected to something not a game server" + raise error("connected to something not a game server") if '\n' in tail: break n = tail.index('\n') @@ -135,7 +135,7 @@ class Playfield: ## if i >= 0: ## self.gameident, self.datapath = (self.gameident[:i].strip(), ## self.gameident[i+1:-1]) - print "connected to %r." % self.gameident + print("connected to %r." % self.gameident) self.s.sendall(message(CMSG_PROTO_VERSION, 3)) def setup(self, mode, udp_over_tcp): @@ -156,10 +156,10 @@ class Playfield: self.playericons = {} self.screenmode = mode self.initlevel = 0 - if mode[-1].has_key('udp_over_tcp'): + if 'udp_over_tcp' in mode[-1]: udp_over_tcp = mode[-1]['udp_over_tcp'] self.trackcfgmtime = None - if mode[-1].has_key('cfgfile'): + if 'cfgfile' in mode[-1]: self.trackcfgfile = mode[-1]['cfgfile'] else: self.trackcfgfile = os.path.join(DataChunk.SOURCEDIR, @@ -217,8 +217,8 @@ class Playfield: while self.udpsock in iwtd: try: udpdata = self.udpsock.recv(65535) - except error, e: - print >> sys.stderr, e + except error as e: + print(e, file=sys.stderr) errors += 1 if errors > 10: raise @@ -420,9 +420,9 @@ class Playfield: t = time.time() t, t0 = t-t0, t if t: - print "%.2f images per second, %.1f kbytes per second" % ( + print("%.2f images per second, %.1f kbytes per second" % ( float(n)/t, - float(self.tcpbytecounter+self.udpbytecounter)/1024/t) + float(self.tcpbytecounter+self.udpbytecounter)/1024/t)) self.tcpbytecounter = -self.udpbytecounter n = 0 self.painttimes = t0, n @@ -432,7 +432,7 @@ class Playfield: iconlist = [] f = 1.5 * time.time() f = f-int(f) - pi = self.playericons.items() + pi = list(self.playericons.items()) pi.sort() xpos = 0 for id, ico in pi: @@ -460,7 +460,8 @@ class Playfield: self.animdelay = 0.04 return y0, iconlist - def clic_taskbar(self, (cx,cy)): + def clic_taskbar(self, xxx_todo_changeme): + (cx,cy) = xxx_todo_changeme y0, icons = self.get_taskbar() if cy >= y0: for x, y, ico, id in icons: @@ -480,13 +481,14 @@ class Playfield: pass return y0, bkgnd - def erase_taskbar(self, (y0, bkgnd)): + def erase_taskbar(self, xxx_todo_changeme1): + (y0, bkgnd) = xxx_todo_changeme1 self.dpy.putppm(0, y0, bkgnd) def nextkeyname(self): pid, df = self.keydefinition - undef = [(num, keyname) for keyname, (num, icons) in self.keys.items() - if not df.has_key(keyname) and icons] + undef = [(num, keyname) for keyname, (num, icons) in list(self.keys.items()) + if keyname not in df and icons] if undef: num, keyname = min(undef) return keyname @@ -556,7 +558,7 @@ class Playfield: pending = {} for keysym, event in keyevents: pending[keysym] = event - for keysym, event in pending.items(): + for keysym, event in list(pending.items()): code = self.keycodes.get((keysym, event)) if code and self.playing.get(code[0]) == 'l': if (code == self.last_key_event[0] and @@ -588,7 +590,7 @@ class Playfield: self.taskbartimeout = None if self.taskbarfree: self.taskbarmode = (nmode or - 'l' not in self.playing.values() or + 'l' not in list(self.playing.values()) or (self.keydefinition is not None)) if nmode: self.taskbartimeout = time.time() + 5.0 @@ -597,26 +599,26 @@ class Playfield: def define_key(self, keysym): clic_id, df = self.keydefinition - if keysym in df.values(): + if keysym in list(df.values()): return df[self.nextkeyname()] = keysym if self.nextkeyname() is not None: return self.keydefinition = None self.s.sendall(message(CMSG_ADD_PLAYER, clic_id)) - for keyname, (num, icons) in self.keys.items(): + for keyname, (num, icons) in list(self.keys.items()): if keyname[:1] == '-': event = KeyReleased keyname = keyname[1:] else: event = KeyPressed - if df.has_key(keyname): + if keyname in df: keysym = df[keyname] self.keycodes[keysym, event] = \ clic_id, message(CMSG_KEY, clic_id, num) def msg_unknown(self, *rest): - print >> sys.stderr, "?" + print("?", file=sys.stderr) def msg_player_join(self, id, local, *rest): if local: @@ -628,7 +630,7 @@ class Playfield: def msg_player_kill(self, id, *rest): self.playing[id] = 0 - for key, (pid, msg) in self.keycodes.items(): + for key, (pid, msg) in list(self.keycodes.items()): if pid == id: del self.keycodes[key] @@ -651,8 +653,8 @@ class Playfield: self.udpsock2 = socket(AF_INET, SOCK_DGRAM) self.udpsock2.bind(('', port)) self.udpsock2.setsockopt(SOL_SOCKET, SO_BROADCAST, 1) - except error, e: - print "Cannot listen on the broadcast port %d" % port, str(e) + except error as e: + print("Cannot listen on the broadcast port %d" % port, str(e)) self.udpsock2 = None else: self.iwtd.append(self.udpsock2) @@ -664,7 +666,7 @@ class Playfield: # self.snd.close() if self.dpy is not None: # clear all pixmaps - for ico in self.icons.values(): + for ico in list(self.icons.values()): ico.clear() self.pixmaps.clear() self.dpy.close() @@ -726,7 +728,7 @@ class Playfield: f.when_ready(ready) def msg_patch_file(self, fileid, position, data, lendata=None, *rest): - if self.fileids.has_key(fileid): + if fileid in self.fileids: f = self.fileids[fileid] else: f = self.fileids[fileid] = DataChunk(fileid) @@ -737,7 +739,7 @@ class Playfield: self.msg_patch_file(fileid, position, data1, len(data), *rest) def msg_md5_file(self, fileid, filename, position, length, checksum, *rest): - if self.fileids.has_key(fileid): + if fileid in self.fileids: f = self.fileids[fileid] else: f = self.fileids[fileid] = DataChunk(fileid) @@ -777,13 +779,13 @@ class Playfield: f.close() d = eval(data or '{}', {}, {}) except: - print >> sys.stderr, 'Invalid config file format' + print('Invalid config file format', file=sys.stderr) else: d = d.get(gethostname(), {}) namemsg = '' - for id, local in self.playing.items(): + for id, local in list(self.playing.items()): keyid = 'player%d' % id - if local == 'l' and d.has_key(keyid): + if local == 'l' and keyid in d: namemsg = namemsg + message( CMSG_PLAYER_NAME, id, d[keyid]) if namemsg: @@ -803,9 +805,9 @@ class Playfield: self.udpsock_low += 1 if self.udpsock_low >= 3 and self.initlevel >= 1: # third time now -- that's too much - print "Note: routing UDP traffic over TCP", + print("Note: routing UDP traffic over TCP", end=' ') inp = self.udpbytecounter / (udpkbytes*1024.0) - print "(%d%% packet loss)" % int(100*(1.0-inp)) + print("(%d%% packet loss)" % int(100*(1.0-inp))) self.start_udp_over_tcp() self.s.sendall(message(CMSG_UDP_PORT, MSG_INLINE_FRAME)) else: -- cgit v1.2.3