Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Attempt some basic python3 compatability.

  • Loading branch information...
commit f2d60c6653815a5da8a011fd778110954fc67bca 1 parent 56e5c8b
Ryan Kelly authored September 08, 2012
8  playitagainsam/eventlog.py
@@ -9,6 +9,9 @@
9 9
 
10 10
 import json
11 11
 
  12
+import six
  13
+
  14
+
12 15
 
13 16
 class EventLog(object):
14 17
 
@@ -32,6 +35,11 @@ def close(self):
32 35
 
33 36
     def write_event(self, event):
34 37
         # Append an event to the event log.
  38
+        # Since we'll be writing JSON, we need to ensure serializability.
  39
+        if six.PY3 and "data" in event:
  40
+            data = event["data"]
  41
+            if isinstance(data, six.binary_type):
  42
+                event["data"] = data.decode("ascii")
35 43
         # We try to do some basic simplifications.
36 44
         # Collapse consecutive "PAUSE" events into a single pause.
37 45
         if event["act"] == "PAUSE":
10  playitagainsam/player.py
@@ -9,6 +9,8 @@
9 9
 
10 10
 import time
11 11
 
  12
+import six
  13
+
12 14
 from playitagainsam.util import forkexec, get_default_terminal
13 15
 from playitagainsam.util import get_pias_script, set_terminal_size
14 16
 from playitagainsam.coordinator import SocketCoordinator, proxy_to_coordinator
@@ -18,7 +20,7 @@
18 20
 
19 21
 class Player(SocketCoordinator):
20 22
 
21  
-    waypoint_chars = ("\n", "\r")
  23
+    waypoint_chars = (six.b("\n"), six.b("\r"))
22 24
 
23 25
     def __init__(self, sock_path, eventlog, terminal=None):
24 26
         super(Player, self).__init__(sock_path)
@@ -73,6 +75,8 @@ def _do_close_terminal(self, term):
73 75
         view_sock.close()
74 76
 
75 77
     def _do_read(self, term, wanted):
  78
+        if isinstance(wanted, six.text_type):
  79
+            wanted = wanted.encode("ascii")
76 80
         view_sock = self.terminals[term][0]
77 81
         c = view_sock.recv(1)
78 82
         if wanted in self.waypoint_chars:
@@ -81,7 +85,9 @@ def _do_read(self, term, wanted):
81 85
 
82 86
     def _do_write(self, term, data):
83 87
         view_sock = self.terminals[term][0]
84  
-        view_sock.sendall(data.encode('utf8'))
  88
+        if isinstance(data, six.text_type):
  89
+            data = data.encode("utf8")
  90
+        view_sock.sendall(data)
85 91
 
86 92
 
87 93
 def join_player(sock_path, **kwds):
2  setup.py
@@ -77,7 +77,7 @@
77 77
       keywords=KEYWORDS,
78 78
       packages=["playitagainsam"],
79 79
       scripts=["scripts/pias"],
80  
-      install_requires=["psutil"],
  80
+      install_requires=["psutil", "six"],
81 81
       classifiers=CLASSIFIERS,
82 82
       **setup_kwds
83 83
      )

0 notes on commit f2d60c6

Please sign in to comment.
Something went wrong with that request. Please try again.