Skip to content

Commit

Permalink
Merge pull request #118 from lsst/tickets/DM-7293
Browse files Browse the repository at this point in the history
Add setBytes/getBytes for py3 compatibility tickets/DM-7293
  • Loading branch information
parejkoj committed Nov 10, 2016
2 parents d7adb7c + 043758c commit 89a905c
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions python/lsst/afw/table/specializations.i
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,25 @@
self->set(key, v);
}
}

// To help with python3, we need to be able to deal with bytestrings directly.
%extend lsst::afw::table::BaseRecord {
PyObject * getBytes(lsst::afw::table::Key< std::string > const & key) const {
auto str = self->get(key);
return PyBytes_FromStringAndSize(str.data(), str.size());
}
PyObject * setBytes(lsst::afw::table::Key< std::string > const & key, PyObject * bytes) {
char * buffer = nullptr;
Py_ssize_t len = 0;
if (PyBytes_AsStringAndSize(bytes, &buffer, &len) == 0) {
std::string str(buffer, len);
self->set(key, str);
Py_RETURN_NONE;
}
return nullptr;
}
}

%extend lsst::afw::table::KeyBase< std::string > {
%pythoncode %{
subfields = None
Expand Down

0 comments on commit 89a905c

Please sign in to comment.