Some minor cleanup.
This commit is contained in:
parent
bc2285eb60
commit
f032cdbb24
|
@ -77,7 +77,7 @@ def istoken(s):
|
||||||
return _token_rx.match(s) is not None
|
return _token_rx.match(s) is not None
|
||||||
|
|
||||||
|
|
||||||
def do_convert(ifp, ofp, xml=0, autoclose=(), verbatims=()):
|
def convert(ifp, ofp, xml=0, autoclose=(), verbatims=()):
|
||||||
if xml:
|
if xml:
|
||||||
autoclose = ()
|
autoclose = ()
|
||||||
attrs = {}
|
attrs = {}
|
||||||
|
@ -152,26 +152,27 @@ def do_convert(ifp, ofp, xml=0, autoclose=(), verbatims=()):
|
||||||
|
|
||||||
|
|
||||||
def dump_empty_element_names(knownempties):
|
def dump_empty_element_names(knownempties):
|
||||||
|
d = {}
|
||||||
|
for gi in knownempties:
|
||||||
|
d[gi] = gi
|
||||||
knownempties.append("")
|
knownempties.append("")
|
||||||
if os.path.isfile(EMPTIES_FILENAME):
|
if os.path.isfile(EMPTIES_FILENAME):
|
||||||
mode = "a"
|
fp = open(EMPTIES_FILENAME)
|
||||||
else:
|
while 1:
|
||||||
mode = "w"
|
line = fp.readline()
|
||||||
fp = open(EMPTIES_FILENAME, mode)
|
if not line:
|
||||||
fp.write(string.join(knownempties, "\n"))
|
break
|
||||||
|
gi = string.strip(line)
|
||||||
|
if gi:
|
||||||
|
d[gi] = gi
|
||||||
|
fp = open(EMPTIES_FILENAME, "w")
|
||||||
|
gilist = d.keys()
|
||||||
|
gilist.sort()
|
||||||
|
fp.write(string.join(gilist, "\n"))
|
||||||
|
fp.write("\n")
|
||||||
fp.close()
|
fp.close()
|
||||||
|
|
||||||
|
|
||||||
def sgml_convert(ifp, ofp, autoclose, verbatims):
|
|
||||||
return do_convert(ifp, ofp, xml=0,
|
|
||||||
autoclose=autoclose, verbatims=verbatims)
|
|
||||||
|
|
||||||
|
|
||||||
def xml_convert(ifp, ofp, autoclose, verbatims):
|
|
||||||
return do_convert(ifp, ofp, xml=1,
|
|
||||||
autoclose=autoclose, verbatims=verbatims)
|
|
||||||
|
|
||||||
|
|
||||||
def update_gi_map(map, names, fromsgml=1):
|
def update_gi_map(map, names, fromsgml=1):
|
||||||
for name in string.split(names, ","):
|
for name in string.split(names, ","):
|
||||||
if fromsgml:
|
if fromsgml:
|
||||||
|
@ -186,7 +187,6 @@ def main():
|
||||||
import sys
|
import sys
|
||||||
#
|
#
|
||||||
autoclose = AUTOCLOSE
|
autoclose = AUTOCLOSE
|
||||||
convert = xml_convert
|
|
||||||
xml = 1
|
xml = 1
|
||||||
xmldecl = 0
|
xmldecl = 0
|
||||||
elem_names = ''
|
elem_names = ''
|
||||||
|
@ -205,10 +205,8 @@ def main():
|
||||||
LIST_EMPTIES = 1
|
LIST_EMPTIES = 1
|
||||||
elif opt in ("-s", "--sgml"):
|
elif opt in ("-s", "--sgml"):
|
||||||
xml = 0
|
xml = 0
|
||||||
convert = sgml_convert
|
|
||||||
elif opt in ("-x", "--xml"):
|
elif opt in ("-x", "--xml"):
|
||||||
xml = 1
|
xml = 1
|
||||||
convert = xml_convert
|
|
||||||
elif opt in ("-a", "--autoclose"):
|
elif opt in ("-a", "--autoclose"):
|
||||||
autoclose = string.split(arg, ",")
|
autoclose = string.split(arg, ",")
|
||||||
elif opt == "--elements-map":
|
elif opt == "--elements-map":
|
||||||
|
@ -252,7 +250,7 @@ def main():
|
||||||
try:
|
try:
|
||||||
if xml and xmldecl:
|
if xml and xmldecl:
|
||||||
opf.write('<?xml version="1.0" encoding="iso8859-1"?>\n')
|
opf.write('<?xml version="1.0" encoding="iso8859-1"?>\n')
|
||||||
convert(ifp, ofp, autoclose, verbatims)
|
convert(ifp, ofp, xml=xml, autoclose=autoclose, verbatims=verbatims)
|
||||||
except IOError, (err, msg):
|
except IOError, (err, msg):
|
||||||
if err != errno.EPIPE:
|
if err != errno.EPIPE:
|
||||||
raise
|
raise
|
||||||
|
|
Loading…
Reference in New Issue