File: python3-conformity.patch

package info (click to toggle)
chemical-structures 2.2.dfsg.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,808 kB
  • sloc: xml: 7,224; javascript: 1,194; python: 993; sh: 51; makefile: 42
file content (284 lines) | stat: -rw-r--r-- 11,077 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
From: Debian Science Maintainers
 <debian-science-maintainers@lists.alioth.debian.org>
Date: Mon, 29 Sep 2025 16:11:15 +0200
Subject: python3-conformity

===================================================================
---
 tools/cmlwriter.py          |  6 +++---
 tools/formulaindexwriter.py |  6 +++---
 tools/indexhandler.py       | 14 +++++++-------
 tools/indexwriter.py        | 30 +++++++++++++++---------------
 tools/l10nhandler.py        |  6 +++---
 tools/make_index_files.py   | 15 +++++++++++----
 6 files changed, 42 insertions(+), 35 deletions(-)

diff --git a/tools/cmlwriter.py b/tools/cmlwriter.py
index 6a04f09..77cd749 100644
--- a/tools/cmlwriter.py
+++ b/tools/cmlwriter.py
@@ -118,7 +118,7 @@ class CMLWriter:
         return formula
 
     def WriteXHTML(self, entry_details, lang, level):
-        if entry_details.name.has_key(lang):
+        if lang in entry_details.name:
             title = entry_details.name[lang]
         else:
             title = entry_details.name['en']
@@ -182,7 +182,7 @@ class CMLWriter:
         # Write only if synonyms (localized or english) are
         # available
         #########################################################
-        if entry_details.synDict.has_key(lang):
+        if lang in entry_details.synDict:
             if len(entry_details.synDict[lang]) == 1:
                 xhtmlout.addBody('            <li>' + self.l10n.translate('Synonym:', lang) )
             else:
@@ -192,7 +192,7 @@ class CMLWriter:
                 xhtmlout.addBody('                <li>' + synonym + '</li>')
             xhtmlout.addBody('              </ul>')
             xhtmlout.addBody('            </li>')
-        elif entry_details.synDict.has_key('en'):
+        elif 'en' in entry_details.synDict:
             if len(entry_details.synDict['en']) == 1:
                 xhtmlout.addBody('            <li>' + self.l10n.translate('Synonym:', lang) )
             else:
diff --git a/tools/formulaindexwriter.py b/tools/formulaindexwriter.py
index e55e8e7..79235ec 100644
--- a/tools/formulaindexwriter.py
+++ b/tools/formulaindexwriter.py
@@ -16,12 +16,12 @@ class DataIndexWriter:
         continue
       if idx % 2:
         formula += "<sub>" + i
-	subBool = True
+        subBool = True
         idx += 1
       else:
         if subBool:
           formula += "</sub>"
-	  subBool = False
+          subBool = False
         formula += i
         idx += 1
     if subBool:
@@ -29,7 +29,7 @@ class DataIndexWriter:
     return formula
   
   def WriteXHTML(self, title, lang):
-    size = len(self.data_list)/3
+    size = len(self.data_list)//3
     if len(self.data_list) % 3:
         size += 1
     xhtmlout = xhtmlwriter.XHTMLWriter()
