diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-11-09 11:40:23 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-11-09 11:40:23 -0500 |
commit | a41c50ad63f688cce99fdb9920c4f7c24ef0c866 (patch) | |
tree | d811319676606ce89642bf316499e101c785b974 /lib/sqlalchemy | |
parent | 30bc42403754110df1fdec3037c7700cc4f26b70 (diff) | |
download | sqlalchemy-a41c50ad63f688cce99fdb9920c4f7c24ef0c866.tar.gz |
- Implemented sequence check capability for the C
version of RowProxy, as well as 2.7 style
"collections.Sequence" registration for RowProxy.
[ticket:1871]
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r-- | lib/sqlalchemy/cextension/resultproxy.c | 8 | ||||
-rw-r--r-- | lib/sqlalchemy/engine/base.py | 8 | ||||
-rw-r--r-- | lib/sqlalchemy/test/requires.py | 15 |
3 files changed, 29 insertions, 2 deletions
diff --git a/lib/sqlalchemy/cextension/resultproxy.c b/lib/sqlalchemy/cextension/resultproxy.c index 7404b9ed2..73e127345 100644 --- a/lib/sqlalchemy/cextension/resultproxy.c +++ b/lib/sqlalchemy/cextension/resultproxy.c @@ -327,6 +327,12 @@ BaseRowProxy_subscript(BaseRowProxy *self, PyObject *key) } static PyObject * +BaseRowProxy_getitem(PyObject *self, Py_ssize_t i) +{ + return BaseRowProxy_subscript((BaseRowProxy*)self, PyInt_FromSsize_t(i)); +} + +static PyObject * BaseRowProxy_getattro(BaseRowProxy *self, PyObject *name) { PyObject *tmp; @@ -506,7 +512,7 @@ static PySequenceMethods BaseRowProxy_as_sequence = { (lenfunc)BaseRowProxy_length, /* sq_length */ 0, /* sq_concat */ 0, /* sq_repeat */ - 0, /* sq_item */ + (ssizeargfunc)BaseRowProxy_getitem, /* sq_item */ 0, /* sq_slice */ 0, /* sq_ass_item */ 0, /* sq_ass_slice */ diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index ef402ceea..10b2b6782 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -2090,6 +2090,14 @@ class RowProxy(BaseRowProxy): def itervalues(self): return iter(self) +try: + # Register RowProxy with Sequence, + # so sequence protocol is implemented + import collections + collections.Sequence.register(RowProxy) +except ImportError: + pass + class ResultMetaData(object): """Handle cursor.description, applying additional info from an execution diff --git a/lib/sqlalchemy/test/requires.py b/lib/sqlalchemy/test/requires.py index 14c548f12..5b68a18e1 100644 --- a/lib/sqlalchemy/test/requires.py +++ b/lib/sqlalchemy/test/requires.py @@ -252,6 +252,12 @@ def sane_rowcount(fn): skip_if(lambda: not testing.db.dialect.supports_sane_rowcount) ) +def cextensions(fn): + return _chain_decorators_on( + fn, + skip_if(lambda: not _has_cextensions(), "C extensions not installed") + ) + def dbapi_lastrowid(fn): return _chain_decorators_on( fn, @@ -279,7 +285,14 @@ def python2(fn): "Python version 2.xx is required." ) ) - + +def _has_cextensions(): + try: + from sqlalchemy import cresultproxy, cprocessors + return True + except ImportError: + return False + def _has_sqlite(): from sqlalchemy import create_engine try: |