Debian Codegraph @

python/obitools3/parsers/header.pyx

raw
1 #cython: language_level=3
2
3 '''
4 Created on 25 mars 2016
5
6 @author: coissac
7 '''
8
9 from obitools3.utils cimport __etag__
10 import re
11
12
13 __ret__ = re.compile(b'''(([^ ]+)=('[^']*'|"[^"]*"|[^;]+); *)+?''')
14
15
16 cpdef tuple parseHeader(bytes header, bytes nastring=b"NA"):
17 cdef list m
18 cdef dict tags
19 cdef bytes definition
20 cdef bytes ident
21 cdef bytes second
22
23 m=header[1:-1].split(maxsplit=1)
24
25 ident=m[0]
26 if len(ident)>1 and ident[-2:-1] == b';':
27 ident = ident[:-1]
28
29 if len(m)==1:
30 tags={}
31 definition=b''
32 else:
33 second=m[1]
34 m = __ret__.findall(second)
35
36 if m:
37 tags = dict([(a[1],__etag__(a[2], nastring=nastring)) for a in m])
38 definition = second.split(m[-1][0],1)[1].strip()
39 else:
40 tags = {}
41 definition = second.strip()
42
43 return ident,tags,definition
44
45