From f3741058de44ec373e4d3d1001a66176081f1797 Mon Sep 17 00:00:00 2001 From: kalenz Date: Tue, 3 Feb 2015 08:45:22 +0100 Subject: Python 3 support --- miniircd | 17 ++++++++--------- test.py | 4 ++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/miniircd b/miniircd index 0eae9a8..e95bb2d 100755 --- a/miniircd +++ b/miniircd @@ -541,7 +541,7 @@ class Client(object): self.server.print_debug( "[%s:%d] -> %r" % (self.host, self.port, data)) quitmsg = "EOT" - except socket.error, x: + except socket.error as x: data = "" quitmsg = x if data: @@ -559,7 +559,7 @@ class Client(object): "[%s:%d] <- %r" % ( self.host, self.port, self.__writebuffer[:sent])) self.__writebuffer = self.__writebuffer[sent:] - except socket.error, x: + except socket.error as x: self.disconnect(x) def disconnect(self, quitmsg): @@ -705,12 +705,12 @@ class Server(object): def print_info(self, msg): if self.verbose: - print msg + print(msg) sys.stdout.flush() def print_debug(self, msg): if self.debug: - print msg + print(msg) sys.stdout.flush() def print_error(self, msg): @@ -800,11 +800,10 @@ class Server(object): client.check_aliveness() last_aliveness_check = now - -_alpha = "abcdefghijklmnopqrstuvwxyz" -_ircstring_translation = string.maketrans( - string.upper(_alpha) + "[]\\^", - _alpha + "{}|~") +_maketrans = str.maketrans if sys.version_info[0] == 3 else string.maketrans +_ircstring_translation = _maketrans( + string.ascii_lowercase.upper() + "[]\\^", + string.ascii_lowercase + "{}|~") def irc_lower(s): diff --git a/test.py b/test.py index 4b1c3f7..18dd08c 100644 --- a/test.py +++ b/test.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#! /usr/bin/env python import os import re @@ -44,7 +44,7 @@ class ServerFixture(object): except socket.error: tries_left -= 1 time.sleep(0.01) - self.connections[nick] = s.makefile() + self.connections[nick] = s.makefile(mode="rw") self.send(nick, "NICK %s" % nick) self.send(nick, "USER %s * * %s" % (nick, nick)) self.expect(nick, r":local\S+ 001 %s :.*" % nick) -- cgit v1.2.3