Cython API: moved an eval function to utils
This commit is contained in:
@ -12,4 +12,6 @@ cdef str tostr(object string)
|
||||
cdef obitype_t get_obitype_single_value(object value)
|
||||
cdef obitype_t update_obitype(obitype_t obitype, object new_value)
|
||||
cdef obitype_t get_obitype_iterable_value(object value)
|
||||
cdef obitype_t get_obitype(object value)
|
||||
cdef obitype_t get_obitype(object value)
|
||||
|
||||
cdef object __etag__(str x)
|
||||
|
@ -15,6 +15,8 @@ from obitools3.dms.capi.obierrno cimport OBI_LINE_IDX_ERROR, \
|
||||
OBI_ELT_IDX_ERROR
|
||||
#obi_errno
|
||||
|
||||
import re
|
||||
|
||||
#from obitools3.dms.obiseq cimport Nuc_Seq, Nuc_Seq_Stored
|
||||
|
||||
|
||||
@ -156,3 +158,50 @@ cdef obitype_t get_obitype(object value) :
|
||||
|
||||
else :
|
||||
return get_obitype_single_value(value)
|
||||
|
||||
|
||||
__re_int__ = re.compile("^[+-]?[0-9]+$")
|
||||
__re_float__ = re.compile("^[+-]?[0-9]+(\.[0-9]*)?([eE][+-]?[0-9]+)?$")
|
||||
__re_str__ = re.compile("""^"[^"]*"|'[^']*'$""")
|
||||
__re_dict__ = re.compile("""^\{\ *
|
||||
(
|
||||
("[^"]*"|'[^']*')
|
||||
\ *:\ *
|
||||
([^,}]+|
|
||||
"[^"]*"|
|
||||
'[^']*'
|
||||
)
|
||||
)?
|
||||
(\ *,\ *
|
||||
("[^"]*"|'[^']*')
|
||||
\ *:\ *
|
||||
([^,}]+|
|
||||
"[^"]*"|
|
||||
'[^']*'
|
||||
)
|
||||
)*\ *\}$""", re.VERBOSE)
|
||||
|
||||
__re_val__ = re.compile("""(("[^"]*"|'[^']*') *: *([^,}]+|"[^"]*"|'[^']*') *[,}] *)""")
|
||||
|
||||
cdef object __etag__(str x):
|
||||
cdef list elements
|
||||
cdef tuple i
|
||||
|
||||
if __re_int__.match(x):
|
||||
v=int(x)
|
||||
elif __re_float__.match(x):
|
||||
v=float(x)
|
||||
elif __re_str__.match(x):
|
||||
v=x[1:-1]
|
||||
elif x=='None':
|
||||
v=None
|
||||
elif x=='False':
|
||||
v=False
|
||||
elif x=='True':
|
||||
v=True
|
||||
elif __re_dict__.match(x):
|
||||
elements=__re_val__.findall(x)
|
||||
v=dict([(i[1][1:-1],__etag__(i[2])) for i in elements])
|
||||
else:
|
||||
v=x
|
||||
return v
|
||||
|
Reference in New Issue
Block a user