increase parsing speed of the header
This commit is contained in:
@ -30,20 +30,27 @@ __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):
|
||||
v=eval(x)
|
||||
elements=__re_val__.findall(x)
|
||||
v=dict([(i[1][1:-1],__etag__(i[2])) for i in elements])
|
||||
else:
|
||||
v=x
|
||||
return v
|
||||
@ -56,7 +63,7 @@ cpdef tuple parseHeader(str header):
|
||||
cdef str second
|
||||
|
||||
m=header[1:-1].split(maxsplit=1)
|
||||
|
||||
|
||||
ident=m[0]
|
||||
|
||||
if len(m)==1:
|
||||
@ -75,4 +82,4 @@ cpdef tuple parseHeader(str header):
|
||||
|
||||
return ident,tags,definition
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user