Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
aa876c40
Commit
aa876c40
authored
Aug 04, 1995
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changed comment parsing
parent
c4a0bd3c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
13 deletions
+14
-13
Lib/sgmllib.py
Lib/sgmllib.py
+14
-13
No files found.
Lib/sgmllib.py
View file @
aa876c40
...
@@ -21,7 +21,9 @@ entityref = regex.compile('&[a-zA-Z][a-zA-Z0-9]*[;.]')
...
@@ -21,7 +21,9 @@ entityref = regex.compile('&[a-zA-Z][a-zA-Z0-9]*[;.]')
charref = regex.compile('
&
#[a-zA-Z0-9]+;')
charref = regex.compile('
&
#[a-zA-Z0-9]+;')
starttagopen
=
regex
.
compile
(
'<[a-zA-Z]'
)
starttagopen
=
regex
.
compile
(
'<[a-zA-Z]'
)
endtag
=
regex
.
compile
(
'</[a-zA-Z][a-zA-Z0-9]*[
\
t
\
n
]*>'
)
endtag
=
regex
.
compile
(
'</[a-zA-Z][a-zA-Z0-9]*[
\
t
\
n
]*>'
)
special
=
regex
.
compile
(
'<![^<>]*>'
)
commentopen
=
regex
.
compile
(
'<!--'
)
commentopen
=
regex
.
compile
(
'<!--'
)
commentclose
=
regex
.
compile
(
'--[
\
t
\
n
]*>'
)
# SGML parser base class -- find tags and call handler functions.
# SGML parser base class -- find tags and call handler functions.
...
@@ -111,6 +113,14 @@ class SGMLParser:
...
@@ -111,6 +113,14 @@ class SGMLParser:
if
k
<
0
:
break
if
k
<
0
:
break
i
=
i
+
k
i
=
i
+
k
continue
continue
k
=
special
.
match
(
rawdata
,
i
)
if
k
>=
0
:
if
self
.
literal
:
self
.
handle_data
(
rawdata
[
i
])
i
=
i
+
1
continue
i
=
i
+
k
continue
elif
rawdata
[
i
]
==
'&'
:
elif
rawdata
[
i
]
==
'&'
:
k
=
charref
.
match
(
rawdata
,
i
)
k
=
charref
.
match
(
rawdata
,
i
)
if
k
>=
0
:
if
k
>=
0
:
...
@@ -141,25 +151,16 @@ class SGMLParser:
...
@@ -141,25 +151,16 @@ class SGMLParser:
self
.
rawdata
=
rawdata
[
i
:]
self
.
rawdata
=
rawdata
[
i
:]
# XXX if end: check for empty stack
# XXX if end: check for empty stack
# Internal -- parse comment, return length or -1 if not ter
nim
ated
# Internal -- parse comment, return length or -1 if not ter
min
ated
def
parse_comment
(
self
,
i
):
def
parse_comment
(
self
,
i
):
rawdata
=
self
.
rawdata
rawdata
=
self
.
rawdata
if
rawdata
[
i
:
i
+
4
]
<>
'<!--'
:
if
rawdata
[
i
:
i
+
4
]
<>
'<!--'
:
raise
RuntimeError
,
'unexpected call to handle_comment'
raise
RuntimeError
,
'unexpected call to handle_comment'
try
:
j
=
commentclose
.
search
(
rawdata
,
i
+
4
)
j
=
string
.
index
(
rawdata
,
'--'
,
i
+
4
)
if
j
<
0
:
except
string
.
index_error
:
return
-
1
return
-
1
self
.
handle_comment
(
rawdata
[
i
+
4
:
j
])
self
.
handle_comment
(
rawdata
[
i
+
4
:
j
])
j
=
j
+
2
j
=
j
+
commentclose
.
match
(
rawdata
,
j
)
n
=
len
(
rawdata
)
while
j
<
n
and
rawdata
[
j
]
in
'
\
t
\
n
'
:
j
=
j
+
1
if
j
==
n
:
return
-
1
# Wait for final '>'
if
rawdata
[
j
]
==
'>'
:
j
=
j
+
1
else
:
print
'*** comment not terminated with >'
print
repr
(
rawdata
[
j
-
5
:
j
]),
'*!*'
,
repr
(
rawdata
[
j
:
j
+
5
])
return
j
-
i
return
j
-
i
# Internal -- handle starttag, return length or -1 if not terminated
# Internal -- handle starttag, return length or -1 if not terminated
...
...
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