diff --git a/tools/indexhandler.py b/tools/indexhandler.py
index 6a38e61..e698e58 100644
--- a/tools/indexhandler.py
+++ b/tools/indexhandler.py
@@ -66,8 +66,8 @@ class IndexHandler(xml.sax.handler.ContentHandler):
         """
         if name == "title":
             self.inTitle = True
-            if attributes.has_key("xml:lang"):
-                self.titleLang = unicode.encode(attributes["xml:lang"])
+            if "xml:lang" in attributes:
+                self.titleLang = attributes["xml:lang"]
                 if self.titleLang == "":
                     self.titleLang = "en"
             else:
@@ -80,8 +80,8 @@ class IndexHandler(xml.sax.handler.ContentHandler):
 
         if name == "name":
             self.inName = True
-            if attributes.has_key("xml:lang"):
-                self.nameLang = unicode.encode(attributes["xml:lang"])
+            if "xml:lang" in attributes:
+                self.nameLang = attributes["xml:lang"]
                 if self.nameLang == "":
                     self.nameLang = "en"
             else:
@@ -98,13 +98,13 @@ class IndexHandler(xml.sax.handler.ContentHandler):
 
         if name == "synonym":
             self.inSynonym = True
-            if attributes.has_key("xml:lang"):
-                self.synLang = unicode.encode(attributes["xml:lang"])
+            if "xml:lang" in attributes:
+                self.synLang = attributes["xml:lang"]
                 if self.synLang == "":
                     self.synLang = "en"
             else:
                 self.synLang ="en"
-            if not self.entry.synDict.has_key(self.synLang):
+            if not self.synLang in self.entry.synDict:
                 self.entry.synDict[self.synLang] = []
 
         if name == "abbrev":
diff --git a/tools/indexwriter.py b/tools/indexwriter.py
index e57385b..71322ad 100644
--- a/tools/indexwriter.py
+++ b/tools/indexwriter.py
@@ -5,17 +5,17 @@ class IndexWriter:
     """
     def __init__(self, fout, index_handler, l10n_handler):
         """Creates an instance of the class.
-	"""
+        """
         self.fout = fout
         self.index = index_handler
         self.l10n = l10n_handler
 
     def WriteXHTML(self, index_title, lang, level):
         """
-	"""
+        """
         xhtmlout = xhtmlwriter.XHTMLWriter()
         xhtmlout.setOutput(self.fout)
-        if index_title.has_key(lang):
+        if lang in index_title:
             xhtmlout.setTitle(index_title[lang])
         else:
             xhtmlout.setTitle(index_title['en'])
@@ -37,49 +37,49 @@ class IndexWriter:
         xhtmlout.addBody('      </div>')
         xhtmlout.addBody('    </div>')
         xhtmlout.addBody('    <div id="main">')
-	"""
-	Create a list of directories
-	"""
+        """
+        Create a list of directories
+        """
         if len(self.index.entryList["dir"]) > 0:
             # Order the entry list by alphabetic order
             entryDict = {}
             for entry in self.index.entryList["dir"]:
-                if entry.name.has_key(lang):
+                if lang in entry.name:
                     entryDict[entry.name[lang]] = entry
                 else:
                     entryDict[entry.name['en']] = entry
-            keys = entryDict.keys()
+            keys = list(entryDict.keys())
             keys.sort()
             xhtmlout.addBody('      <div id="directories">')
             xhtmlout.addBody('        <h2>'+ self.l10n.translate("Directories", lang) +'</h2>')
             xhtmlout.addBody('        <ul id="directory_list">')
             for key in keys:
                 entry = entryDict[key]
-                if entry.name.has_key(lang):
+                if lang in entry.name:
                     xhtmlout.addBody('          <li><a href="./' + entry.path + '/index_' + lang + '.html">' + entry.name[lang] + '</a></li>')
                 else:
                     xhtmlout.addBody('          <li><a href="./' + entry.path + '/index_' + lang + '.html">' + entry.name['en'] + ' (<i>en</i>)</a></li>')
             xhtmlout.addBody('        </ul>')
             xhtmlout.addBody('      </div>')
-	"""
-	Create list of files
-	"""
+        """
+        Create list of files
+        """
         if len(self.index.entryList["file"]) > 0:
             # Order the entry list by alphabetic order
             entryDict = {}
             for entry in self.index.entryList["file"]:
-                if entry.name.has_key(lang):
+                if lang in entry.name:
                     entryDict[entry.name[lang]] = entry
                 else:
                     entryDict[entry.name['en']] = entry
-            keys = entryDict.keys()
+            keys = list(entryDict.keys())
             keys.sort()
             xhtmlout.addBody('      <div id="files">')
             xhtmlout.addBody('        <h2>' + self.l10n.translate("Names", lang) + '</h2>')
             xhtmlout.addBody('        <ul id="directory_list">')
             for key in keys:
                 entry = entryDict[key]
