summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/postgresql/hstore.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-06-03 13:13:16 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2013-06-03 13:13:16 -0400
commit74c98bf182a1cac1ca1837da69e1c0550beaaab5 (patch)
tree4815d198d2aa4a6497330fb5d81e53bf4acfbb2d /lib/sqlalchemy/dialects/postgresql/hstore.py
parentff399ac75074916045410cedae72489cb60e8b50 (diff)
parentc2a158c137ee07a146f02e5ee89ec42e486c6a37 (diff)
downloadsqlalchemy-74c98bf182a1cac1ca1837da69e1c0550beaaab5.tar.gz
Merge branch 'master' into ticket_1068
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/hstore.py')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/hstore.py41
1 files changed, 29 insertions, 12 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/hstore.py b/lib/sqlalchemy/dialects/postgresql/hstore.py
index e555a1afd..d7368ff42 100644
--- a/lib/sqlalchemy/dialects/postgresql/hstore.py
+++ b/lib/sqlalchemy/dialects/postgresql/hstore.py
@@ -10,6 +10,7 @@ from .base import ARRAY, ischema_names
from ... import types as sqltypes
from ...sql import functions as sqlfunc
from ...sql.operators import custom_op
+from ... import util
__all__ = ('HSTORE', 'hstore')
@@ -96,14 +97,14 @@ def _serialize_hstore(val):
def esc(s, position):
if position == 'value' and s is None:
return 'NULL'
- elif isinstance(s, basestring):
+ elif isinstance(s, util.string_types):
return '"%s"' % s.replace('"', r'\"')
else:
raise ValueError("%r in %s position is not a string." %
(s, position))
return ', '.join('%s=>%s' % (esc(k, 'key'), esc(v, 'value'))
- for k, v in val.iteritems())
+ for k, v in val.items())
class HSTORE(sqltypes.Concatenable, sqltypes.TypeEngine):
@@ -260,19 +261,35 @@ class HSTORE(sqltypes.Concatenable, sqltypes.TypeEngine):
_adapt_expression(self, op, other_comparator)
def bind_processor(self, dialect):
- def process(value):
- if isinstance(value, dict):
- return _serialize_hstore(value)
- else:
- return value
+ if util.py2k:
+ encoding = dialect.encoding
+ def process(value):
+ if isinstance(value, dict):
+ return _serialize_hstore(value).encode(encoding)
+ else:
+ return value
+ else:
+ def process(value):
+ if isinstance(value, dict):
+ return _serialize_hstore(value)
+ else:
+ return value
return process
def result_processor(self, dialect, coltype):
- def process(value):
- if value is not None:
- return _parse_hstore(value)
- else:
- return value
+ if util.py2k:
+ encoding = dialect.encoding
+ def process(value):
+ if value is not None:
+ return _parse_hstore(value.decode(encoding))
+ else:
+ return value
+ else:
+ def process(value):
+ if value is not None:
+ return _parse_hstore(value)
+ else:
+ return value
return process