Skip to content

Commit

Permalink
Bug 1622683 - Make dom/websocket flake8 and pylint compliant. r=sylve…
Browse files Browse the repository at this point in the history
  • Loading branch information
PFischbeck committed Aug 31, 2020
1 parent 50b96d5 commit 24588e8
Show file tree
Hide file tree
Showing 12 changed files with 246 additions and 231 deletions.
1 change: 0 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ exclude =
dom/base,
dom/bindings,
dom/encoding,
dom/websocket,
gfx/tests,
ipc/ipdl/ipdl,
layout/base/tests/marionette,
Expand Down
40 changes: 21 additions & 19 deletions dom/websocket/tests/file_websocket_basic_wsh.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
from mod_pywebsocket import msgutil


def web_socket_do_extra_handshake(request):
# must set request.ws_protocol to the selected version from ws_requested_protocols
request.ws_protocol = request.ws_requested_protocols[0]
# must set request.ws_protocol to the selected version from ws_requested_protocols
request.ws_protocol = request.ws_requested_protocols[0]

if (request.ws_protocol == 'error'):
raise ValueError('Error')
pass

if (request.ws_protocol == 'error'):
raise ValueError('Error')
pass

def web_socket_transfer_data(request):
while True:
line = msgutil.receive_message(request)
if line == 'protocol':
msgutil.send_message(request, request.ws_protocol)
continue
while True:
line = msgutil.receive_message(request)
if line == 'protocol':
msgutil.send_message(request, request.ws_protocol)
continue

if line == 'resource':
msgutil.send_message(request, request.ws_resource)
continue
if line == 'resource':
msgutil.send_message(request, request.ws_resource)
continue

if line == 'origin':
msgutil.send_message(request, request.ws_origin)
continue
if line == 'origin':
msgutil.send_message(request, request.ws_origin)
continue

msgutil.send_message(request, line)
msgutil.send_message(request, line)

if line == 'end':
return
if line == 'end':
return
10 changes: 6 additions & 4 deletions dom/websocket/tests/file_websocket_bigBlob_wsh.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from mod_pywebsocket import msgutil


def web_socket_do_extra_handshake(request):
pass
pass


def web_socket_transfer_data(request):
while True:
line = msgutil.receive_message(request)
msgutil.send_message(request, line, True, True)
while True:
line = msgutil.receive_message(request)
msgutil.send_message(request, line, True, True)
12 changes: 7 additions & 5 deletions dom/websocket/tests/file_websocket_hello_wsh.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from mod_pywebsocket import msgutil


def web_socket_do_extra_handshake(request):
pass
pass


def web_socket_transfer_data(request):
resp = "Test"
if msgutil.receive_message(request) == "data":
resp = "Hello world!"
msgutil.send_message(request, resp)
resp = "Test"
if msgutil.receive_message(request) == "data":
resp = "Hello world!"
msgutil.send_message(request, resp)
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
from mod_pywebsocket import msgutil
from mod_pywebsocket import common


def web_socket_do_extra_handshake(request):
if request.ws_requested_extensions is not None:
for extension_request in request.ws_requested_extensions:
if extension_request.name() == "permessage-deflate":
raise ValueError('permessage-deflate should not be offered')
if request.ws_requested_extensions is not None:
for extension_request in request.ws_requested_extensions:
if extension_request.name() == "permessage-deflate":
raise ValueError('permessage-deflate should not be offered')


def web_socket_transfer_data(request):
while True:
rcvd = msgutil.receive_message(request)
opcode = request.ws_stream.get_last_received_opcode()
if (opcode == common.OPCODE_BINARY):
msgutil.send_message(request, rcvd, binary=True)
elif (opcode == common.OPCODE_TEXT):
msgutil.send_message(request, rcvd)
while True:
rcvd = msgutil.receive_message(request)
opcode = request.ws_stream.get_last_received_opcode()
if (opcode == common.OPCODE_BINARY):
msgutil.send_message(request, rcvd, binary=True)
elif (opcode == common.OPCODE_TEXT):
msgutil.send_message(request, rcvd)
32 changes: 17 additions & 15 deletions dom/websocket/tests/file_websocket_permessage_deflate_params_wsh.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
from mod_pywebsocket import msgutil
from mod_pywebsocket import common


