increase parsing speed of the header
This commit is contained in:
@ -30,20 +30,27 @@ __re_dict__ = re.compile("""^\{\ *
|
|||||||
)
|
)
|
||||||
)*\ *\}$""", re.VERBOSE)
|
)*\ *\}$""", re.VERBOSE)
|
||||||
|
|
||||||
|
__re_val__ = re.compile("""(("[^"]*"|'[^']*') *: *([^,}]+|"[^"]*"|'[^']*') *[,}] *)""")
|
||||||
|
|
||||||
cdef object __etag__(str x):
|
cdef object __etag__(str x):
|
||||||
|
cdef list elements
|
||||||
|
cdef tuple i
|
||||||
|
|
||||||
if __re_int__.match(x):
|
if __re_int__.match(x):
|
||||||
v=int(x)
|
v=int(x)
|
||||||
elif __re_float__.match(x):
|
elif __re_float__.match(x):
|
||||||
v=float(x)
|
v=float(x)
|
||||||
elif __re_str__.match(x):
|
elif __re_str__.match(x):
|
||||||
v=x[1:-1]
|
v=x[1:-1]
|
||||||
|
elif x=='None':
|
||||||
|
v=None
|
||||||
elif x=='False':
|
elif x=='False':
|
||||||
v=False
|
v=False
|
||||||
elif x=='True':
|
elif x=='True':
|
||||||
v=True
|
v=True
|
||||||
elif __re_dict__.match(x):
|
elif __re_dict__.match(x):
|
||||||
v=eval(x)
|
elements=__re_val__.findall(x)
|
||||||
|
v=dict([(i[1][1:-1],__etag__(i[2])) for i in elements])
|
||||||
else:
|
else:
|
||||||
v=x
|
v=x
|
||||||
return v
|
return v
|
||||||
@ -56,7 +63,7 @@ cpdef tuple parseHeader(str header):
|
|||||||
cdef str second
|
cdef str second
|
||||||
|
|
||||||
m=header[1:-1].split(maxsplit=1)
|
m=header[1:-1].split(maxsplit=1)
|
||||||
|
|
||||||
ident=m[0]
|
ident=m[0]
|
||||||
|
|
||||||
if len(m)==1:
|
if len(m)==1:
|
||||||
@ -75,4 +82,4 @@ cpdef tuple parseHeader(str header):
|
|||||||
|
|
||||||
return ident,tags,definition
|
return ident,tags,definition
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user