45 lines
1.6 KiB
Cython
45 lines
1.6 KiB
Cython
#cython: language_level=3
|
|
|
|
from .capi.obidmscolumn cimport obi_close_column,\
|
|
obi_truncate_and_close_column, \
|
|
obi_column_get_obichar_with_elt_name, \
|
|
obi_column_set_obichar_with_elt_name
|
|
from .capi.obierrno cimport obi_errno
|
|
from .capi.obitypes cimport OBIChar_NA
|
|
|
|
from obitools3.utils cimport str2bytes
|
|
|
|
|
|
cdef class OBIDMS_column_char(OBIDMS_column) :
|
|
|
|
cpdef object get_item(self, size_t line_nb, str element_name):
|
|
cdef char value
|
|
cdef object result
|
|
value = obi_column_get_obichar_with_elt_name(self.pointer, line_nb, str2bytes(element_name))
|
|
if obi_errno > 0 :
|
|
raise IndexError(line_nb, element_name)
|
|
if value == OBIChar_NA :
|
|
result = None
|
|
else :
|
|
result = <bytes> value
|
|
return result
|
|
|
|
cpdef set_item(self, size_t line_nb, str element_name, bytes 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_char_writable(OBIDMS_column_char) :
|
|
|
|
cpdef set_item(self, size_t line_nb, str element_name, bytes value):
|
|
if obi_column_set_obichar_with_elt_name(self.pointer, line_nb, str2bytes(element_name), value[0]) < 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")
|
|
|