diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2008-05-13 19:55:49 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2008-05-13 19:55:49 +0000 |
commit | 17684a1b81b63a436fcf4f8426bcd822bdb8d463 (patch) | |
tree | df476f202c006b5b08ee62a27b2b1cff462c14bf /lib/sqlalchemy/util.py | |
parent | 1b6306c69e730eafdae499443efeb83322ce03e8 (diff) | |
download | sqlalchemy-17684a1b81b63a436fcf4f8426bcd822bdb8d463.tar.gz |
- LIMIT/OFFSET of zero is detected within compiler and is counted
- Query.__getitem__ now returns list/scalar in all cases, not generative (#1035)
- added Query.slice_() which provides the simple "limit/offset from a positive range" operation,
we can rename this to range_()/section()/_something_private_because_users_shouldnt_do_this() as needed
Diffstat (limited to 'lib/sqlalchemy/util.py')
-rw-r--r-- | lib/sqlalchemy/util.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/sqlalchemy/util.py b/lib/sqlalchemy/util.py index ff1108c3b..e0bf45b67 100644 --- a/lib/sqlalchemy/util.py +++ b/lib/sqlalchemy/util.py @@ -249,6 +249,24 @@ def to_ascii(x): else: raise TypeError +if sys.version_info >= (2, 5): + def decode_slice(slc): + """decode a slice object as sent to __getitem__. + + takes into account the 2.5 __index__() method, basically. + + """ + ret = [] + for x in slc.start, slc.stop, slc.step: + if hasattr(x, '__index__'): + x = x.__index__() + ret.append(x) + return tuple(ret) +else: + def decode_slice(slc): + return (slc.start, slc.stop, slc.step) + + def flatten_iterator(x): """Given an iterator of which further sub-elements may also be iterators, flatten the sub-elements into a single iterator. |