aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2016-01-27 12:06:48 -0500
committerEric S. Raymond <esr@thyrsus.com>2016-01-27 12:06:48 -0500
commit05f6b5b121086b12d255359c3585c3fa83510ded (patch)
tree6b3cf17a43d4313920a2d8293fa18dcb2b6cb524
parentTypo fix. (diff)
downloadirker-05f6b5b121086b12d255359c3585c3fa83510ded.tar.xz
Port to Python 3.
-rw-r--r--NEWS3
-rwxr-xr-xirk6
-rwxr-xr-xirkerd24
-rwxr-xr-xirkerhook.py2
4 files changed, 19 insertions, 16 deletions
diff --git a/NEWS b/NEWS
index c716f9f..ea57739 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,8 @@
irker history
+Repository head:
+ irkerd and irk have been moved to Python 3 (but irkerhook.py left in Python 2).
+
2.15: 2016-01-12
Emergency backout of getaddrinfo, it randomly hangs.
diff --git a/irk b/irk
index 214010e..6835e97 100755
--- a/irk
+++ b/irk
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# Illustrates how to test irkerd.
#
# First argument must be a channel URL. If it does not begin with "irc",
@@ -21,7 +21,7 @@ def connect(server = DEFAULT_SERVER):
def send(s, target, message):
data = {"to": target, "privmsg" : message}
#print(json.dumps(data))
- s.sendall(json.dumps(data))
+ s.sendall(bytes(json.dumps(data), "ascii"))
def irk(target, message, server = DEFAULT_SERVER):
s = connect(server)
@@ -38,7 +38,7 @@ def main():
target = sys.argv[1]
message = " ".join(sys.argv[2:])
# XXX: why is this necessary?
- message = message.decode('string_escape')
+ #message = message.decode('string_escape')
try:
irk(target, message)
diff --git a/irkerd b/irkerd
index c13aae7..9e04358 100755
--- a/irkerd
+++ b/irkerd
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
"""
irkerd - a simple IRC multiplexer daemon
@@ -21,8 +21,8 @@ Requires Python 2.7, or:
"""
# SPDX-License-Identifier: BSD-2-Clause
-from __future__ import unicode_literals
-from __future__ import with_statement
+
+
# These things might need tuning
@@ -53,7 +53,7 @@ import os.path
try: # Python 3
import queue
except ImportError: # Python 2
- import Queue as queue
+ import queue as queue
import random
import re
import select
@@ -62,7 +62,7 @@ import socket
try: # Python 3
import socketserver
except ImportError: # Python 2
- import SocketServer as socketserver
+ import socketserver as socketserver
import ssl
import sys
import threading
@@ -71,7 +71,7 @@ import traceback
try: # Python 3
import urllib.parse as urllib_parse
except ImportError: # Python 2
- import urlparse as urllib_parse
+ import urllib.parse as urllib_parse
LOG = logging.getLogger(__name__)
@@ -79,7 +79,7 @@ LOG.setLevel(logging.ERROR)
LOG_LEVELS = ['critical', 'error', 'warning', 'info', 'debug']
try: # Python 2
- UNICODE_TYPE = unicode
+ UNICODE_TYPE = str
except NameError: # Python 3
UNICODE_TYPE = str
@@ -745,7 +745,7 @@ class Dispatcher:
# scavenged.
ancients = []
for connection in connections:
- for (chan, age) in connections.channels_joined.items():
+ for (chan, age) in list(connections.channels_joined.items()):
if age < time.time() - CHANNEL_TTL:
ancients.append((connection, chan, age))
if ancients:
@@ -848,13 +848,13 @@ class Irker:
"Log all messages when in watcher mode."
if self.logfile:
with open(self.logfile, "ab") as logfp:
- message = u"%03f|%s|%s\n" % \
+ message = "%03f|%s|%s\n" % \
(time.time(), event.source, event.arguments[0])
logfp.write(message.encode('utf-8'))
def pending(self):
"Do we have any pending message traffic?"
- return [k for (k, v) in self.servers.items() if v.pending()]
+ return [k for (k, v) in list(self.servers.items()) if v.pending()]
def _parse_request(self, line):
"Request-parsing helper for the handle() method"
@@ -901,7 +901,7 @@ class Irker:
self.servers[target.server()].dispatch(
target.channel, message, target.key, quit_after=quit_after)
# GC dispatchers with no active connections
- servernames = self.servers.keys()
+ servernames = list(self.servers.keys())
for servername in servernames:
if not self.servers[servername].live():
del self.servers[servername]
@@ -918,7 +918,7 @@ class Irker:
# that message activity is likely to be clumpy.
if len(self.servers) >= CONNECTION_MAX:
oldest = min(
- self.servers.keys(),
+ list(self.servers.keys()),
key=lambda name: self.servers[name].last_xmit())
del self.servers[oldest]
except InvalidRequest as e:
diff --git a/irkerhook.py b/irkerhook.py
index 7b727f2..2795dc4 100755
--- a/irkerhook.py
+++ b/irkerhook.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python2
# Copyright (c) 2012 Eric S. Raymond <esr@thyrsus.com>
# Distributed under BSD terms.
#