Helpviewer/Bookmarks/NsHtmlWriter.py

branch
Py2 comp.
changeset 3057
10516539f238
parent 2525
8b507a9a2d40
parent 3002
6ffc581f00f1
child 3058
0a02c433f52d
equal deleted inserted replaced
3056:9986ec0e559a 3057:10516539f238
16 import Utilities 16 import Utilities
17 17
18 18
19 class NsHtmlWriter(QObject): 19 class NsHtmlWriter(QObject):
20 """ 20 """
21 Class implementing a writer object to generate Netscape HTML bookmark files. 21 Class implementing a writer object to generate Netscape HTML bookmark
22 files.
22 """ 23 """
23 indentSize = 4 24 indentSize = 4
24 25
25 def __init__(self): 26 def __init__(self):
26 """ 27 """
33 Public method to write an Netscape HTML bookmark file. 34 Public method to write an Netscape HTML bookmark file.
34 35
35 @param fileNameOrDevice name of the file to write (string) 36 @param fileNameOrDevice name of the file to write (string)
36 or device to write to (QIODevice) 37 or device to write to (QIODevice)
37 @param root root node of the bookmark tree (BookmarkNode) 38 @param root root node of the bookmark tree (BookmarkNode)
39 @return flag indicating success (boolean)
38 """ 40 """
39 if isinstance(fileNameOrDevice, QIODevice): 41 if isinstance(fileNameOrDevice, QIODevice):
40 f = fileNameOrDevice 42 f = fileNameOrDevice
41 else: 43 else:
42 f = QFile(fileNameOrDevice) 44 f = QFile(fileNameOrDevice)
49 def __write(self, root): 51 def __write(self, root):
50 """ 52 """
51 Private method to write an Netscape HTML bookmark file. 53 Private method to write an Netscape HTML bookmark file.
52 54
53 @param root root node of the bookmark tree (BookmarkNode) 55 @param root root node of the bookmark tree (BookmarkNode)
56 @return flag indicating success (boolean)
54 """ 57 """
55 self.__dev.write("<!DOCTYPE NETSCAPE-Bookmark-file-1>\n" 58 self.__dev.write("<!DOCTYPE NETSCAPE-Bookmark-file-1>\n"
56 "<!-- This is an automatically generated file.\n" 59 "<!-- This is an automatically generated file.\n"
57 " It will be read and overwritten.\n" 60 " It will be read and overwritten.\n"
58 " DO NOT EDIT! -->\n" 61 " DO NOT EDIT! -->\n"
59 "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=UTF-8\">\n" 62 "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html;"
63 " charset=UTF-8\">\n"
60 "<TITLE>Bookmarks</TITLE>\n" 64 "<TITLE>Bookmarks</TITLE>\n"
61 "<H1>Bookmarks</H1>\n" 65 "<H1>Bookmarks</H1>\n"
62 "\n" 66 "\n"
63 "<DL><p>\n") 67 "<DL><p>\n")
64 if root.type() == BookmarkNode.Root: 68 if root.type() == BookmarkNode.Root:
102 if node.added.isValid(): 106 if node.added.isValid():
103 added = " ADD_DATE=\"{0}\"".format(node.added.toTime_t()) 107 added = " ADD_DATE=\"{0}\"".format(node.added.toTime_t())
104 else: 108 else:
105 added = "" 109 added = ""
106 if node.modified.isValid(): 110 if node.modified.isValid():
107 modified = " LAST_MODIFIED=\"{0}\"".format(node.modified.toTime_t()) 111 modified = " LAST_MODIFIED=\"{0}\"".format(
112 node.modified.toTime_t())
108 else: 113 else:
109 modified = "" 114 modified = ""
110 if node.visited.isValid(): 115 if node.visited.isValid():
111 visited = " LAST_VISIT=\"{0}\"".format(node.visited.toTime_t()) 116 visited = " LAST_VISIT=\"{0}\"".format(node.visited.toTime_t())
112 else: 117 else:
113 visited = "" 118 visited = ""
114 119
115 self.__dev.write(" " * indent) 120 self.__dev.write(" " * indent)
116 self.__dev.write("<DT><A HREF=\"{0}\"{1}{2}{3}>{4}</A>\n".format( 121 self.__dev.write("<DT><A HREF=\"{0}\"{1}{2}{3}>{4}</A>\n".format(
117 node.url, added, modified, visited, Utilities.html_uencode(node.title) 122 node.url, added, modified, visited,
123 Utilities.html_uencode(node.title)
118 )) 124 ))
119 125
120 if node.desc: 126 if node.desc:
121 self.__dev.write(" " * indent) 127 self.__dev.write(" " * indent)
122 self.__dev.write("<DD>{0}\n".format( 128 self.__dev.write("<DD>{0}\n".format(
144 folded, added, Utilities.html_uencode(node.title) 150 folded, added, Utilities.html_uencode(node.title)
145 )) 151 ))
146 152
147 if node.desc: 153 if node.desc:
148 self.__dev.write(" " * indent) 154 self.__dev.write(" " * indent)
149 self.__dev.write("<DD>{0}\n".format("".join(node.desc.splitlines()))) 155 self.__dev.write("<DD>{0}\n".format(
156 "".join(node.desc.splitlines())))
150 157
151 self.__dev.write(" " * indent) 158 self.__dev.write(" " * indent)
152 self.__dev.write("<DL><p>\n") 159 self.__dev.write("<DL><p>\n")
153 160
154 for child in node.children(): 161 for child in node.children():

eric ide

mercurial