entirely reworked cython wrapper
This commit is contained in:
48
python/obitools3/obidms/_obidmscolumn_int.pyx
Normal file
48
python/obitools3/obidms/_obidmscolumn_int.pyx
Normal file
@ -0,0 +1,48 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obidmscolumn cimport obi_close_column,\
|
||||
obi_truncate_and_close_column, \
|
||||
obi_column_get_obiint_with_elt_name, \
|
||||
obi_column_set_obiint_with_elt_name
|
||||
from .capi.obierrno cimport obi_errno
|
||||
from .capi.obitypes cimport OBIInt_NA
|
||||
|
||||
from obitools3.utils cimport str2bytes
|
||||
|
||||
from cpython.int cimport PyInt_FromLong
|
||||
|
||||
from ._obidms cimport OBIDMS_column
|
||||
|
||||
|
||||
cdef class OBIDMS_column_int(OBIDMS_column):
|
||||
|
||||
cpdef object get_item(self, size_t line_nb, str element_name):
|
||||
cdef obiint_t value
|
||||
cdef object result
|
||||
value = obi_column_get_obiint_with_elt_name(self.pointer, line_nb, str2bytes(element_name))
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb, element_name)
|
||||
if value == OBIInt_NA :
|
||||
result = None
|
||||
else :
|
||||
result = PyInt_FromLong(value)
|
||||
return result
|
||||
|
||||
cpdef set_item(self, size_t line_nb, str element_name, obiint_t value):
|
||||
raise Exception("Column is read-only")
|
||||
|
||||
cpdef close(self):
|
||||
if obi_close_column(self.pointer) < 0 :
|
||||
raise Exception("Problem closing a column")
|
||||
|
||||
|
||||
cdef class OBIDMS_column_int_writable(OBIDMS_column_int):
|
||||
|
||||
cpdef set_item(self, size_t line_nb, str element_name, obiint_t value):
|
||||
if obi_column_set_obiint_with_elt_name(self.pointer, line_nb, str2bytes(element_name), value) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
||||
|
||||
cpdef close(self):
|
||||
if obi_truncate_and_close_column(self.pointer) < 0 :
|
||||
raise Exception("Problem closing a column")
|
||||
|
Reference in New Issue
Block a user