mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
Port websocket examples to Python 3 (#2371)
This commit is contained in:
parent
e60a5591b0
commit
7e16d13011
@ -250,7 +250,7 @@ class WebSocket(object):
|
|||||||
data = struct.unpack('<I', buf[f['hlen']:f['hlen']+4])[0]
|
data = struct.unpack('<I', buf[f['hlen']:f['hlen']+4])[0]
|
||||||
of1 = f['hlen']+4
|
of1 = f['hlen']+4
|
||||||
b = ''
|
b = ''
|
||||||
for i in xrange(0, int(f['length']/4)):
|
for i in range(0, int(f['length']/4)):
|
||||||
mask = struct.unpack('<I', buf[of1+4*i:of1+4*(i+1)])[0]
|
mask = struct.unpack('<I', buf[of1+4*i:of1+4*(i+1)])[0]
|
||||||
b += struct.pack('I', data ^ mask)
|
b += struct.pack('I', data ^ mask)
|
||||||
|
|
||||||
@ -292,10 +292,8 @@ class WebSocket(object):
|
|||||||
|
|
||||||
As per the dataframing section (5.3) for the websocket spec
|
As per the dataframing section (5.3) for the websocket spec
|
||||||
"""
|
"""
|
||||||
if isinstance(message, unicode):
|
if isinstance(message, str):
|
||||||
message = message.encode('utf-8')
|
message = message.encode('utf-8')
|
||||||
elif not isinstance(message, str):
|
|
||||||
message = str(message)
|
|
||||||
packed = "\x00%s\xFF" % message
|
packed = "\x00%s\xFF" % message
|
||||||
return packed
|
return packed
|
||||||
|
|
||||||
|
|||||||
@ -251,7 +251,7 @@ class WebSocket(object):
|
|||||||
data = struct.unpack('<I', buf[f['hlen']:f['hlen']+4])[0]
|
data = struct.unpack('<I', buf[f['hlen']:f['hlen']+4])[0]
|
||||||
of1 = f['hlen']+4
|
of1 = f['hlen']+4
|
||||||
b = ''
|
b = ''
|
||||||
for i in xrange(0, int(f['length']/4)):
|
for i in range(0, int(f['length']/4)):
|
||||||
mask = struct.unpack('<I', buf[of1+4*i:of1+4*(i+1)])[0]
|
mask = struct.unpack('<I', buf[of1+4*i:of1+4*(i+1)])[0]
|
||||||
b += struct.pack('I', data ^ mask)
|
b += struct.pack('I', data ^ mask)
|
||||||
|
|
||||||
@ -293,10 +293,8 @@ class WebSocket(object):
|
|||||||
|
|
||||||
As per the dataframing section (5.3) for the websocket spec
|
As per the dataframing section (5.3) for the websocket spec
|
||||||
"""
|
"""
|
||||||
if isinstance(message, unicode):
|
if isinstance(message, str):
|
||||||
message = message.encode('utf-8')
|
message = message.encode('utf-8')
|
||||||
elif not isinstance(message, str):
|
|
||||||
message = str(message)
|
|
||||||
packed = "\x00%s\xFF" % message
|
packed = "\x00%s\xFF" % message
|
||||||
return packed
|
return packed
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user