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
f82e4ab6
Commit
f82e4ab6
authored
Jan 19, 1999
by
Fred Drake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
format_attrs(): Attempt a bit more minimization for SGML output.
parent
9bbdce59
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
4 deletions
+22
-4
Doc/tools/sgmlconv/esis2sgml.py
Doc/tools/sgmlconv/esis2sgml.py
+22
-4
No files found.
Doc/tools/sgmlconv/esis2sgml.py
View file @
f82e4ab6
...
...
@@ -15,15 +15,33 @@ import string
from
xml.utils
import
escape
def
format_attrs
(
attrs
):
def
format_attrs
(
attrs
,
xml
=
0
):
attrs
=
attrs
.
items
()
attrs
.
sort
()
s
=
''
for
name
,
value
in
attrs
:
s
=
'%s %s="%s"'
%
(
s
,
name
,
escape
(
value
))
if
xml
:
s
=
'%s %s="%s"'
%
(
s
,
name
,
escape
(
value
))
else
:
# this is a little bogus, but should do for now
if
name
==
value
and
isnmtoken
(
value
):
s
=
"%s %s"
%
(
s
,
value
)
elif
istoken
(
value
):
s
=
"%s %s=%s"
%
(
s
,
name
,
value
)
else
:
s
=
'%s %s="%s"'
%
(
s
,
name
,
escape
(
value
))
return
s
_nmtoken_rx
=
re
.
compile
(
"[a-z][-._a-z0-9]*"
,
re
.
IGNORECASE
)
def
isnmtoken
(
s
):
return
_nmtoken_rx
.
match
(
s
)
is
not
None
_token_rx
=
re
.
compile
(
"[a-z0-9][-._a-z0-9]*"
,
re
.
IGNORECASE
)
def
istoken
(
s
):
return
_token_rx
.
match
(
s
)
is
not
None
def
do_convert
(
ifp
,
ofp
,
xml
=
0
):
attrs
=
{}
lastopened
=
None
...
...
@@ -51,9 +69,9 @@ def do_convert(ifp, ofp, xml=0):
ofp
.
write
(
"<!--"
)
continue
if
knownempty
and
xml
:
ofp
.
write
(
"<%s%s/>"
%
(
data
,
format_attrs
(
attrs
)))
ofp
.
write
(
"<%s%s/>"
%
(
data
,
format_attrs
(
attrs
,
xml
)))
else
:
ofp
.
write
(
"<%s%s>"
%
(
data
,
format_attrs
(
attrs
)))
ofp
.
write
(
"<%s%s>"
%
(
data
,
format_attrs
(
attrs
,
xml
)))
if
knownempty
and
data
not
in
knownempties
:
# accumulate knowledge!
knownempties
.
append
(
data
)
...
...
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