- fixed #55
This commit is contained in:
@@ -130,6 +130,7 @@ ChangeLog
|
|||||||
|
|
||||||
- v0.13.0
|
- v0.13.0
|
||||||
|
|
||||||
|
- Controlling fragmentation(ISSUE#55)
|
||||||
- server certificate validation(ISSUE#56)
|
- server certificate validation(ISSUE#56)
|
||||||
- PyPI tarball is missing test_websocket.py(ISSUE#65)
|
- PyPI tarball is missing test_websocket.py(ISSUE#65)
|
||||||
- Payload length encoding bug(ISSUE#58)
|
- Payload length encoding bug(ISSUE#58)
|
||||||
|
|||||||
@@ -277,7 +277,7 @@ class ABNF(object):
|
|||||||
+ " data=" + str(self.data)
|
+ " data=" + str(self.data)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create_frame(data, opcode):
|
def create_frame(data, opcode, fin=1):
|
||||||
"""
|
"""
|
||||||
create frame to send text, binary and other data.
|
create frame to send text, binary and other data.
|
||||||
|
|
||||||
@@ -286,11 +286,13 @@ class ABNF(object):
|
|||||||
data value is conveted into unicode string, automatically.
|
data value is conveted into unicode string, automatically.
|
||||||
|
|
||||||
opcode: operation code. please see OPCODE_XXX.
|
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, unicode):
|
if opcode == ABNF.OPCODE_TEXT and isinstance(data, unicode):
|
||||||
data = data.encode("utf-8")
|
data = data.encode("utf-8")
|
||||||
# mask must be set if send data from client
|
# 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):
|
def format(self):
|
||||||
"""
|
"""
|
||||||
@@ -562,6 +564,20 @@ class WebSocket(object):
|
|||||||
return self.send_frame(frame)
|
return self.send_frame(frame)
|
||||||
|
|
||||||
def send_frame(self, 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:
|
if self.get_mask_key:
|
||||||
frame.get_mask_key = self.get_mask_key
|
frame.get_mask_key = self.get_mask_key
|
||||||
data = frame.format()
|
data = frame.format()
|
||||||
|
|||||||
Reference in New Issue
Block a user