comparison emeraldtree/TidyTools.py @ 47:e647f30cc08e

remove backwards compat code for python < 2.4
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 03 Aug 2008 20:59:44 +0200
parents 7b33b90de8be
children
comparison
equal deleted inserted replaced
46:c228aba7258c 47:e647f30cc08e
17 ## 17 ##
18 # Tools to build element trees from HTML, using the external <b>tidy</b> 18 # Tools to build element trees from HTML, using the external <b>tidy</b>
19 # utility. 19 # utility.
20 ## 20 ##
21 21
22 import glob, string, os, sys 22 import glob, os, sys
23 23
24 from ElementTree import ElementTree, Element 24 from ElementTree import ElementTree, Element
25 25
26 NS_XHTML = "{http://www.w3.org/1999/xhtml}" 26 NS_XHTML = "{http://www.w3.org/1999/xhtml}"
27 27
38 38
39 command = ["tidy", "-qn", "-asxml"] 39 command = ["tidy", "-qn", "-asxml"]
40 40
41 if new_inline_tags: 41 if new_inline_tags:
42 command.append("--new-inline-tags") 42 command.append("--new-inline-tags")
43 command.append(string.join(new_inline_tags, ",")) 43 command.append(",".join(new_inline_tags))
44 44
45 # FIXME: support more tidy options! 45 # FIXME: support more tidy options!
46 46
47 # convert 47 # convert
48 os.system( 48 os.system(
49 "%s %s >%s.out 2>%s.err" % (string.join(command), file, file, file) 49 "%s %s >%s.out 2>%s.err" % (" ".join(command), file, file, file)
50 ) 50 )
51 # check that the result is valid XML 51 # check that the result is valid XML
52 try: 52 try:
53 tree = ElementTree() 53 tree = ElementTree()
54 tree.parse(file + ".out") 54 tree.parse(file + ".out")
108 108
109 body = getbody(file, **options) 109 body = getbody(file, **options)
110 if body is None: 110 if body is None:
111 return 111 return
112 112
113 if body.text and string.strip(body.text): 113 if body.text and body.text.strip():
114 title = Element("h1") 114 title = Element("h1")
115 title.text = string.strip(body.text) 115 title.text = body.text.strip()
116 title.tail = "\n\n" 116 title.tail = "\n\n"
117 body.insert(0, title) 117 body.insert(0, title)
118 118
119 body.text = None 119 body.text = None
120 120