Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
BTrees
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
BTrees
Commits
3f48cb0a
Commit
3f48cb0a
authored
Dec 14, 2012
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make BTreeItems sliceable under Py3k.
parent
06d3daba
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
1 deletion
+48
-1
BTrees/BTreeItemsTemplate.c
BTrees/BTreeItemsTemplate.c
+48
-1
No files found.
BTrees/BTreeItemsTemplate.c
View file @
3f48cb0a
...
...
@@ -408,13 +408,60 @@ BTreeItems_slice(BTreeItems *self, Py_ssize_t ilow, Py_ssize_t ihigh)
lowbucket
,
lowoffset
,
highbucket
,
highoffset
);
}
static
PyObject
*
BTreeItems_subscript
(
BTreeItems
*
self
,
PyObject
*
key
)
{
Py_ssize_t
len
=
BTreeItems_length_or_nonzero
(
self
,
0
);
if
(
PyIndex_Check
(
key
))
{
Py_ssize_t
i
=
INT_AS_LONG
(
key
);
i
=
PyNumber_AsSsize_t
(
key
,
PyExc_IndexError
);
if
(
i
==
-
1
&&
PyErr_Occurred
())
return
NULL
;
if
(
i
<
0
)
i
+=
len
;
return
BTreeItems_item
(
self
,
i
);
}
if
(
PySlice_Check
(
key
))
{
Py_ssize_t
start
,
stop
,
step
,
slicelength
;
if
(
PySlice_GetIndicesEx
(
key
,
len
,
&
start
,
&
stop
,
&
step
,
&
slicelength
)
<
0
)
{
return
NULL
;
}
if
(
step
!=
1
)
{
PyErr_SetString
(
PyExc_RuntimeError
,
"slices must have step size of 1"
);
return
NULL
;
}
return
BTreeItems_slice
(
self
,
start
,
stop
);
}
PyErr_SetString
(
PyExc_RuntimeError
,
"Unknown index type: must be int or slice"
);
return
NULL
;
}
/* Py3K doesn't honor sequence slicing, so implement via mapping */
static
PyMappingMethods
BTreeItems_as_mapping
=
{
(
lenfunc
)
BTreeItems_length
,
/* mp_length */
(
binaryfunc
)
BTreeItems_subscript
,
/* mp_subscript */
};
static
PySequenceMethods
BTreeItems_as_sequence
=
{
(
lenfunc
)
BTreeItems_length
,
/* sq_length */
(
binaryfunc
)
0
,
/* sq_concat */
(
ssizeargfunc
)
0
,
/* sq_repeat */
(
ssizeargfunc
)
BTreeItems_item
,
/* sq_item */
#ifndef PY3K
/* Py3K doesn't honor this slot */
(
ssizessizeargfunc
)
BTreeItems_slice
,
/* sq_slice */
#endif
};
/* Number Method items (just for nb_nonzero!) */
...
...
@@ -455,7 +502,7 @@ static PyTypeObject BTreeItemsType = {
0
,
/* tp_repr */
&
BTreeItems_as_number_for_nonzero
,
/* tp_as_number */
&
BTreeItems_as_sequence
,
/* tp_as_sequence */
0
,
/* tp_as_mapping */
&
BTreeItems_as_mapping
,
/* tp_as_mapping */
(
hashfunc
)
0
,
/* tp_hash */
(
ternaryfunc
)
0
,
/* tp_call */
(
reprfunc
)
0
,
/* tp_str */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment