summaryrefslogtreecommitdiff
path: root/lib/extensions.py
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2010-12-14 02:21:49 +0000
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2010-12-21 04:02:14 +0000
commitb96dcef8a264ab166608c9f821e73d8510c2c871 (patch)
tree1e2cf5d7a3192a8b98e184a8af057b266ef1e500 /lib/extensions.py
parent4635c2aa4f41c1fe05ec4d5d562f89eb3c4f9d27 (diff)
downloadpsycopg2-b96dcef8a264ab166608c9f821e73d8510c2c871.tar.gz
Fixed PG -> Py encodings mapping with non-alnum chars.
We mangle the encoding names a little bit before asking it to the backend: be sure to be able to find the equivalent Python code back or decoding (unicode cast or Py3) will barf.
Diffstat (limited to 'lib/extensions.py')
-rw-r--r--lib/extensions.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/extensions.py b/lib/extensions.py
index fca7973..7618751 100644
--- a/lib/extensions.py
+++ b/lib/extensions.py
@@ -128,4 +128,12 @@ class SQL_IN(object):
__str__ = getquoted
+# Add the "cleaned" version of the encodings to the key.
+# When the encoding is set its name is cleaned up from - and _ and turned
+# uppercase, so an encoding not respecting these rules wouldn't be found in the
+# encodings keys and would raise an exception with the unicode typecaster
+for k, v in encodings.items():
+ k = k.replace('_', '').replace('-', '').upper()
+ encodings[k] = v
+
__all__ = filter(lambda k: not k.startswith('_'), locals().keys())