Skip to content

Commit

Permalink
Fixed unicode errors and added Linux and OSX keymappings
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Zook committed Nov 2, 2012
1 parent 10ee7f0 commit 39163b5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
7 changes: 7 additions & 0 deletions Default (Linux).sublime-keymap
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{ "keys": ["ctrl+alt+c"], "command": "collab_connect_to_server" },
{ "keys": ["ctrl+alt+d"], "command": "collab_disconnect_from_server" },
{ "keys": ["ctrl+alt+o"], "command": "collab_open_document" },
{ "keys": ["ctrl+alt+s"], "command": "collab_toggle_server" },
{ "keys": ["ctrl+alt+a"], "command": "collab_add_current_document" }
]
7 changes: 7 additions & 0 deletions Default (OSX).sublime-keymap
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{ "keys": ["command+alt+c"], "command": "collab_connect_to_server" },
{ "keys": ["command+alt+d"], "command": "collab_disconnect_from_server" },
{ "keys": ["command+alt+o"], "command": "collab_open_document" },
{ "keys": ["command+alt+s"], "command": "collab_toggle_server" },
{ "keys": ["command+alt+a"], "command": "collab_add_current_document" }
]
19 changes: 8 additions & 11 deletions collab/connection.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import json, threading, socket, base64, hashlib



def unicode_to_str(obj):
return dict((str(x) if isinstance(x, unicode) else x, str(y) if isinstance(y, unicode) else y) for x, y in obj.iteritems())



class ClientSocket(threading.Thread):
def __init__(self, host, port):
threading.Thread.__init__(self)
Expand Down Expand Up @@ -41,7 +34,9 @@ def emit(self, event, *args):
def send(self, data):
#print('Sending:{0}'.format(data))
msg = json.dumps(data)
self.sock.send("0"*(10-len(str(len(msg))))+str(len(msg))+msg)

#A pretty terrible hacky framing system, I'll need to come up with a better one soon
self.sock.send(u"0"*(10-len(unicode(len(msg))))+unicode(len(msg))+msg)

def close(self):
self.keep_running = False
Expand All @@ -66,7 +61,7 @@ def run(self):
if self.target_size:
self.saved_data += data
if len(self.saved_data) == self.target_size:
self.emit('message', json.loads(data, object_hook=unicode_to_str))
self.emit('message', json.loads(data, "utf-8"))
self.saved_data = ''
self.target_size = None
else:
Expand Down Expand Up @@ -125,7 +120,7 @@ def run(self):
if self.target_size:
self.saved_data += data
if len(self.saved_data) == self.target_size:
self.emit('message', json.loads(data, object_hook=unicode_to_str))
self.emit('message', json.loads(data, "utf-8"))
self.saved_data = ''
self.target_size = None
else:
Expand All @@ -143,7 +138,9 @@ def send(self, data):
if not self._ready: return
#print('Sending to {0}:{1}'.format(self.address, msg))
msg = json.dumps(data)
self.sock.send("0"*(10-len(str(len(msg))))+str(len(msg))+msg)

#A pretty terrible hacky framing system, I'll need to come up with a better one soon
self.sock.send(u"0"*(10-len(unicode(len(msg))))+unicode(len(msg))+msg)

def ready(self):
return self._ready
Expand Down

0 comments on commit 39163b5

Please sign in to comment.