diff options
authorEric S. Raymond <esr@thyrsus.com>2016-03-25 19:25:08 +0000
committerEric S. Raymond <esr@thyrsus.com>2016-03-25 19:25:08 +0000
commit86178b064eadeba1d04bb0992b8bcfd65877f063 (patch)
parentVersion bump for release 2.17. (diff)
parentFix irk for Python 3 and Unicode input (diff)
Merge branch 'master' into 'master'
Fix irk for Python 3 and Unicode input There were several issues: - json.dumps does not have an encoding parameter in Python 3. - Forcing the json.dumps encoding to ASCII prevents any non-ASCII character in the message. To avoid having non-ASCII characters in the *dump*, the only needed parameter is ensure_ascii=True which is the default. - To coerce a str to bytes in Python 3, an encoding must be provided even when it only contains ASCII characters. The solution is to use the encode() method which is available in both versions. See merge request !7
1 files changed, 4 insertions, 2 deletions
diff --git a/irk b/irk
index a51eacf..f95febd 100755
--- a/irk
+++ b/irk
@@ -20,8 +20,10 @@ def connect(server = DEFAULT_SERVER):
def send(s, target, message):
data = {"to": target, "privmsg" : message}
- #print(json.dumps(data))
- s.sendall(bytes(json.dumps(data, encoding="ascii")))
+ dump = json.dumps(data)
+ if not isinstance(dump, bytes):
+ dump = dump.encode('ascii')
+ s.sendall(dump)
def irk(target, message, server = DEFAULT_SERVER):
s = connect(server)