Codebase list chemical-structures / a5ae8a1
fixed many details to comply with python3 Georges Khaznadar 4 years ago
1 changed file(s) with 187 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
1616 formula += i
1717 idx += 1
1818 if subBool:
19 @@ -29,7 +29,7 @@ class DataIndexWriter:
20 return formula
21
22 def WriteXHTML(self, title, lang):
23 - size = len(self.data_list)/3
24 + size = len(self.data_list)//3
25 if len(self.data_list) % 3:
26 size += 1
27 xhtmlout = xhtmlwriter.XHTMLWriter()
1928 Index: chemical-structures/tools/indexwriter.py
2029 ===================================================================
2130 --- chemical-structures.orig/tools/indexwriter.py
2231 +++ chemical-structures/tools/indexwriter.py
23 @@ -5,14 +5,14 @@ class IndexWriter:
32 @@ -5,17 +5,17 @@ class IndexWriter:
2433 """
2534 def __init__(self, fout, index_handler, l10n_handler):
2635 """Creates an instance of the class.
3645 + """
3746 xhtmlout = xhtmlwriter.XHTMLWriter()
3847 xhtmlout.setOutput(self.fout)
39 if index_title.has_key(lang):
40 @@ -37,9 +37,9 @@ class IndexWriter:
48 - if index_title.has_key(lang):
49 + if lang in index_title:
50 xhtmlout.setTitle(index_title[lang])
51 else:
52 xhtmlout.setTitle(index_title['en'])
53 @@ -37,49 +37,49 @@ class IndexWriter:
4154 xhtmlout.addBody(' </div>')
4255 xhtmlout.addBody(' </div>')
4356 xhtmlout.addBody(' <div id="main">')
5063 if len(self.index.entryList["dir"]) > 0:
5164 # Order the entry list by alphabetic order
5265 entryDict = {}
53 @@ -61,9 +61,9 @@ class IndexWriter:
66 for entry in self.index.entryList["dir"]:
67 - if entry.name.has_key(lang):
68 + if lang in entry.name:
69 entryDict[entry.name[lang]] = entry
70 else:
71 entryDict[entry.name['en']] = entry
72 - keys = entryDict.keys()
73 + keys = list(entryDict.keys())
74 keys.sort()
75 xhtmlout.addBody(' <div id="directories">')
76 xhtmlout.addBody(' <h2>'+ self.l10n.translate("Directories", lang) +'</h2>')
77 xhtmlout.addBody(' <ul id="directory_list">')
78 for key in keys:
79 entry = entryDict[key]
80 - if entry.name.has_key(lang):
81 + if lang in entry.name:
82 xhtmlout.addBody(' <li><a href="./' + entry.path + '/index_' + lang + '.html">' + entry.name[lang] + '</a></li>')
83 else:
5484 xhtmlout.addBody(' <li><a href="./' + entry.path + '/index_' + lang + '.html">' + entry.name['en'] + ' (<i>en</i>)</a></li>')
5585 xhtmlout.addBody(' </ul>')
5686 xhtmlout.addBody(' </div>')
6393 if len(self.index.entryList["file"]) > 0:
6494 # Order the entry list by alphabetic order
6595 entryDict = {}
96 for entry in self.index.entryList["file"]:
97 - if entry.name.has_key(lang):
98 + if lang in entry.name:
99 entryDict[entry.name[lang]] = entry
100 else:
101 entryDict[entry.name['en']] = entry
102 - keys = entryDict.keys()
103 + keys = list(entryDict.keys())
104 keys.sort()
105 xhtmlout.addBody(' <div id="files">')
106 xhtmlout.addBody(' <h2>' + self.l10n.translate("Names", lang) + '</h2>')
107 xhtmlout.addBody(' <ul id="directory_list">')
108 for key in keys:
109 entry = entryDict[key]
110 - if entry.name.has_key(lang):
111 + if lang in entry.name:
112 xhtmlout.addBody(' <li><a href="./' + entry.path + '_' + lang + '.html">' + entry.name[lang] + '</a></li>')
113 else:
114 xhtmlout.addBody(' <li><a href="./' + entry.path + '_' + lang + '.html">' + entry.name['en'] + ' (<i>en</i>)</a></li>')
66115 Index: chemical-structures/tools/make_index_files.py
67116 ===================================================================
68117 --- chemical-structures.orig/tools/make_index_files.py
69118 +++ chemical-structures/tools/make_index_files.py
70 @@ -44,7 +44,7 @@ def formulaCmp(tuple1, tuple2):
119 @@ -14,9 +14,10 @@ import indexhandler
120 import indexwriter
121 import nameindexwriter
122 import formulaindexwriter
123 +from functools import cmp_to_key
124
125 def get_formula_ar(file):
126 - fin = open(unicode.encode(file) + ".cml", 'r')
127 + fin = open(file + ".cml", 'r')
128 for line in fin:
129 if line.count("formula concise"):
130 idx = line.find('=') + 2
131 @@ -27,6 +28,12 @@ def get_formula_ar(file):
132 return formula_ar
133 return []
134
135 +def cmp(x,y):
136 + """
137 + simulates python2's cmp in python3
138 + """
139 + return (x>y) - (x<y)
140 +
141 def formulaCmp(tuple1, tuple2):
142 formula1 = tuple1[0][0]
143 formula2 = tuple2[0][0]
144 @@ -44,7 +51,7 @@ def formulaCmp(tuple1, tuple2):
71145
72146 sourceDir = sys.argv[1]
73147 if not os.path.isdir(sourceDir):
76150 sys.exit(1)
77151 indexFile = sys.argv[2]
78152 level = int(sys.argv[3])
79 @@ -77,7 +77,7 @@ for dir in src_list:
153 @@ -77,7 +84,7 @@ for dir in src_list:
80154 index_parser.setFeature(xml.sax.handler.feature_external_ges, 0)
81155 index_handler = indexhandler.IndexHandler()
82156 index_parser.setContentHandler(index_handler)
85159 index_parser.parse("index.xml")
86160 for entry in index_handler.entryList["file"]:
87161 name_list.append( (entry.name["en"], "./" + dir +"/" + entry.path) )
162 @@ -85,7 +92,7 @@ for dir in src_list:
163 os.chdir(os.pardir)
164 os.chdir(current_binary_dir)
165 name_list.sort()
166 -formula_list.sort(formulaCmp)
167 +formula_list.sort(key=cmp_to_key(formulaCmp))
168 data_index = nameindexwriter.DataIndexWriter("name_index",name_list,l10n_handler)
169 formula_index = formulaindexwriter.DataIndexWriter("formula_index",formula_list,l10n_handler)
170
171 Index: chemical-structures/tools/cmlwriter.py
172 ===================================================================
173 --- chemical-structures.orig/tools/cmlwriter.py
174 +++ chemical-structures/tools/cmlwriter.py
175 @@ -118,7 +118,7 @@ class CMLWriter:
176 return formula
177
178 def WriteXHTML(self, entry_details, lang, level):
179 - if entry_details.name.has_key(lang):
180 + if lang in entry_details.name:
181 title = entry_details.name[lang]
182 else:
183 title = entry_details.name['en']
184 @@ -182,7 +182,7 @@ class CMLWriter:
185 # Write only if synonyms (localized or english) are
186 # available
187 #########################################################
188 - if entry_details.synDict.has_key(lang):
189 + if lang in entry_details.synDict:
190 if len(entry_details.synDict[lang]) == 1:
191 xhtmlout.addBody(' <li>' + self.l10n.translate('Synonym:', lang) )
192 else:
193 @@ -192,7 +192,7 @@ class CMLWriter:
194 xhtmlout.addBody(' <li>' + synonym + '</li>')
195 xhtmlout.addBody(' </ul>')
196 xhtmlout.addBody(' </li>')
197 - elif entry_details.synDict.has_key('en'):
198 + elif 'en' in entry_details.synDict:
199 if len(entry_details.synDict['en']) == 1:
200 xhtmlout.addBody(' <li>' + self.l10n.translate('Synonym:', lang) )
201 else:
202 Index: chemical-structures/tools/l10nhandler.py
203 ===================================================================
204 --- chemical-structures.orig/tools/l10nhandler.py
205 +++ chemical-structures/tools/l10nhandler.py
206 @@ -41,8 +41,8 @@ class L10NHandler(xml.sax.handler.Conten
207 self.inMsgid = True
208
209 if name == "msg":
210 - if attributes.has_key('xml:lang'):
211 - self.msgLang = unicode.encode(attributes["xml:lang"])
212 + if 'xml:lang' in attributes:
213 + self.msgLang = attributes["xml:lang"]
214 else:
215 self.msgLang = "en"
216 self.inMsg = True
217 @@ -92,7 +92,7 @@ class L10NHandler(xml.sax.handler.Conten
218 a string - either the translated string if the translation is
219 available or the msgid in other cases.
220 """
221 - if self.msgDict.has_key(msgid) and self.msgDict[msgid].has_key(lang):
222 + if msgid in self.msgDict and lang in self.msgDict[msgid]:
223 return self.msgDict[msgid][lang]
224 else:
225 return msgid
226 Index: chemical-structures/tools/indexhandler.py
227 ===================================================================
228 --- chemical-structures.orig/tools/indexhandler.py
229 +++ chemical-structures/tools/indexhandler.py
230 @@ -66,8 +66,8 @@ class IndexHandler(xml.sax.handler.Conte
231 """
232 if name == "title":
233 self.inTitle = True
234 - if attributes.has_key("xml:lang"):
235 - self.titleLang = unicode.encode(attributes["xml:lang"])
236 + if "xml:lang" in attributes:
237 + self.titleLang = attributes["xml:lang"]
238 if self.titleLang == "":
239 self.titleLang = "en"
240 else:
241 @@ -80,8 +80,8 @@ class IndexHandler(xml.sax.handler.Conte
242
243 if name == "name":
244 self.inName = True
245 - if attributes.has_key("xml:lang"):
246 - self.nameLang = unicode.encode(attributes["xml:lang"])
247 + if "xml:lang" in attributes:
248 + self.nameLang = attributes["xml:lang"]
249 if self.nameLang == "":
250 self.nameLang = "en"
251 else:
252 @@ -98,13 +98,13 @@ class IndexHandler(xml.sax.handler.Conte
253
254 if name == "synonym":
255 self.inSynonym = True
256 - if attributes.has_key("xml:lang"):
257 - self.synLang = unicode.encode(attributes["xml:lang"])
258 + if "xml:lang" in attributes:
259 + self.synLang = attributes["xml:lang"]
260 if self.synLang == "":
261 self.synLang = "en"
262 else:
263 self.synLang ="en"
264 - if not self.entry.synDict.has_key(self.synLang):
265 + if not self.synLang in self.entry.synDict:
266 self.entry.synDict[self.synLang] = []
267
268 if name == "abbrev":