def web_socket_do_extra_handshake(request):
deflate_found = False
deflate_found = False

if request.ws_extension_processors is not None:
for extension_processor in request.ws_extension_processors:
if extension_processor.name() == "deflate":
extension_processor.set_client_no_context_takeover(True)
deflate_found = True

if request.ws_extension_processors is not None:
for extension_processor in request.ws_extension_processors:
if extension_processor.name() == "deflate":
extension_processor.set_client_no_context_takeover(True)
deflate_found = True
if deflate_found is False:
raise ValueError('deflate extension processor not found')

if deflate_found is False:
raise ValueError('deflate extension processor not found')

def web_socket_transfer_data(request):
while True:
rcvd = msgutil.receive_message(request)
opcode = request.ws_stream.get_last_received_opcode()
if (opcode == common.OPCODE_BINARY):
msgutil.send_message(request, rcvd, binary=True)
elif (opcode == common.OPCODE_TEXT):
msgutil.send_message(request, rcvd)
while True:
rcvd = msgutil.receive_message(request)
opcode = request.ws_stream.get_last_received_opcode()
if (opcode == common.OPCODE_BINARY):
msgutil.send_message(request, rcvd, binary=True)
elif (opcode == common.OPCODE_TEXT):
msgutil.send_message(request, rcvd)
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
from mod_pywebsocket import msgutil
from mod_pywebsocket import common


def web_socket_do_extra_handshake(request):
deflate_removed = False
deflate_removed = False

if request.ws_extension_processors is not None:
for extension_processor in request.ws_extension_processors:
if extension_processor.name() == "deflate":
request.ws_extension_processors.remove(extension_processor)
deflate_removed = True

if request.ws_extension_processors is not None:
for extension_processor in request.ws_extension_processors:
if extension_processor.name() == "deflate":
request.ws_extension_processors.remove(extension_processor)
deflate_removed = True
if deflate_removed is False:
raise ValueError('deflate extension processor not found')

if deflate_removed is False:
raise ValueError('deflate extension processor not found')

def web_socket_transfer_data(request):
while True:
rcvd = msgutil.receive_message(request)
opcode = request.ws_stream.get_last_received_opcode()
if (opcode == common.OPCODE_BINARY):
msgutil.send_message(request, rcvd, binary=True)
elif (opcode == common.OPCODE_TEXT):
msgutil.send_message(request, rcvd)
while True:
rcvd = msgutil.receive_message(request)
opcode = request.ws_stream.get_last_received_opcode()
if (opcode == common.OPCODE_BINARY):
msgutil.send_message(request, rcvd, binary=True)
elif (opcode == common.OPCODE_TEXT):
msgutil.send_message(request, rcvd)
30 changes: 16 additions & 14 deletions dom/websocket/tests/file_websocket_permessage_deflate_wsh.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
from mod_pywebsocket import msgutil
from mod_pywebsocket import common


def web_socket_do_extra_handshake(request):
pmce_offered = False
pmce_offered = False

if request.ws_requested_extensions is not None:
for extension_request in request.ws_requested_extensions:
if extension_request.name() == "permessage-deflate":
pmce_offered = True

if request.ws_requested_extensions is not None:
for extension_request in request.ws_requested_extensions:
if extension_request.name() == "permessage-deflate":
pmce_offered = True
if pmce_offered is False:
raise ValueError('permessage-deflate not offered')

if pmce_offered is False:
raise ValueError('permessage-deflate not offered')

def web_socket_transfer_data(request):
while True:
rcvd = msgutil.receive_message(request)
opcode = request.ws_stream.get_last_received_opcode()
if (opcode == common.OPCODE_BINARY):
msgutil.send_message(request, rcvd, binary=True)
elif (opcode == common.OPCODE_TEXT):
msgutil.send_message(request, rcvd)
while True:
rcvd = msgutil.receive_message(request)
opcode = request.ws_stream.get_last_received_opcode()
if (opcode == common.OPCODE_BINARY):
msgutil.send_message(request, rcvd, binary=True)
elif (opcode == common.OPCODE_TEXT):
msgutil.send_message(request, rcvd)
Loading

0 comments on commit 24588e8

Please sign in to comment.