diff --git a/docs/sources/basics.rst b/docs/sources/basics.rst index 5d8d271..3bf587a 100644 --- a/docs/sources/basics.rst +++ b/docs/sources/basics.rst @@ -34,7 +34,7 @@ necessarily need a connected socket, in fact, you don't even need a socket at al >>> def data_source(): >>> yield TextMessage(u'hello world') - >>> from mock import MagicMock + >>> from unittest.mock import MagicMock >>> source = MagicMock(side_effect=data_source) >>> ws = EchoWebSocket(sock=source) >>> ws.send(u'hello there') diff --git a/example/basic/app.py b/example/basic/app.py index 7d0745c..c81dcf1 100644 --- a/example/basic/app.py +++ b/example/basic/app.py @@ -24,7 +24,7 @@ cur_dir = os.path.normpath(os.path.abspath(os.path.dirname(__file__))) index_path = os.path.join(cur_dir, 'index.html') -index_page = file(index_path, 'r').read() +index_page = open(index_path, 'r').read() class ChatWebSocketHandler(WebSocket): def received_message(self, m): diff --git a/example/droid_sensor.py b/example/droid_sensor.py index 7f9e8af..3699a50 100644 --- a/example/droid_sensor.py +++ b/example/droid_sensor.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +from __future__ import print_function + __doc__ = """ WebSocket client that pushes Android sensor metrics to the websocket server it is connected to. @@ -64,7 +66,7 @@ def run(self): continue c = lambda rad: rad * 360.0 / math.pi - print c(azimuth), c(pitch), c(roll), x, y, z + print(c(azimuth), c(pitch), c(roll), x, y, z) if self.client.terminated: break diff --git a/example/droid_sensor_cherrypy_server.py b/example/droid_sensor_cherrypy_server.py index b342540..8bd4d28 100644 --- a/example/droid_sensor_cherrypy_server.py +++ b/example/droid_sensor_cherrypy_server.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +from __future__ import print_function + import os.path import cherrypy @@ -8,7 +10,7 @@ class BroadcastWebSocketHandler(WebSocket): def received_message(self, m): cherrypy.engine.publish('websocket-broadcast', str(m)) - + class Root(object): @cherrypy.expose def display(self): @@ -61,7 +63,7 @@ def index(self): """ - + if __name__ == '__main__': cherrypy.config.update({ 'server.socket_host': '0.0.0.0', @@ -69,7 +71,7 @@ def index(self): 'tools.staticdir.root': os.path.abspath(os.path.join(os.path.dirname(__file__), 'static')) } ) - print os.path.abspath(os.path.join(__file__, 'static')) + print(os.path.abspath(os.path.join(__file__, 'static'))) WebSocketPlugin(cherrypy.engine).subscribe() cherrypy.tools.websocket = WebSocketTool() diff --git a/example/websensors/templates/.cache/board.html.py b/example/websensors/templates/.cache/board.html.py index 5bd9f8b..3e73637 100644 --- a/example/websensors/templates/.cache/board.html.py +++ b/example/websensors/templates/.cache/board.html.py @@ -22,9 +22,9 @@ def render_body(context,**pageargs): # SOURCE LINE 1 __M_writer(u'\n\n\n\n \n \n \n \n Mobile remote control\n \n \n \n \n \n\n \n \n \n\n \n \n \n \n\n
\n\t \n\t \n
\n\n \n\t\n \n \n \n \n\n') return '' finally: diff --git a/example/websensors/templates/.cache/index.html.py b/example/websensors/templates/.cache/index.html.py index 28ac0d3..6f8f25a 100644 --- a/example/websensors/templates/.cache/index.html.py +++ b/example/websensors/templates/.cache/index.html.py @@ -21,9 +21,9 @@ def render_body(context,**pageargs): # SOURCE LINE 1 __M_writer(u'\n\n\n\n \n \n \n \n Shared drawing board\n \n \n \n \n \n\n \n \n\n \n \n \n \n\n
\n
\n

shared drawing board

\n
\n
\n\n
\n
\n\n \n\n
\n
\n\n \n\n \n \n \n\n') return '' finally: diff --git a/test/test_cherrypy.py b/test/test_cherrypy.py index 4d184de..326e5df 100644 --- a/test/test_cherrypy.py +++ b/test/test_cherrypy.py @@ -4,7 +4,10 @@ import time import unittest -from mock import MagicMock, call +try: + from unittest.mock import MagicMock, call +except ImportError: + from mock import MagicMock, call import cherrypy from ws4py.server.cherrypyserver import WebSocketPlugin, WebSocketTool diff --git a/test/test_client.py b/test/test_client.py index 7ad6a4b..dd542a6 100644 --- a/test/test_client.py +++ b/test/test_client.py @@ -4,8 +4,10 @@ import socket import time import unittest - -from mock import MagicMock, patch +try: + from unittest.mock import MagicMock, patch +except ImportError: + from mock import MagicMock, patch from ws4py import WS_KEY from ws4py.exc import HandshakeError diff --git a/test/test_manager.py b/test/test_manager.py index 126c714..9a8d347 100644 --- a/test/test_manager.py +++ b/test/test_manager.py @@ -8,7 +8,10 @@ except ImportError: from itertools import zip_longest -from mock import MagicMock, call, patch +try: + from unittest.mock import MagicMock, call, patch +except ImportError: + from mock import MagicMock, call, patch from ws4py.manager import WebSocketManager, SelectPoller,\ EPollPoller diff --git a/test/test_utils.py b/test/test_utils.py index 4f21afd..3e48aef 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -1,9 +1,14 @@ # -*- coding: utf-8 -*- import unittest +try: + from unittest.mock import MagicMock +except ImportError: + from mock import MagicMock + from ws4py import format_addresses from ws4py.websocket import WebSocket -from mock import MagicMock + class WSUtilities(unittest.TestCase): def test_format_address(self): @@ -14,7 +19,7 @@ def test_format_address(self): log = format_addresses(ws) self.assertEqual(log, "[Local => 127.0.0.1:52300 | Remote => 127.0.0.1:4800]") - + if __name__ == '__main__': suite = unittest.TestSuite() loader = unittest.TestLoader() diff --git a/test/test_websocket.py b/test/test_websocket.py index 96fb384..981d2b7 100644 --- a/test/test_websocket.py +++ b/test/test_websocket.py @@ -4,7 +4,10 @@ import socket import struct -from mock import MagicMock, call, patch +try: + from unittest.mock import MagicMock, call, patch +except ImportError: + from mock import MagicMock, call, patch from ws4py.framing import Frame, \ OPCODE_CONTINUATION, OPCODE_TEXT, \ diff --git a/ws4py/compat.py b/ws4py/compat.py index e986e33..5b8870d 100644 --- a/ws4py/compat.py +++ b/ws4py/compat.py @@ -34,7 +34,7 @@ def ord(c): else: py3k = False from urlparse import urlsplit - range = xrange + range = xrange # noqa: F821 unicode = unicode basestring = basestring ord = ord diff --git a/ws4py/server/cherrypyserver.py b/ws4py/server/cherrypyserver.py index 5b93465..49ffebf 100644 --- a/ws4py/server/cherrypyserver.py +++ b/ws4py/server/cherrypyserver.py @@ -379,4 +379,4 @@ def index(self): cherrypy.log("Handler created: %s" % repr(cherrypy.request.ws_handler)) cherrypy.quickstart(Root(), '/', config={'/': {'tools.websocket.on': True, - 'tools.websocket.handler_cls': EchoWebSocketHandler}}) + 'tools.websocket.handler_cls': EchoWebSocketHandler}}) # noqa: F821