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
c7572ccb
Commit
c7572ccb
authored
Nov 07, 2012
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved frame masking accessibily in various high-level functions
parent
53d9f210
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
9 deletions
+16
-9
connection.py
connection.py
+3
-3
frame.py
frame.py
+11
-4
message.py
message.py
+2
-2
No files found.
connection.py
View file @
c7572ccb
...
...
@@ -28,16 +28,16 @@ class Connection(object):
self
.
onopen
()
def
send
(
self
,
message
,
fragment_size
=
None
):
def
send
(
self
,
message
,
fragment_size
=
None
,
mask
=
False
):
"""
Send a message. If `fragment_size` is specified, the message is
fragmented into multiple frames whose payload size does not extend
`fragment_size`.
"""
if
fragment_size
is
None
:
self
.
sock
.
send
(
message
.
frame
())
self
.
sock
.
send
(
message
.
frame
(
mask
=
mask
))
else
:
self
.
sock
.
send
(
*
message
.
fragment
(
fragment_size
))
self
.
sock
.
send
(
*
message
.
fragment
(
fragment_size
,
mask
=
mask
))
def
receive
(
self
):
"""
...
...
frame.py
View file @
c7572ccb
...
...
@@ -28,8 +28,8 @@ class Frame(object):
To encoding a frame for sending it over a socket, use Frame.pack(). To
receive and decode a frame from a socket, use receive_frame().
"""
def
__init__
(
self
,
opcode
,
payload
,
masking_key
=
''
,
final
=
True
,
rsv1
=
Fals
e
,
rsv2
=
False
,
rsv3
=
False
):
def
__init__
(
self
,
opcode
,
payload
,
masking_key
=
''
,
mask
=
False
,
final
=
Tru
e
,
rsv
1
=
False
,
rsv
2
=
False
,
rsv3
=
False
):
"""
Create a new frame.
...
...
@@ -37,12 +37,19 @@ class Frame(object):
`payload` is a string of bytes containing the data sendt in the frame.
`masking_key` is an optional custom key to use for masking, or `mask`
can be used instead to let this constructor generate a random masking
key.
`final` is a boolean indicating whether this frame is the last in a
chain of fragments.
`rsv1`, `rsv2` and `rsv3` are booleans indicating bit values for RSV1,
RVS2 and RSV3, which are only non-zero if defined so by extensions.
"""
if
mask
:
masking_key
=
urandom
(
4
)
if
len
(
masking_key
)
not
in
(
0
,
4
):
raise
ValueError
(
'invalid masking key "%s"'
%
masking_key
)
...
...
@@ -122,8 +129,8 @@ class Frame(object):
for
start
in
range
(
0
,
len
(
self
.
payload
),
fragment_size
):
payload
=
self
.
payload
[
start
:
start
+
fragment_size
]
key
=
urandom
(
4
)
if
mask
else
''
frames
.
append
(
Frame
(
OPCODE_CONTINUATION
,
payload
,
key
,
False
))
frames
.
append
(
Frame
(
OPCODE_CONTINUATION
,
payload
,
mask
=
mask
,
final
=
False
))
frames
[
0
].
opcode
=
self
.
opcode
frames
[
-
1
].
final
=
True
...
...
message.py
View file @
c7572ccb
...
...
@@ -9,8 +9,8 @@ class Message(object):
self
.
opcode
=
opcode
self
.
payload
=
payload
def
frame
(
self
):
return
Frame
(
self
.
opcode
,
self
.
payload
)
def
frame
(
self
,
mask
=
False
):
return
Frame
(
self
.
opcode
,
self
.
payload
,
mask
=
mask
)
def
fragment
(
self
,
fragment_size
,
mask
=
False
):
return
self
.
frame
().
fragment
(
fragment_size
,
mask
)
...
...
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