Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
9ebb14ae
Commit
9ebb14ae
authored
Mar 22, 2001
by
Evan Simpson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extended tag nesting exceptions to be a little more informative.
parent
534fb1cc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
4 deletions
+20
-4
lib/python/TAL/HTMLTALParser.py
lib/python/TAL/HTMLTALParser.py
+20
-4
No files found.
lib/python/TAL/HTMLTALParser.py
View file @
9ebb14ae
...
@@ -138,10 +138,26 @@ TIGHTEN_IMPLICIT_CLOSE_TAGS = (PARA_LEVEL_HTML_TAGS
...
@@ -138,10 +138,26 @@ TIGHTEN_IMPLICIT_CLOSE_TAGS = (PARA_LEVEL_HTML_TAGS
class
NestingError
(
HTMLParseError
):
class
NestingError
(
HTMLParseError
):
"""Exception raised when elements aren't properly nested."""
"""Exception raised when elements aren't properly nested."""
def
__init__
(
self
,
tagstack
,
endtag
,
position
=
(
None
,
None
)):
self
.
endtag
=
endtag
if
tagstack
:
if
len
(
tagstack
)
==
1
:
msg
=
(
'Open tag <%s> does not match close tag </%s>'
%
(
tagstack
[
0
],
endtag
))
else
:
msg
=
(
'Open tags <%s> do not match close tag </%s>'
%
(
string
.
join
(
tagstack
,
'>, <'
),
endtag
))
else
:
msg
=
'No tags are open to match </%s>'
%
endtag
HTMLParseError
.
__init__
(
self
,
msg
,
position
)
class
EmptyTagError
(
NestingError
):
"""Exception raised when empty elements have an end tag."""
def
__init__
(
self
,
tag
,
position
=
(
None
,
None
)):
def
__init__
(
self
,
tag
,
position
=
(
None
,
None
)):
self
.
tag
=
tag
self
.
tag
=
tag
HTMLParseError
.
__init__
(
self
,
"unmatched </%s>"
%
tag
,
position
)
msg
=
'Close tag </%s> should be removed'
%
tag
HTMLParseError
.
__init__
(
self
,
msg
,
position
)
class
HTMLTALParser
(
HTMLParser
):
class
HTMLTALParser
(
HTMLParser
):
...
@@ -201,7 +217,7 @@ class HTMLTALParser(HTMLParser):
...
@@ -201,7 +217,7 @@ class HTMLTALParser(HTMLParser):
def
handle_endtag
(
self
,
tag
):
def
handle_endtag
(
self
,
tag
):
if
tag
in
EMPTY_HTML_TAGS
:
if
tag
in
EMPTY_HTML_TAGS
:
# </img> etc. in the source is an error
# </img> etc. in the source is an error
raise
Nestin
gError
(
tag
,
self
.
getpos
())
raise
EmptyTa
gError
(
tag
,
self
.
getpos
())
self
.
close_enclosed_tags
(
tag
)
self
.
close_enclosed_tags
(
tag
)
self
.
gen
.
emitEndElement
(
tag
)
self
.
gen
.
emitEndElement
(
tag
)
self
.
pop_xmlns
()
self
.
pop_xmlns
()
...
@@ -233,7 +249,7 @@ class HTMLTALParser(HTMLParser):
...
@@ -233,7 +249,7 @@ class HTMLTALParser(HTMLParser):
def
close_enclosed_tags
(
self
,
tag
):
def
close_enclosed_tags
(
self
,
tag
):
if
tag
not
in
self
.
tagstack
:
if
tag
not
in
self
.
tagstack
:
raise
NestingError
(
tag
,
self
.
getpos
())
raise
NestingError
(
self
.
tagstack
,
tag
,
self
.
getpos
())
while
tag
!=
self
.
tagstack
[
-
1
]:
while
tag
!=
self
.
tagstack
[
-
1
]:
self
.
implied_endtag
(
self
.
tagstack
[
-
1
],
1
)
self
.
implied_endtag
(
self
.
tagstack
[
-
1
],
1
)
assert
self
.
tagstack
[
-
1
]
==
tag
assert
self
.
tagstack
[
-
1
]
==
tag
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment