summaryrefslogtreecommitdiff
path: root/examples/websocket.py
diff options
context:
space:
mode:
authorVictor Sergeyev <vsergeyev@mirantis.com>2013-11-25 18:21:40 +0200
committerSergey Shepelev <temotor@gmail.com>2014-03-28 10:58:14 +0400
commit2b2f0a96b44779c5b98c851c55d70ec5e46e41f9 (patch)
tree3f8c8cfca3d6899e4355a80668b605adb4abc5e4 /examples/websocket.py
parentcfdd9a922cffc2478a52e4b5b9a4dead5fe580c4 (diff)
downloadeventlet-2b2f0a96b44779c5b98c851c55d70ec5e46e41f9.tar.gz
python3 compat fixes
https://github.com/eventlet/eventlet/pull/59
Diffstat (limited to 'examples/websocket.py')
-rw-r--r--examples/websocket.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/examples/websocket.py b/examples/websocket.py
index 89a4fbf..66a2165 100644
--- a/examples/websocket.py
+++ b/examples/websocket.py
@@ -1,14 +1,16 @@
import eventlet
from eventlet import wsgi
from eventlet import websocket
+from eventlet.support import six
# demo app
import os
import random
+
@websocket.WebSocketWSGI
def handle(ws):
- """ This is the websocket handler function. Note that we
+ """ This is the websocket handler function. Note that we
can dispatch based on path in here, too."""
if ws.path == '/echo':
while True:
@@ -16,12 +18,12 @@ def handle(ws):
if m is None:
break
ws.send(m)
-
+
elif ws.path == '/data':
- for i in xrange(10000):
+ for i in six.moves.range(10000):
ws.send("0 %s %s\n" % (i, random.random()))
eventlet.sleep(0.1)
-
+
def dispatch(environ, start_response):
""" This resolves to the web page or the websocket depending on
the path."""
@@ -30,11 +32,11 @@ def dispatch(environ, start_response):
else:
start_response('200 OK', [('content-type', 'text/html')])
return [open(os.path.join(
- os.path.dirname(__file__),
+ os.path.dirname(__file__),
'websocket.html')).read()]
-
+
if __name__ == "__main__":
- # run an example app from the command line
+ # run an example app from the command line
listener = eventlet.listen(('127.0.0.1', 7000))
print("\nVisit http://localhost:7000/ in your websocket-capable browser.\n")
wsgi.server(listener, dispatch)