summaryrefslogtreecommitdiff
path: root/lib/extensions.py
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2010-12-29 03:43:19 +0100
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2010-12-31 03:18:27 +0100
commit89c492d3a4a95044344310bb87570c546fc9a9f4 (patch)
treed06f746a4286f1ff2cca57d16203b5e51ab1fd0a /lib/extensions.py
parent061079c918a6fdb32ac1ddcd20ba8cc0f0b82043 (diff)
downloadpsycopg2-89c492d3a4a95044344310bb87570c546fc9a9f4.tar.gz
Added b() function to return bytes in both Py2 and Py3.
Diffstat (limited to 'lib/extensions.py')
-rw-r--r--lib/extensions.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/extensions.py b/lib/extensions.py
index 7618751..43092fb 100644
--- a/lib/extensions.py
+++ b/lib/extensions.py
@@ -100,6 +100,16 @@ TRANSACTION_STATUS_INTRANS = 2
TRANSACTION_STATUS_INERROR = 3
TRANSACTION_STATUS_UNKNOWN = 4
+import sys as _sys
+
+# Return bytes from a string
+if _sys.version_info[0] < 3:
+ def b(s):
+ return s
+else:
+ def b(s):
+ return s.encode('utf8')
+
def register_adapter(typ, callable):
"""Register 'callable' as an ISQLQuote adapter for type 'typ'."""
adapters[(typ, ISQLQuote)] = callable