summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRalph Bean <rbean@redhat.com>2014-04-14 16:31:56 -0400
committerRalph Bean <rbean@redhat.com>2014-04-14 16:31:56 -0400
commit2b3f3ff28c736a5e6617edbbdd94b0138ea17ee8 (patch)
tree670f1589bb140a652d27ded66dea4d1762cdd6c0
parentfd11038bab9d276e83eb7127c771be9d4a7da789 (diff)
downloadwebsocket-client-2b3f3ff28c736a5e6617edbbdd94b0138ea17ee8.tar.gz
Initial pass at low-hanging python3 fruit.
-rw-r--r--examples/echo_client.py1
-rw-r--r--setup.py5
-rw-r--r--tests/test_websocket.py1
-rw-r--r--websocket/__init__.py14
4 files changed, 17 insertions, 4 deletions
diff --git a/examples/echo_client.py b/examples/echo_client.py
index d4fa3b7..7a74461 100644
--- a/examples/echo_client.py
+++ b/examples/echo_client.py
@@ -1,3 +1,4 @@
+from __future__ import print_function
import websocket
if __name__ == "__main__":
diff --git a/setup.py b/setup.py
index babb32a..153647b 100644
--- a/setup.py
+++ b/setup.py
@@ -25,7 +25,10 @@ setup(
],
keywords='websockets',
scripts=["bin/wsdump.py"],
- install_requires=['backports.ssl_match_hostname'],
+ install_requires=[
+ 'backports.ssl_match_hostname',
+ 'six',
+ ],
packages=["tests", "websocket"],
package_data={
'tests': ['data/*.txt'],
diff --git a/tests/test_websocket.py b/tests/test_websocket.py
index c5865ce..83ffc4f 100644
--- a/tests/test_websocket.py
+++ b/tests/test_websocket.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
#
+import six
import sys
sys.path[0:0] = [""]
diff --git a/websocket/__init__.py b/websocket/__init__.py
index 6199788..7dc9c1a 100644
--- a/websocket/__init__.py
+++ b/websocket/__init__.py
@@ -18,8 +18,10 @@ Copyright (C) 2010 Hiroki Ohtani(liris)
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
+from __future__ import print_function
+import six
import socket
try:
@@ -34,7 +36,13 @@ except ImportError:
HAVE_SSL = False
-from urlparse import urlparse
+try:
+ # python 3
+ from urllib.parse import urlparse
+except ImportError:
+ # python 2
+ from urlparse import urlparse
+
import os
import array
import struct
@@ -300,7 +308,7 @@ class ABNF(object):
fin: fin flag. if set to 0, create continue fragmentation.
"""
- if opcode == ABNF.OPCODE_TEXT and isinstance(data, unicode):
+ if opcode == ABNF.OPCODE_TEXT and isinstance(data, six.text_type):
data = data.encode("utf-8")
# mask must be set if send data from client
return ABNF(fin, 0, 0, 0, opcode, 1, data)
@@ -519,7 +527,7 @@ class WebSocket(object):
self.connected = True
def _validate_header(self, headers, key):
- for k, v in _HEADERS_TO_CHECK.iteritems():
+ for k, v in _HEADERS_TO_CHECK.items():
r = headers.get(k, None)
if not r:
return False