Skip to content

Commit 3b5e210

Browse files
author
Tony Crisci
committed
python2 fixes
1 parent 0b26ca3 commit 3b5e210

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

i3ipc/i3ipc.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python3
22

3+
import sys
34
import errno
45
import struct
56
import json
@@ -12,6 +13,8 @@
1213
from threading import Timer, Lock
1314
import time
1415

16+
python2 = sys.version_info[0] < 3
17+
1518

1619
class MessageType(Enum):
1720
COMMAND = 0
@@ -471,10 +474,15 @@ def _wait_for_socket(self):
471474
return socket_path_exists
472475

473476
def message(self, message_type, payload):
477+
if python2:
478+
ErrorType = IOError
479+
else:
480+
ErrorType = ConnectionError
481+
474482
try:
475483
self.cmd_lock.acquire()
476484
return self._ipc_send(self.cmd_socket, message_type, payload)
477-
except BrokenPipeError as e:
485+
except ErrorType as e:
478486
if not self.auto_reconnect:
479487
raise (e)
480488

test/test_get_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from ipctest import IpcTest
22
import i3ipc
3-
3+
import io
44

55
class TestGetConfig(IpcTest):
66
def test_get_config(self, i3):
77
config = i3.get_config()
88
assert isinstance(config, i3ipc.ConfigReply)
9-
with open('test/i3.config') as f:
9+
with io.open('test/i3.config', 'r', encoding='utf-8') as f:
1010
assert config.config == f.read()

test/test_get_marks.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# coding=utf-8
2+
from __future__ import unicode_literals
3+
14
from ipctest import IpcTest
25
import i3ipc
36

0 commit comments

Comments
 (0)