1. Arkaitz Jimenez
  2. gevent-websocket

Commits

Arkaitz Jimenez  committed 4184f0a

UTF-8 encoding improved, capable of sending binary now

  • Participants
  • Parent commits 102a461
  • Branches default

Comments (0)

Files changed (1)

File geventwebsocket/websocket.py

View file
  • Ignore whitespace
 from gevent.coros import Semaphore
 import struct
+from codecs import utf_8_encode
+
 
 class WebSocket(object):
     def __init__(self, sock, rfile, environ):
 
     def send(self, message):
 
-        if isinstance(message, unicode):
-            message = message.encode('utf-8')
-        elif isinstance(message, str):
-            message = unicode(message).encode('utf-8')
-        else:
-            raise Exception("Invalid message encoding")
-
+        message = utf_8_encode(unicode(message, 'latin-1'))[0] 
         msglen = len(message)
         frameheader = 0x81
         maskbit = 0