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
9d12f4e5
Commit
9d12f4e5
authored
Aug 18, 2013
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added draft for extensions implementation
parent
c1bcd852
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
88 additions
and
0 deletions
+88
-0
extension.py
extension.py
+88
-0
No files found.
extension.py
0 → 100644
View file @
9d12f4e5
from
errors
import
HandshakeError
class
Extension
(
object
):
rsv1
=
False
rsv2
=
False
rsv3
=
False
opcodes
=
[]
parameters
=
[]
def
__init__
(
self
,
**
kwargs
):
for
param
in
self
.
parameters
:
setattr
(
self
,
param
,
None
)
for
param
,
value
in
kwargs
.
items
():
if
param
not
in
self
.
parameters
:
raise
HandshakeError
(
'invalid parameter "%s"'
%
param
)
if
value
is
None
:
value
=
True
setattr
(
self
,
param
,
value
)
def
hook_send
(
self
,
frame
):
return
frame
def
hook_receive
(
self
,
frame
):
return
frame
class
Deflate
(
Extension
):
rsv1
=
True
parameters
=
[
'max_window_bits'
,
'no_context_takeover'
]
def
__init__
(
self
,
**
kwargs
):
super
(
Deflate
,
self
).
__init__
(
**
kwargs
)
self
.
max_window_bits
=
int
(
self
.
max_window_bits
)
def
hook_send
(
self
,
frame
):
# FIXME: original `frame` is modified, maybe it should be copied?
if
not
frame
.
rsv1
:
frame
.
rsv1
=
True
frame
.
payload
=
self
.
encode
(
frame
.
payload
)
return
frame
def
hook_recv
(
self
,
frame
):
# FIXME: original `frame` is modified, maybe it should be copied?
if
frame
.
rsv1
:
frame
.
rsv1
=
False
frame
.
payload
=
self
.
decode
(
frame
.
payload
)
return
frame
def
encode
(
self
,
data
):
raise
NotImplementedError
# TODO
def
decode
(
self
,
data
):
raise
NotImplementedError
# TODO
def
filter_compatible
(
extensions
):
"""
Remove extensions that use conflicting rsv bits and/or opcodes, with the
first options being most preferable.
"""
rsv1_reserved
=
True
rsv2_reserved
=
True
rsv3_reserved
=
True
opcodes_reserved
=
[]
compat
=
[]
for
ext
in
extensions
:
if
ext
.
rsv1
and
rsv1_reserved
\
or
ext
.
rsv2
and
rsv2_reserved
\
or
ext
.
rsv3
and
rsv3_reserved
\
or
len
(
set
(
ext
.
opcodes
)
&
set
(
opcodes_reserved
)):
continue
rsv1_reserved
|=
ext
.
rsv1
rsv2_reserved
|=
ext
.
rsv2
rsv3_reserved
|=
ext
.
rsv3
opcodes_reserved
.
extend
(
ext
.
opcodes
)
compat
.
append
(
ext
)
return
compat
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