parent
573f9279da
commit
de41919272
11
README.rst
11
README.rst
@ -14,19 +14,19 @@ License
|
||||
Installation
|
||||
=============
|
||||
|
||||
This module is tested on only Python 2.7.
|
||||
This module is tested on Python 2.7 and Python 3.x.
|
||||
|
||||
Type "python setup.py install" or "pip install websocket-client" to install.
|
||||
|
||||
This module depend on
|
||||
|
||||
- backports.ssl_match_hostname
|
||||
- six
|
||||
- backports.ssl_match_hostname for Python 2.x
|
||||
|
||||
How about Python 3
|
||||
===========================
|
||||
|
||||
py3( https://github.com/liris/websocket-client/tree/py3 ) branch is for python 3.3. Every test case is passed.
|
||||
If you are using python3, please check it.
|
||||
Now, we support python 3 on single source code from version 0.14.0. Thanks, @battlemidge.
|
||||
|
||||
Example
|
||||
============
|
||||
@ -128,6 +128,9 @@ example::
|
||||
ChangeLog
|
||||
============
|
||||
|
||||
- v0.14.0
|
||||
- Support python 3(#73)
|
||||
|
||||
- v0.13.0
|
||||
|
||||
- MemoryError when receiving large amount of data (~60 MB) at once(ISSUE#59)
|
||||
|
9
setup.py
9
setup.py
@ -1,7 +1,11 @@
|
||||
from setuptools import setup
|
||||
import sys
|
||||
|
||||
VERSION = "0.14.0"
|
||||
|
||||
install_requires = ["six"]
|
||||
if sys.version_info.major == 2:
|
||||
install_requires.append('backports.ssl_match_hostname')
|
||||
|
||||
setup(
|
||||
name="websocket-client",
|
||||
@ -25,10 +29,7 @@ setup(
|
||||
],
|
||||
keywords='websockets',
|
||||
scripts=["bin/wsdump.py"],
|
||||
install_requires=[
|
||||
'backports.ssl_match_hostname',
|
||||
'six',
|
||||
],
|
||||
install_requires=install_requires,
|
||||
packages=["tests", "websocket"],
|
||||
package_data={
|
||||
'tests': ['data/*.txt'],
|
||||
|
@ -20,15 +20,8 @@ import uuid
|
||||
# websocket-client
|
||||
import websocket as ws
|
||||
|
||||
# There are three tests to test the library's behaviour when the received
|
||||
# message is fragmented (please see [1] for details). They fail currently as
|
||||
# the library doesn't yet support fragmentation. Therefore the tests are
|
||||
# skipped unless the flag below is set.
|
||||
#
|
||||
# [1]: https://tools.ietf.org/html/rfc6455#section-5.4
|
||||
# "RFC6455: 5.4. Fragmentation"
|
||||
#
|
||||
TEST_WITH_INTERNET = False
|
||||
# Skip test to access the internet.
|
||||
TEST_WITH_INTERNET = True
|
||||
|
||||
TRACABLE = False
|
||||
|
||||
@ -226,12 +219,11 @@ class WebSocketTest(unittest.TestCase):
|
||||
something = six.b("\x81\x8fabcd\x82\xe3\xf0\x87\xe3\xf1\x80\xe5\xca\x81\xe2\xc5\x82\xe3\xcc")
|
||||
s.add_packet(something)
|
||||
data = sock.recv()
|
||||
data = data.decode('utf-8')
|
||||
self.assertEquals(data, u"こんにちは")
|
||||
self.assertEquals(data, "こんにちは")
|
||||
|
||||
s.add_packet(six.b("\x81\x85abcd)\x07\x0f\x08\x0e"))
|
||||
data = sock.recv()
|
||||
self.assertEquals(data.decode('utf-8'), "Hello")
|
||||
self.assertEquals(data, "Hello")
|
||||
|
||||
def testInternalRecvStrict(self):
|
||||
sock = ws.WebSocket()
|
||||
@ -246,7 +238,7 @@ class WebSocketTest(unittest.TestCase):
|
||||
with self.assertRaises(SSLError):
|
||||
data = sock._recv_strict(9)
|
||||
data = sock._recv_strict(9)
|
||||
self.assertEquals(data.decode('utf-8'), "foobarbaz")
|
||||
self.assertEquals(data, six.b("foobarbaz"))
|
||||
with self.assertRaises(ws.WebSocketConnectionClosedException):
|
||||
data = sock._recv_strict(1)
|
||||
|
||||
@ -263,7 +255,7 @@ class WebSocketTest(unittest.TestCase):
|
||||
with self.assertRaises(ws.WebSocketTimeoutException):
|
||||
data = sock.recv()
|
||||
data = sock.recv()
|
||||
self.assertEquals(data.decode('utf-8'), "Hello, World!")
|
||||
self.assertEquals(data, "Hello, World!")
|
||||
with self.assertRaises(ws.WebSocketConnectionClosedException):
|
||||
data = sock.recv()
|
||||
|
||||
@ -275,7 +267,7 @@ class WebSocketTest(unittest.TestCase):
|
||||
# OPCODE=CONT, FIN=1, MSG="the soul of wit"
|
||||
s.add_packet(six.b("\x80\x8fabcd\x15\n\x06D\x12\r\x16\x08A\r\x05D\x16\x0b\x17"))
|
||||
data = sock.recv()
|
||||
self.assertEqual(data.decode('utf-8'), "Brevity is the soul of wit")
|
||||
self.assertEqual(data, "Brevity is the soul of wit")
|
||||
with self.assertRaises(ws.WebSocketConnectionClosedException):
|
||||
sock.recv()
|
||||
|
||||
@ -299,7 +291,7 @@ class WebSocketTest(unittest.TestCase):
|
||||
s.add_packet(six.b("\x80\x89abcd\x0e\x0c\x00\x01A\x0f\x0c\x16\x04"))
|
||||
data = sock.recv()
|
||||
self.assertEqual(
|
||||
data.decode('utf-8'),
|
||||
data,
|
||||
"Once more unto the breach, dear friends, once more")
|
||||
with self.assertRaises(ws.WebSocketConnectionClosedException):
|
||||
sock.recv()
|
||||
@ -316,7 +308,7 @@ class WebSocketTest(unittest.TestCase):
|
||||
s.add_packet(six.b("\x80\x8fabcd\x0e\x04C\x05A\x05\x0c\x0b\x05B\x17\x0c" \
|
||||
"\x08\x0c\x04"))
|
||||
data = sock.recv()
|
||||
self.assertEqual(data.decode('utf-8'), "Too much of a good thing")
|
||||
self.assertEqual(data, "Too much of a good thing")
|
||||
with self.assertRaises(ws.WebSocketConnectionClosedException):
|
||||
sock.recv()
|
||||
self.assertEqual(
|
||||
@ -329,11 +321,11 @@ class WebSocketTest(unittest.TestCase):
|
||||
self.assertNotEquals(s, None)
|
||||
s.send("Hello, World")
|
||||
result = s.recv()
|
||||
self.assertEquals(result.decode('utf-8'), "Hello, World")
|
||||
self.assertEquals(result, "Hello, World")
|
||||
|
||||
s.send(u"こにゃにゃちは、世界")
|
||||
result = s.recv()
|
||||
self.assertEquals(result.decode('utf-8'), u"こにゃにゃちは、世界")
|
||||
self.assertEquals(result, "こにゃにゃちは、世界")
|
||||
s.close()
|
||||
|
||||
@unittest.skipUnless(TEST_WITH_INTERNET, "Internet-requiring tests are disabled")
|
||||
@ -353,10 +345,10 @@ class WebSocketTest(unittest.TestCase):
|
||||
self.assert_(isinstance(s.sock, ssl.SSLSocket))
|
||||
s.send("Hello, World")
|
||||
result = s.recv()
|
||||
self.assertEquals(result.decode('utf-8'), "Hello, World")
|
||||
self.assertEquals(result, "Hello, World")
|
||||
s.send(u"こにゃにゃちは、世界")
|
||||
result = s.recv()
|
||||
self.assertEquals(result.decode('utf-8'), u"こにゃにゃちは、世界")
|
||||
self.assertEquals(result, "こにゃにゃちは、世界")
|
||||
s.close()
|
||||
#except:
|
||||
# pass
|
||||
@ -368,7 +360,7 @@ class WebSocketTest(unittest.TestCase):
|
||||
self.assertNotEquals(s, None)
|
||||
s.send("Hello, World")
|
||||
result = s.recv()
|
||||
self.assertEquals(result.decode('utf-8'), "Hello, World")
|
||||
self.assertEquals(result, "Hello, World")
|
||||
s.close()
|
||||
|
||||
@unittest.skipUnless(TEST_WITH_INTERNET, "Internet-requiring tests are disabled")
|
||||
|
@ -372,6 +372,7 @@ class ABNF(object):
|
||||
_d = array.array("B", data)
|
||||
for i in range(len(_d)):
|
||||
_d[i] ^= _m[i % 4]
|
||||
|
||||
return _d.tostring()
|
||||
|
||||
|
||||
@ -656,6 +657,8 @@ class WebSocket(object):
|
||||
return value: string(byte array) value.
|
||||
"""
|
||||
opcode, data = self.recv_data()
|
||||
if six.PY3 and opcode == ABNF.OPCODE_TEXT:
|
||||
return data.decode("utf-8")
|
||||
return data
|
||||
|
||||
def recv_data(self, control_frame=False):
|
||||
@ -787,6 +790,7 @@ class WebSocket(object):
|
||||
self._frame_header = None
|
||||
self._frame_length = None
|
||||
self._frame_mask = None
|
||||
|
||||
return ABNF(fin, rsv1, rsv2, rsv3, opcode, has_mask, payload)
|
||||
|
||||
|
||||
@ -865,6 +869,7 @@ class WebSocket(object):
|
||||
raise WebSocketTimeoutException(message)
|
||||
else:
|
||||
raise
|
||||
|
||||
if not bytes:
|
||||
raise WebSocketConnectionClosedException()
|
||||
return bytes
|
||||
|
Loading…
x
Reference in New Issue
Block a user