aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Bachelier <laurent@bachelier.name>2016-03-25 17:52:59 +0100
committerLaurent Bachelier <laurent@bachelier.name>2016-03-25 17:52:59 +0100
commit0764f07ce26e097039937035a26068c7dc74996c (patch)
tree7bfe4e205f5688d2718a625987ed00fb067f9c55
parentVersion bump for release 2.17. (diff)
downloadirker-0764f07ce26e097039937035a26068c7dc74996c.tar.xz
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.
-rwxr-xr-xirk6
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)