]> git.lyx.org Git - features.git/commitdiff
Some python 3 fixes for lyx2lyx
authorGeorg Baum <baum@lyx.org>
Sat, 11 Jun 2016 09:06:11 +0000 (11:06 +0200)
committerGeorg Baum <baum@lyx.org>
Sat, 11 Jun 2016 09:06:11 +0000 (11:06 +0200)
These were found by 2to3 and later adapted to use the compatibility code
which was already used in some parts of lyx2lyx, e.g. lyx_1_5.py.

lib/lyx2lyx/lyx_1_6.py
lib/lyx2lyx/lyx_2_2.py
lib/lyx2lyx/test_parser_tools.py

index 2f8ebd24b8a6ae9664902d786a0e2eda3a3e8432..f431d5fec162dc38bfe086e68e458e444b1ccccd 100644 (file)
@@ -24,6 +24,16 @@ import sys, os
 
 from parser_tools import find_token, find_end_of, find_tokens, get_value
 
+# Provide support for both python 2 and 3
+PY2 = sys.version_info[0] == 2
+if not PY2:
+    text_type = str
+    unichr = chr
+else:
+    text_type = unicode
+    unichr = unichr
+# End of code to support for both python 2 and 3
+
 ####################################################################
 # Private helper functions
 
index 942aa6a094b10de29988e2ac2417a37bed44dbde..073f815cbb028715267bfcc6d0e4ff93f11b754c 100644 (file)
@@ -39,6 +39,16 @@ from parser_tools import find_token, find_token_backwards, find_re, \
      find_end_of_inset, find_end_of_layout, find_nonempty_line, \
      get_containing_layout, get_value, check_token
 
+# Provide support for both python 2 and 3
+PY2 = sys.version_info[0] == 2
+if not PY2:
+    text_type = str
+    unichr = chr
+else:
+    text_type = unicode
+    unichr = unichr
+# End of code to support for both python 2 and 3
+
 ####################################################################
 # Private helper functions
 
@@ -796,7 +806,7 @@ def convert_specialchar_internal(document, forward):
             else:
                 i = j
             continue
-        for key, value in specialchars.iteritems():
+        for key, value in specialchars.items():
             if forward:
                 document.body[i] = document.body[i].replace("\\SpecialChar " + key, "\\SpecialChar " + value)
                 document.body[i] = document.body[i].replace("\\SpecialCharNoPassThru " + key, "\\SpecialCharNoPassThru " + value)
@@ -1155,7 +1165,7 @@ def convert_origin(document):
         else:
             origin = os.path.join("/systemlyxdir", relpath).replace('\\', '/') + '/'
         if os.name != 'nt':
-            origin = unicode(origin, sys.getfilesystemencoding())
+            origin = text_type(origin, sys.getfilesystemencoding())
     document.header[i:i] = ["\\origin " + origin]
 
 
index 7e34947c70c9740253842359463bc9064e8e9109..4af3225263c8af4d4afc92c200b93abbeed846a4 100644 (file)
@@ -65,28 +65,28 @@ class TestParserTools(unittest.TestCase):
     def test_check_token(self):
         line = "\\begin_layout Standard"
 
-        self.assertEquals(check_token(line, '\\begin_layout'), True)
-        self.assertEquals(check_token(line, 'Standard'), False)
+        self.assertEqual(check_token(line, '\\begin_layout'), True)
+        self.assertEqual(check_token(line, 'Standard'), False)
 
 
     def test_is_nonempty_line(self):
-        self.assertEquals(is_nonempty_line(lines[0]), False)
-        self.assertEquals(is_nonempty_line(lines[1]), True)
-        self.assertEquals(is_nonempty_line(" "*5), False)
+        self.assertEqual(is_nonempty_line(lines[0]), False)
+        self.assertEqual(is_nonempty_line(lines[1]), True)
+        self.assertEqual(is_nonempty_line(" "*5), False)
 
 
     def test_find_token(self):
-        self.assertEquals(find_token(lines, '\\emph', 0), 7)
-        self.assertEquals(find_token(lines, '\\emph', 0, 5), -1)
-        self.assertEquals(find_token(lines, '\\emp', 0, 0, True), -1)
-        self.assertEquals(find_token(lines, '\\emp', 0, 0, False), 7)
-        self.assertEquals(find_token(lines, 'emph', 0), -1)
+        self.assertEqual(find_token(lines, '\\emph', 0), 7)
+        self.assertEqual(find_token(lines, '\\emph', 0, 5), -1)
+        self.assertEqual(find_token(lines, '\\emp', 0, 0, True), -1)
+        self.assertEqual(find_token(lines, '\\emp', 0, 0, False), 7)
+        self.assertEqual(find_token(lines, 'emph', 0), -1)
 
 
     def test_find_tokens(self):
         tokens = ['\\emph', '\\end_inset']
-        self.assertEquals(find_tokens(lines, tokens, 0), 4)
-        self.assertEquals(find_tokens(lines, tokens, 0, 4), -1)
+        self.assertEqual(find_tokens(lines, tokens, 0), 4)
+        self.assertEqual(find_tokens(lines, tokens, 0, 4), -1)
 
 
 if __name__ == '__main__':