Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
wspy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
wspy
Commits
bd447183
Commit
bd447183
authored
Nov 02, 2013
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed some function/class names for clarity
parent
09bf4463
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
12 deletions
+12
-12
frame.py
frame.py
+12
-12
No files found.
frame.py
View file @
bd447183
...
@@ -195,7 +195,7 @@ class ControlFrame(Frame):
...
@@ -195,7 +195,7 @@ class ControlFrame(Frame):
def
decode_frame
(
reader
):
def
decode_frame
(
reader
):
b1
,
b2
=
struct
.
unpack
(
'!BB'
,
reader
.
re
cv
n
(
2
))
b1
,
b2
=
struct
.
unpack
(
'!BB'
,
reader
.
re
ad
n
(
2
))
final
=
bool
(
b1
&
0x80
)
final
=
bool
(
b1
&
0x80
)
rsv1
=
bool
(
b1
&
0x40
)
rsv1
=
bool
(
b1
&
0x40
)
...
@@ -207,16 +207,16 @@ def decode_frame(reader):
...
@@ -207,16 +207,16 @@ def decode_frame(reader):
payload_len
=
b2
&
0x7F
payload_len
=
b2
&
0x7F
if
payload_len
==
126
:
if
payload_len
==
126
:
payload_len
=
struct
.
unpack
(
'!H'
,
reader
.
re
cv
n
(
2
))
payload_len
=
struct
.
unpack
(
'!H'
,
reader
.
re
ad
n
(
2
))
elif
payload_len
==
127
:
elif
payload_len
==
127
:
payload_len
=
struct
.
unpack
(
'!Q'
,
reader
.
re
cv
n
(
8
))
payload_len
=
struct
.
unpack
(
'!Q'
,
reader
.
re
ad
n
(
8
))
if
masked
:
if
masked
:
masking_key
=
reader
.
re
cv
n
(
4
)
masking_key
=
reader
.
re
ad
n
(
4
)
payload
=
mask
(
masking_key
,
reader
.
re
cv
n
(
payload_len
))
payload
=
mask
(
masking_key
,
reader
.
re
ad
n
(
payload_len
))
else
:
else
:
masking_key
=
''
masking_key
=
''
payload
=
reader
.
re
cv
n
(
payload_len
)
payload
=
reader
.
re
ad
n
(
payload_len
)
# Control frames have most significant bit 1
# Control frames have most significant bit 1
cls
=
ControlFrame
if
opcode
&
0x8
else
Frame
cls
=
ControlFrame
if
opcode
&
0x8
else
Frame
...
@@ -226,11 +226,11 @@ def decode_frame(reader):
...
@@ -226,11 +226,11 @@ def decode_frame(reader):
def
receive_frame
(
sock
):
def
receive_frame
(
sock
):
return
decode_frame
(
BlockingSocket
(
sock
))
return
decode_frame
(
SocketReader
(
sock
))
def
read_frame
(
data
):
def
read_frame
(
data
):
reader
=
Buffer
ed
Reader
(
data
)
reader
=
BufferReader
(
data
)
frame
=
decode_frame
(
reader
)
frame
=
decode_frame
(
reader
)
return
frame
,
len
(
data
)
-
reader
.
offset
return
frame
,
len
(
data
)
-
reader
.
offset
...
@@ -239,22 +239,22 @@ def pop_frame(data):
...
@@ -239,22 +239,22 @@ def pop_frame(data):
frame
,
l
=
read_frame
(
data
)
frame
,
l
=
read_frame
(
data
)
class
Buffer
ed
Reader
(
object
):
class
BufferReader
(
object
):
def
__init__
(
self
,
data
):
def
__init__
(
self
,
data
):
self
.
data
=
data
self
.
data
=
data
self
.
offset
=
0
self
.
offset
=
0
def
re
cv
n
(
self
,
n
):
def
re
ad
n
(
self
,
n
):
assert
len
(
self
.
data
)
-
self
.
offset
>=
n
assert
len
(
self
.
data
)
-
self
.
offset
>=
n
self
.
offset
+=
n
self
.
offset
+=
n
return
self
.
data
[
self
.
offset
-
n
:
self
.
offset
]
return
self
.
data
[
self
.
offset
-
n
:
self
.
offset
]
class
BlockingSocket
(
object
):
class
SocketReader
(
object
):
def
__init__
(
self
,
sock
):
def
__init__
(
self
,
sock
):
self
.
sock
=
sock
self
.
sock
=
sock
def
re
cv
n
(
self
,
n
):
def
re
ad
n
(
self
,
n
):
"""
"""
Keep receiving data until exactly `n` bytes have been read.
Keep receiving data until exactly `n` bytes have been read.
"""
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment