From: Philip Jenvey Date: Wed, 9 Sep 2009 06:48:06 +0000 (+0000) Subject: fix the new Binary str handling under Jython X-Git-Tag: rel_0_6beta1~299 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2c4311c2a9c0974114b8177a7544f3ccdc7aafb5;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git fix the new Binary str handling under Jython --- diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py index 8b847f2014..9a35e1a4af 100644 --- a/lib/sqlalchemy/types.py +++ b/lib/sqlalchemy/types.py @@ -781,6 +781,8 @@ class Binary(TypeEngine): def result_processor(self, dialect): def process(value): if value is not None: + if util.jython and isinstance(value, array.array): + value = value.tostring() return str(value) else: return None @@ -852,11 +854,7 @@ class PickleType(MutableType, TypeDecorator): # Py3K #return loads(value) # Py2K - if util.jython and isinstance(value, array.ArrayType): - value = value.tostring() - else: - value = str(value) - return loads(value) + return loads(str(value)) # end Py2K def copy_value(self, value): diff --git a/test/sql/test_types.py b/test/sql/test_types.py index f57347115e..c844cf696e 100644 --- a/test/sql/test_types.py +++ b/test/sql/test_types.py @@ -406,20 +406,6 @@ class BinaryTest(TestBase, AssertsExecutionResults): typemap={'pickled':PickleType, 'mypickle':MyPickleType, 'data':Binary, 'data_slice':Binary}, bind=testing.db) ): - #if util.jython: - # TODO: may need to modify Binary type directly - # to detect jython if something other than str()/bytes() - # is needed to convert from raw to string/bytes. - # ArrayType should no longer be expected here though. - # users who want raw ArrayType can of course create their - # own BinaryType that does no conversion. - #_eq_data = eq_data - #def eq_data(x, y): - # # Jython currently returns arrays - # from array import ArrayType - # if isinstance(y, ArrayType): - # return eq_(x, y.tostring()) - # return _eq_data(x, y) l = stmt.execute().fetchall() eq_(stream1, l[0]['data']) eq_(stream1[0:100], l[0]['data_slice'])