Commit 661fe360 authored by Celine Mercier's avatar Celine Mercier

In OBI_CHAR columns, characters are now given and retrieved as decoded

(unicode) characters.
parent c4b7e579
......@@ -16,10 +16,10 @@ cdef class OBIDMS_column_char_writable(OBIDMS_column_char):
cdef class OBIDMS_column_char_multi_elts(OBIDMS_column_char):
cpdef object get_item(self, index_t line_nb, str element_name)
cpdef object get_line(self, index_t line_nb)
cpdef set_item(self, index_t line_nb, str element_name, bytes value)
cpdef set_item(self, index_t line_nb, str element_name, str value)
cpdef set_line(self, index_t line_nb, object values)
cdef class OBIDMS_column_char_multi_elts_writable(OBIDMS_column_char_multi_elts):
cpdef set_item(self, index_t line_nb, str element_name, bytes value)
cpdef set_item(self, index_t line_nb, str element_name, str value)
cpdef set_line(self, index_t line_nb, object values)
cpdef close(self)
......@@ -9,7 +9,7 @@ from .capi.obidmscolumn cimport obi_close_column,\
from .capi.obierrno cimport obi_errno
from .capi.obitypes cimport OBIChar_NA
from obitools3.utils cimport str2bytes
from obitools3.utils cimport str2bytes, bytes2str
cdef class OBIDMS_column_char(OBIDMS_column):
......@@ -23,7 +23,7 @@ cdef class OBIDMS_column_char(OBIDMS_column):
if value == OBIChar_NA :
result = None
else :
result = <bytes> value
result = bytes2str(value)
return result
cpdef set_line(self, index_t line_nb, object value):
......@@ -37,7 +37,7 @@ cdef class OBIDMS_column_char(OBIDMS_column):
cdef class OBIDMS_column_char_writable(OBIDMS_column_char):
cpdef set_line(self, index_t line_nb, object value):
if obi_column_set_obichar_with_elt_idx(self.pointer, line_nb, 0, <bytes> value[0]) < 0:
if obi_column_set_obichar_with_elt_idx(self.pointer, line_nb, 0, str2bytes(value)[0]) < 0:
raise Exception("Problem setting a value in a column")
cpdef close(self):
......@@ -56,7 +56,7 @@ cdef class OBIDMS_column_char_multi_elts(OBIDMS_column_char):
if value == OBIChar_NA :
result = None
else :
result = <bytes> value
result = bytes2str(value)
return result
cpdef object get_line(self, index_t line_nb) :
......@@ -70,14 +70,14 @@ cdef class OBIDMS_column_char_multi_elts(OBIDMS_column_char):
value = obi_column_get_obichar_with_elt_idx(self.pointer, line_nb, i)
if obi_errno > 0 :
raise IndexError(line_nb)
result[self.elements_names[i]] = <bytes> value
result[self.elements_names[i]] = bytes2str(value)
if all_NA and (value != OBIChar_NA) :
all_NA = False
if all_NA :
result = None
return result
cpdef set_item(self, index_t line_nb, str element_name, bytes value):
cpdef set_item(self, index_t line_nb, str element_name, str value):
raise Exception("Column is read-only")
cpdef set_line(self, index_t line_nb, object values):
......@@ -86,53 +86,17 @@ cdef class OBIDMS_column_char_multi_elts(OBIDMS_column_char):
cdef class OBIDMS_column_char_multi_elts_writable(OBIDMS_column_char_multi_elts):
cpdef set_item(self, index_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:
cpdef set_item(self, index_t line_nb, str element_name, str value):
if obi_column_set_obichar_with_elt_name(self.pointer, line_nb, str2bytes(element_name), str2bytes(value)[0]) < 0:
raise Exception("Problem setting a value in a column")
cpdef set_line(self, index_t line_nb, object values):
cdef bytes value
cdef str value
for element_name in values :
value = <bytes> values[element_name]
value = values[element_name]
self.set_item(line_nb, element_name, value)
cpdef close(self):
if obi_truncate_and_close_column(self.pointer) < 0 :
raise Exception("Problem closing a column")
# cdef class OBIDMS_column_char(OBIDMS_column) :
#
# cpdef object get_item(self, index_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, index_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, index_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")
#
......@@ -59,7 +59,7 @@ def random_obivalue(data_type):
return randint(0,1)
elif data_type == "OBI_CHAR" :
nucs = 'atgc'
return bytes(nucs[randint(0,3)], 'utf-8')
return nucs[randint(0,3)]
elif data_type == "OBI_IDX" :
length = randint(1,500)
randoms = ''.join(choice(string.ascii_lowercase) for i in range(length))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment