| 743 | } |
| 744 | |
| 745 | Py::Object Expression::Component::get(const Expression *owner, const Py::Object &pyobj) const { |
| 746 | try { |
| 747 | if(!e1 && !e2 && !e3) |
| 748 | return comp.get(pyobj); |
| 749 | if(!comp.isRange() && !e2 && !e3) { |
| 750 | auto index = e1->getPyValue(); |
| 751 | Py::Object res; |
| 752 | if(pyobj.isMapping()) |
| 753 | res = Py::Mapping(pyobj).getItem(index); |
| 754 | else { |
| 755 | Py_ssize_t i = PyNumber_AsSsize_t(index.ptr(), PyExc_IndexError); |
| 756 | if(PyErr_Occurred()) |
| 757 | throw Py::Exception(); |
| 758 | res = Py::Sequence(pyobj).getItem(i); |
| 759 | } |
| 760 | if(!res.ptr()) |
| 761 | throw Py::Exception(); |
| 762 | return res; |
| 763 | }else{ |
| 764 | Py::Object v1,v2,v3; |
| 765 | if(e1) v1 = e1->getPyValue(); |
| 766 | if(e2) v2 = e2->getPyValue(); |
| 767 | if(e3) v3 = e3->getPyValue(); |
| 768 | PyObject *s = PySlice_New(e1?v1.ptr():nullptr, |
| 769 | e2?v2.ptr():nullptr, |
| 770 | e3?v3.ptr():nullptr); |
| 771 | if(!s) |
| 772 | throw Py::Exception(); |
| 773 | Py::Object slice(s,true); |
| 774 | PyObject *res = PyObject_GetItem(pyobj.ptr(),slice.ptr()); |
| 775 | if(!res) |
| 776 | throw Py::Exception(); |
| 777 | return Py::asObject(res); |
| 778 | } |
| 779 | }catch(Py::Exception &) { |
| 780 | EXPR_PY_THROW(owner); |
| 781 | } |
| 782 | return Py::Object(); |
| 783 | } |
| 784 | |
| 785 | void Expression::Component::set(const Expression *owner, Py::Object &pyobj, const Py::Object &value) const |
| 786 | { |
no test coverage detected