summaryrefslogtreecommitdiffstats
path: root/lib/kformula
diff options
context:
space:
mode:
authorSlávek Banko <slavek.banko@axis.cz>2023-01-22 02:02:13 +0100
committerSlávek Banko <slavek.banko@axis.cz>2023-01-22 02:02:13 +0100
commit86480e58eafc1fa3486e03155ed34e02b4595a24 (patch)
tree0e8f64c4003ea558e946b7a3347688904b451635 /lib/kformula
parent135d005014a1e85295af4e379f026a361537ae5f (diff)
downloadkoffice-86480e58eafc1fa3486e03155ed34e02b4595a24.tar.gz
koffice-86480e58eafc1fa3486e03155ed34e02b4595a24.zip
Drop python2 support in scripts.
Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
Diffstat (limited to 'lib/kformula')
-rw-r--r--lib/kformula/prototype/gensymbolfontmap.py48
-rwxr-xr-xlib/kformula/prototype/unicode.py18
-rwxr-xr-xlib/kformula/scripts/bycodes.py10
-rwxr-xr-xlib/kformula/scripts/bynames.py22
-rwxr-xr-xlib/kformula/scripts/oper-dict.py38
5 files changed, 68 insertions, 68 deletions
diff --git a/lib/kformula/prototype/gensymbolfontmap.py b/lib/kformula/prototype/gensymbolfontmap.py
index df06eeed..1aec3d94 100644
--- a/lib/kformula/prototype/gensymbolfontmap.py
+++ b/lib/kformula/prototype/gensymbolfontmap.py
@@ -16,14 +16,14 @@ class ContentGenerator(handler.ContentHandler):
def startElement(self, name, attrs):
if name == 'unicodetable':
self.font = None
- for (name, value) in attrs.items():
+ for (name, value) in list(attrs.items()):
if name == "font" and value:
self.font = value
if value not in fonttable:
fonttable[value] = []
elif self.font and name == 'entry':
number = ''
- for (name, value) in attrs.items():
+ for (name, value) in list(attrs.items()):
if name == "key": key = int(value)
elif name == "number": number = value
elif name == "name": latexName = value
@@ -53,13 +53,13 @@ def writeFontTable(fontname, f):
def write_header(f):
- print >>f, '''//
+ print('''//
// Created: ''' + time.ctime(time.time()) + '''
// by: gensymbolfontmap.py
// from: symbol.xml
//
// WARNING! All changes made in this file will be lost!
-'''
+''', file=f)
def main():
f = open('../symbolfontmapping.cpp', 'w')
@@ -109,8 +109,8 @@ def main():
f = open('../unicodenames.cpp', 'w')
write_header(f)
- print >>f, 'struct UnicodeNameTable { short unicode; const char* name; };'
- print >>f, 'static UnicodeNameTable nameTable[] = {'
+ print('struct UnicodeNameTable { short unicode; const char* name; };', file=f)
+ print('static UnicodeNameTable nameTable[] = {', file=f)
nameDir = {}
table = {}
for style in unicodetable:
@@ -121,9 +121,9 @@ def main():
if len(latexName) > 0:
#for fn in fontnames:
# if fontkey(fn, style, key):
- print >>f, ' { ' + key + ', "' + latexName + '" },'
+ print(' { ' + key + ', "' + latexName + '" },', file=f)
#break
- print >>f, ' { 0, 0 }\n};'
+ print(' { 0, 0 }\n};', file=f)
f.close()
@@ -132,12 +132,12 @@ def make_unicode_table():
header = []
codes = {}
f = open('../config/unicode.tbl', 'r')
- for line in f.xreadlines():
+ for line in f:
if line[0] == '#':
header.append(line.strip())
else:
break
- for line in f.xreadlines():
+ for line in f:
if len(line) > 0:
codes[line.split(',')[0].strip()] = line
f.close()
@@ -151,9 +151,9 @@ def make_unicode_table():
f = open('../config/unicode.tbl', 'w')
for line in header:
- print >> f, line
+ print(line, file=f)
for key in codes:
- print >> f, codes[key]
+ print(codes[key], file=f)
f.close()
def make_font_table(font):
@@ -178,7 +178,7 @@ def make_font_table(font):
latexName, charClass = unicodetable[key]
pos = fontkey(font, key)
if pos:
- print >> f, str(pos), key, charClass, latexName
+ print(str(pos), key, charClass, latexName, file=f)
f.close()
def make_all_font_tables():
@@ -186,30 +186,30 @@ def make_all_font_tables():
make_font_table(font)
-def symbol_entry(pos, unicode, charClass, name):
+def symbol_entry(pos, str, charClass, name):
return ' <entry key="%d" number="%s" name="%s" class="%s"/>' % \
- (pos, unicode, name, charClass)
+ (pos, str, name, charClass)
def compare_font(font):
for line in file(font+".font"):
list = line.split()
pos = int(list[0])
- unicode = list[1]
+ str = list[1]
charClass = list[2]
if len(list)>3:
name = list[3]
else:
name = ""
- if (pos, unicode) not in fonttable[font]:
- print "not in font", font, (pos, unicode)
- print symbol_entry(pos, unicode, charClass, name)
- if unicode not in unicodetable:
- print font, unicode, (name, charClass)
- print symbol_entry(pos, unicode, charClass, name)
- elif unicodetable[unicode] != (name, charClass):
- print font, unicode, pos, unicodetable[unicode], "!=", (name, charClass)
+ if (pos, str) not in fonttable[font]:
+ print("not in font", font, (pos, str))
+ print(symbol_entry(pos, str, charClass, name))
+ if str not in unicodetable:
+ print(font, str, (name, charClass))
+ print(symbol_entry(pos, str, charClass, name))
+ elif unicodetable[str] != (name, charClass):
+ print(font, str, pos, unicodetable[str], "!=", (name, charClass))
def compare():
fontnames = [ "symbol",
diff --git a/lib/kformula/prototype/unicode.py b/lib/kformula/prototype/unicode.py
index cee5ea6c..ca495d25 100755
--- a/lib/kformula/prototype/unicode.py
+++ b/lib/kformula/prototype/unicode.py
@@ -127,21 +127,21 @@ class Widget(TQWidget):
self.fonts[self.child.fontName] = self.child.fontList()
f = open("symbol.xml", "w")
- print >> f, '<?xml version="1.0" encoding="iso-8859-1"?>'
- print >> f, '<table>'
+ print('<?xml version="1.0" encoding="iso-8859-1"?>', file=f)
+ print('<table>', file=f)
for font in self.fonts:
- print >> f, ' <unicodetable font="' + font + '">'
+ print(' <unicodetable font="' + font + '">', file=f)
for (key, number, latexName, charClass) in self.fonts[font]:
if not charClass or charClass == '':
charClass = 'ORDINARY'
- print >> f, ' <entry key="' + str(key) + \
+ print(' <entry key="' + str(key) + \
'" number="' + str(number) + \
'" name="' + str(latexName) + \
'" class="' + str(charClass) + \
- '"/>'
+ '"/>', file=f)
- print >> f, ' </unicodetable>'
- print >> f, '</table>'
+ print(' </unicodetable>', file=f)
+ print('</table>', file=f)
f.close()
@@ -153,14 +153,14 @@ class ContentGenerator(handler.ContentHandler):
def startElement(self, name, attrs):
if name == 'unicodetable':
- for (name, value) in attrs.items():
+ for (name, value) in list(attrs.items()):
if name == "font":
self.currentFont = value
self.fonts[self.currentFont] = []
elif name == 'entry':
if not self.currentFont:
raise "entry must belong to a font"
- for (name, value) in attrs.items():
+ for (name, value) in list(attrs.items()):
if name == "key":
if len(value) > 1 and value[:2] == "0x":
key = int(value[2:], 16)
diff --git a/lib/kformula/scripts/bycodes.py b/lib/kformula/scripts/bycodes.py
index 45b787a0..fdd84269 100755
--- a/lib/kformula/scripts/bycodes.py
+++ b/lib/kformula/scripts/bycodes.py
@@ -25,11 +25,11 @@ from TQt import qt
def decode( fd, font, line ):
begin = string.find( line, '"' )
end = string.find( line, '"', begin + 1)
- unicode = line[begin + 2:end] # Remove 'U' from string aswell
+ str = line[begin + 2:end] # Remove 'U' from string aswell
char_list = []
- separation = string.find( unicode, '-' )
+ separation = string.find( str, '-' )
if separation != -1:
- second = unicode
+ second = str
while separation != -1:
first = second[0:separation]
second = second[separation + 2:]
@@ -38,13 +38,13 @@ def decode( fd, font, line ):
if separation == -1:
char_list.append( string.atoi( second, 16 ) )
else:
- char_list.append( string.atoi ( unicode, 16 ) )
+ char_list.append( string.atoi ( str, 16 ) )
fm = qt.TQFontMetrics( qt.TQFont( font ) )
in_font = True
for c in char_list:
if not fm.inFont( qt.TQChar( c ) ):
in_font = False
- fd.write( unicode + ' ' + str( in_font ) + '\n')
+ fd.write( str + ' ' + str( in_font ) + '\n')
def parse( file, font ):
fd = open( file )
diff --git a/lib/kformula/scripts/bynames.py b/lib/kformula/scripts/bynames.py
index 6b8c1d7a..fbd1ba5e 100755
--- a/lib/kformula/scripts/bynames.py
+++ b/lib/kformula/scripts/bynames.py
@@ -24,7 +24,7 @@ import time
import os
def write_header( f ):
- print >> f, '''//
+ print('''//
// Created: ''' + time.ctime(time.time()) + '''
// by: ''' + os.path.basename( sys.argv[0] ) + '''
// from: ''' + os.path.basename( sys.argv[1] ) + '''
@@ -49,10 +49,10 @@ def write_header( f ):
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
-'''
+''', file=f)
def write_h( f ):
- print >>f, '''
+ print('''
#ifndef ENTITIES_H
#define ENTITIES_H
@@ -74,19 +74,19 @@ extern const entityMap entities[];
KFORMULA_NAMESPACE_END
#endif // ENTITIES_H
-'''
+''', file=f)
def write_cc( fr, fw ):
- print >> fw, '''
+ print('''
#include "entities.h"
KFORMULA_NAMESPACE_BEGIN
-const entityMap entities[] = {'''
+const entityMap entities[] = {''', file=fw)
parse( fr, fw )
- print >> fw, '''
+ print('''
};
// Needed since sizeof is a macro and we cannot be used until size is known
@@ -96,7 +96,7 @@ int entityMap::size()
}
KFORMULA_NAMESPACE_END
- '''
+ ''', file=fw)
def name_cmp( a, b ):
@@ -104,7 +104,7 @@ def name_cmp( a, b ):
return -1
if a[0] > b[0]:
return 1
- print 'WARNING: Same name in entity: ' + a[0] + ', ' + b[0]
+ print('WARNING: Same name in entity: ' + a[0] + ', ' + b[0])
return 0;
def parse( fr, fw ):
@@ -133,10 +133,10 @@ def parse( fr, fw ):
while True:
e = entries.pop()
fd_list.write( e[0] + ' ' + e[1] + '\n')
- print >> fw, ' {"' + e[0] + '", ' + e[1] + '}',
+ print(' {"' + e[0] + '", ' + e[1] + '}', end=' ', file=fw)
if len( entries ) == 0:
break
- print >> fw, ','
+ print(',', file=fw)
fd_list.close()
if __name__ == '__main__':
diff --git a/lib/kformula/scripts/oper-dict.py b/lib/kformula/scripts/oper-dict.py
index e9e10550..70f7868c 100755
--- a/lib/kformula/scripts/oper-dict.py
+++ b/lib/kformula/scripts/oper-dict.py
@@ -43,7 +43,7 @@ attr_list = [
def write_header( f ):
- print >> f, '''//
+ print('''//
// Created: ''' + time.ctime(time.time()) + '''
// by: ''' + os.path.basename( sys.argv[0] ) + '''
// from: ''' + os.path.basename( sys.argv[1] ) + '''
@@ -68,10 +68,10 @@ def write_header( f ):
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
-'''
+''', file=f)
def write_h( f ):
- print >>f, '''
+ print('''
#ifndef OPERATORDICTIONARY_H
#define OPERATORDICTIONARY_H
@@ -119,20 +119,20 @@ extern const OperatorDictionary operators[];
KFORMULA_NAMESPACE_END
#endif // OPERATORDICTIONARY_H
-'''
+''', file=f)
def write_cc( fr, fw ):
- print >> fw, '''
+ print('''
#include "operatordictionary.h"
KFORMULA_NAMESPACE_BEGIN
-const OperatorDictionary operators[] = {'''
+const OperatorDictionary operators[] = {''', file=fw)
entities = get_entities()
parse( fr, fw, entities )
- print >> fw, '''
+ print('''
};
// Needed since sizeof is a macro and we cannot be used until size is known
@@ -142,7 +142,7 @@ int OperatorDictionary::size()
}
KFORMULA_NAMESPACE_END
- '''
+ ''', file=fw)
def get_entities():
# First, read entity list into a dict
@@ -165,7 +165,7 @@ def key_cmp( a, b ):
return -1
if a[1] > b[1]:
return 1
- print 'WARNING: Same key in operator dictionary: ' + a[0] + ', ' + b[0]
+ print('WARNING: Same key in operator dictionary: ' + a[0] + ', ' + b[0])
return 0
def parse( fr, fw, entities ):
@@ -203,8 +203,8 @@ def parse( fr, fw, entities ):
# application. The best solution would probably to map to a single
# character provided by the font in the private area of Unicode
entity_name = name[begin + 1:end]
- if entities.has_key( entity_name ) :
- name = name.replace( '&' + entity_name + ';', unichr(entities[entity_name]));
+ if entity_name in entities :
+ name = name.replace( '&' + entity_name + ';', chr(entities[entity_name]));
else:
entities_found = False
break
@@ -213,9 +213,9 @@ def parse( fr, fw, entities ):
fields.pop(0) # Remove form
for f in fields:
attr, value = string.split( f, '=' )
- if not attr_dict.has_key( attr ) :
- print 'Unsupported attribute: ' + attr
- print 'If it is valid, update attribute dictionary'
+ if attr not in attr_dict :
+ print('Unsupported attribute: ' + attr)
+ print('If it is valid, update attribute dictionary')
sys.exit(-1)
# Spec has a typo, fix it
if string.count( value, '"' ) == 3:
@@ -227,20 +227,20 @@ def parse( fr, fw, entities ):
while True:
e = entries.pop()
- print >> fw, ' { {' + e[0] + ', ' + e[1] + '},'
+ print(' { {' + e[0] + ', ' + e[1] + '},', file=fw)
d = e[2]
for a in attr_list:
# Convert, at least, bool values
value = d[a]
if value == '"true"' or value == '"false"':
value = string.strip( value, '"' )
- print >> fw, '\t\t' + value,
+ print('\t\t' + value, end=' ', file=fw)
if a != attr_list[len(attr_list) - 1]:
- print >> fw, ','
- print >> fw, '}',
+ print(',', file=fw)
+ print('}', end=' ', file=fw)
if len( entries ) == 0:
break
- print >> fw, ',\n'
+ print(',\n', file=fw)
if __name__ == '__main__':
fh = open( '../operatordictionary.h', 'w' )