File tree 1 file changed +5
-3
lines changed 1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -25,16 +25,18 @@ def xmliter(obj, nodename):
25
25
- a unicode string
26
26
- a string encoded as utf-8
27
27
"""
28
- HEADER_START_RE = re .compile (r'^(.*?)<\s*%s(?:\s|>)' % nodename , re .S )
29
- HEADER_END_RE = re .compile (r'<\s*/%s\s*>' % nodename , re .S )
28
+ nodename_patt = re .escape (nodename )
29
+
30
+ HEADER_START_RE = re .compile (r'^(.*?)<\s*%s(?:\s|>)' % nodename_patt , re .S )
31
+ HEADER_END_RE = re .compile (r'<\s*/%s\s*>' % nodename_patt , re .S )
30
32
text = _body_or_str (obj )
31
33
32
34
header_start = re .search (HEADER_START_RE , text )
33
35
header_start = header_start .group (1 ).strip () if header_start else ''
34
36
header_end = re_rsearch (HEADER_END_RE , text )
35
37
header_end = text [header_end [1 ]:].strip () if header_end else ''
36
38
37
- r = re .compile (r"<%s [\s>].*?</%s>" % ( nodename , nodename ), re .DOTALL )
39
+ r = re .compile (r"<{0} [\s>].*?</{0}>" . format ( nodename_patt ), re .DOTALL )
38
40
for match in r .finditer (text ):
39
41
nodetext = header_start + match .group () + header_end
40
42
yield Selector (text = nodetext , type = 'xml' ).xpath ('//' + nodename )[0 ]
You can’t perform that action at this time.
0 commit comments