summaryrefslogtreecommitdiff
path: root/game/python-extra/ws4py/compat.py
diff options
context:
space:
mode:
Diffstat (limited to 'game/python-extra/ws4py/compat.py')
-rw-r--r--game/python-extra/ws4py/compat.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/game/python-extra/ws4py/compat.py b/game/python-extra/ws4py/compat.py
new file mode 100644
index 0000000..e986e33
--- /dev/null
+++ b/game/python-extra/ws4py/compat.py
@@ -0,0 +1,46 @@
+# -*- coding: utf-8 -*-
+__doc__ = """
+This compatibility module is inspired by the one found
+in CherryPy. It provides a common entry point for the various
+functions and types that are used with ws4py but which
+differ from Python 2.x to Python 3.x
+
+There are likely better ways for some of them so feel
+free to provide patches.
+
+Note this has been tested against 2.7 and 3.3 only but
+should hopefully work fine with other versions too.
+"""
+import sys
+
+if sys.version_info >= (3, 0):
+ py3k = True
+ from urllib.parse import urlsplit
+ range = range
+ unicode = str
+ basestring = (bytes, str)
+ _ord = ord
+
+ def get_connection(fileobj):
+ return fileobj.raw._sock
+
+ def detach_connection(fileobj):
+ fileobj.detach()
+
+ def ord(c):
+ if isinstance(c, int):
+ return c
+ return _ord(c)
+else:
+ py3k = False
+ from urlparse import urlsplit
+ range = xrange
+ unicode = unicode
+ basestring = basestring
+ ord = ord
+
+ def get_connection(fileobj):
+ return fileobj._sock
+
+ def detach_connection(fileobj):
+ fileobj._sock = None