-                if entry.name.has_key(lang):
+                if lang in entry.name:
                     xhtmlout.addBody('            <li><a href="./' + entry.path + '_' + lang + '.html">' + entry.name[lang] + '</a></li>')
                 else:
                     xhtmlout.addBody('            <li><a href="./' + entry.path + '_' + lang + '.html">' + entry.name['en'] + ' (<i>en</i>)</a></li>')
diff --git a/tools/l10nhandler.py b/tools/l10nhandler.py
index c169977..2a913cc 100644
--- a/tools/l10nhandler.py
+++ b/tools/l10nhandler.py
@@ -41,8 +41,8 @@ class L10NHandler(xml.sax.handler.ContentHandler):
             self.inMsgid = True
 
         if name == "msg":
-            if attributes.has_key('xml:lang'):
-                self.msgLang = unicode.encode(attributes["xml:lang"])
+            if 'xml:lang' in attributes:
+                self.msgLang = attributes["xml:lang"]
             else:
                 self.msgLang = "en"
             self.inMsg = True
@@ -92,7 +92,7 @@ class L10NHandler(xml.sax.handler.ContentHandler):
             a string - either the translated string if the translation is
                        available or the msgid in other cases.
         """
-        if self.msgDict.has_key(msgid) and self.msgDict[msgid].has_key(lang):
+        if msgid in self.msgDict and lang in self.msgDict[msgid]:
             return self.msgDict[msgid][lang]
         else:
             return msgid
diff --git a/tools/make_index_files.py b/tools/make_index_files.py
index 97b6eb0..280343b 100644
--- a/tools/make_index_files.py
+++ b/tools/make_index_files.py
@@ -14,9 +14,10 @@ import indexhandler
 import indexwriter
 import nameindexwriter
 import formulaindexwriter
+from functools import cmp_to_key
 
 def get_formula_ar(file):
-  fin = open(unicode.encode(file) + ".cml", 'r')
+  fin = open(file + ".cml", 'r')
   for line in fin:
     if line.count("formula concise"):
       idx = line.find('=') + 2
@@ -27,6 +28,12 @@ def get_formula_ar(file):
       return formula_ar
   return []
 
+def cmp(x,y):
+  """
+  simulates python2's cmp in python3
+  """
+  return (x>y) - (x<y)
+
 def formulaCmp(tuple1, tuple2):
   formula1 = tuple1[0][0]
   formula2 = tuple2[0][0]
@@ -44,7 +51,7 @@ def formulaCmp(tuple1, tuple2):
 
 sourceDir = sys.argv[1]
 if not os.path.isdir(sourceDir):
-    print "Error: "+ sourceDir + ": no such directory"
+    print ("Error: "+ sourceDir + ": no such directory")
     sys.exit(1)
 indexFile = sys.argv[2]
 level = int(sys.argv[3])
@@ -77,7 +84,7 @@ for dir in src_list:
       index_parser.setFeature(xml.sax.handler.feature_external_ges, 0)
       index_handler = indexhandler.IndexHandler()
       index_parser.setContentHandler(index_handler)
-      print os.path.realpath(os.path.curdir)
+      print (os.path.realpath(os.path.curdir))
       index_parser.parse("index.xml")
       for entry in index_handler.entryList["file"]:
         name_list.append( (entry.name["en"], "./" + dir +"/" + entry.path) )
@@ -85,7 +92,7 @@ for dir in src_list:
     os.chdir(os.pardir)
 os.chdir(current_binary_dir)
 name_list.sort()
-formula_list.sort(formulaCmp)
+formula_list.sort(key=cmp_to_key(formulaCmp))
 data_index = nameindexwriter.DataIndexWriter("name_index",name_list,l10n_handler)
 formula_index = formulaindexwriter.DataIndexWriter("formula_index",formula_list,l10n_handler)