summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorliris <liris.pp@gmail.com>2014-04-08 09:52:25 +0900
committerliris <liris.pp@gmail.com>2014-04-08 09:52:25 +0900
commit43789edb1d32eaab121fde1e0aac3b444ee9f19f (patch)
tree00cfa8bc10e974972faa2a1bcc49094d4b763e70
parent0bc58cae517655a82cd5c33934153611077dacdc (diff)
downloadwebsocket-client-43789edb1d32eaab121fde1e0aac3b444ee9f19f.tar.gz
- #55 for py3
-rw-r--r--README.rst2
-rw-r--r--websocket/__init__.py23
2 files changed, 22 insertions, 3 deletions
diff --git a/README.rst b/README.rst
index ba67912..8067de2 100644
--- a/README.rst
+++ b/README.rst
@@ -129,7 +129,7 @@ ChangeLog
- v0.13.0
- - Controlling fragmentation(ISSUE#55)
+ - Controlling fragmentation(ISSUE#55)
- server certificate validation(ISSUE#56)
- PyPI tarball is missing test_websocket.py(ISSUE#65)
- Payload length encoding bug(ISSUE#58)
diff --git a/websocket/__init__.py b/websocket/__init__.py
index 5067df8..9b6be19 100644
--- a/websocket/__init__.py
+++ b/websocket/__init__.py
@@ -276,7 +276,7 @@ class ABNF(object):
+ " data=" + str(self.data)
@staticmethod
- def create_frame(data, opcode):
+ def create_frame(data, opcode, fin=1):
"""
create frame to send text, binary and other data.
@@ -285,11 +285,13 @@ class ABNF(object):
data value is conveted into unicode string, automatically.
opcode: operation code. please see OPCODE_XXX.
+
+ fin: fin flag. if set to 0, create continue fragmentation.
"""
if opcode == ABNF.OPCODE_TEXT and isinstance(data, str):
data = data.encode("utf-8")
# mask must be set if send data from client
- return ABNF(1, 0, 0, 0, opcode, 1, data)
+ return ABNF(fin, 0, 0, 0, opcode, 1, data)
def format(self):
"""
@@ -562,6 +564,23 @@ class WebSocket(object):
if isinstance(payload, str):
payload = bytes(payload, "utf-8")
frame = ABNF.create_frame(payload, opcode)
+ return self.send_frame(frame)
+
+ def send_frame(self, frame):
+ """
+ Send the data frame.
+
+ frame: frame data created by ABNF.create_frame
+
+ >>> ws = create_connection("ws://echo.websocket.org/")
+ >>> frame = ABNF.create_frame("Hello", ABNF.OPCODE_TEXT)
+ >>> ws.send_frame(frame)
+ >>> cont_frame = ABNF.create_frame("My name is ", ABNF.OPCODE_CONT, 0)
+ >>> ws.send_frame(frame)
+ >>> cont_frame = ABNF.create_frame("Foo Bar", ABNF.OPCODE_CONT, 1)
+ >>> ws.send_frame(frame)
+
+ """
if self.get_mask_key:
frame.get_mask_key = self.get_mask_key
data = frame.format()