Python 3.4+ compatibility (while dropping Python < 2.6).
authorRadek Czajka <rczajka@rczajka.pl>
Mon, 26 Mar 2018 08:02:45 +0000 (10:02 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Mon, 26 Mar 2018 08:02:45 +0000 (10:02 +0200)
.gitignore [new file with mode: 0644]
Texml/handler.py
Texml/processor.py
Texml/texmlwr.py
scripts/texml.py
setup.py
tox.ini [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..d94120e
--- /dev/null
@@ -0,0 +1,4 @@
+*.pyc
+/.tox
+/tests/tmp
+MANIFEST
index 32a6118..f6b3031 100644 (file)
@@ -4,11 +4,9 @@
 import xml.sax.handler
 from xml.sax.handler import feature_namespaces
 
-import texmlwr
-import specmap
-import StringIO
+from Texml import texmlwr
+from Texml import specmap
 import string
-import os, sys
 
 # Unbreakable spaces should not be deleted by strip(), but it happens:
 # http://uucode.com/blog/2010/06/01/python-wtf-strip-eats-too-much/
@@ -256,11 +254,11 @@ class Handler:
       else:
         msg += '%s not expected' % (local_name)
 
-      raise InvalidXmlException, msg
+      raise InvalidXmlException(msg)
 
   def invalid_xml_other(self, msg):
       # for other types of invalid XML
-      raise InvalidXmlException, msg
+      raise InvalidXmlException(msg)
 
   # -------------------------------------------------------------------
   
index 4f746d5..ac9415c 100644 (file)
@@ -93,7 +93,7 @@ try:
       encoding     = encoding,
       always_ascii = always_ascii,
       use_context  = use_context)
-except Exception, msg:
+except Exception as msg:
   print sys.stderr, 'texml: %s' % str(msg)
 
 # Clean up resources
index 631517a..0cfa8cc 100644 (file)
@@ -11,13 +11,18 @@ ASIS    = 3
 PDF     = 4
 WEAK_WS_IS_NEWLINE = 2
 
-import unimap
-import specmap
+from Texml import unimap
+from Texml import specmap
 import codecs
 import os
 import sys
 import string
 
+if sys.version_info[0] >= 3:
+    byteord = lambda c: c
+else:
+    byteord = ord
+
 #
 # Writer&Co class
 #
@@ -69,7 +74,7 @@ class texmlwr:
       if always_ascii:
         encoding        = 'ascii'
       self.stream     = stream_encoder(stream, encoding)
-    except Exception, e:
+    except Exception as e:
       raise ValueError("Can't create encoder: '%s'" % e)
     # Continue initialization
     self.after_char0d     = 1
@@ -274,9 +279,9 @@ class texmlwr:
       try:
         bytes = ch.encode(self.encoding)
         for by in bytes:
-          self.write('^^%02x' % ord(by), 0)
+          self.write('^^%02x' % byteord(by), 0)
         return
-      except Exception, e:
+      except Exception as e:
         pass
     #
     # Symbol have to be rewritten. Let start with math mode.
@@ -336,7 +341,7 @@ class texmlwr:
     """ Write char in Acrobat utf16be encoding """
     bytes = ch.encode('utf_16_be')
     for by in bytes:
-      self.write('\\%03o' % ord(by), 0)
+      self.write('\\%03o' % byteord(by), 0)
       
 #
 # Wrapper over output stream to write is desired encoding
index 40dd6b6..6822dd8 100755 (executable)
@@ -24,7 +24,7 @@ use_namespace = 1
 import getopt
 try:
   opts, args = getopt.getopt(sys.argv[1:], 'hcaw:e:', ['help', 'context', 'ascii', 'width=', 'encoding=', ])
-except getopt.GetoptError, e:
+except getopt.GetoptError as e:
   print >>sys.stderr, 'texml: Can\'t parse command line: %s' % e
   print >>sys.stderr, usage
   sys.exit(2)
@@ -71,7 +71,7 @@ if '-' == infile:
 if '-' == outfile:
   f = sys.stdout
 else:
-  f = file(outfile, 'wb')
+  f = open(outfile, 'wb')
 
 #
 # An error handler
@@ -88,7 +88,7 @@ import Texml.processor
 try:
   Texml.processor.process(infile, f, encoding, width, always_ascii, use_context)
     
-except Exception, msg:
+except Exception as msg:
   msg = 'texml: %s\n' % (str(msg))
   quit(msg)
 
index a5eeacf..2a17358 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -4,22 +4,6 @@ import os.path
 import re
 import glob
 
-def test_for_sax():
-    try:
-        import xml.sax
-    except ImportError:
-        sys.stderr.write('Please install the python pyxml modules\n')
-        sys.stdout.write('You must have this module before you can install texml\n')
-        sys.exit(1)
-
-def get_dtd_location():
-    """
-    For now, this is not used
-
-    """
-    return
-    return '/home/paul/Documents/data/dtds/'
-
 
 def get_version():
     # Take the version from "scripts/texml.py"
@@ -36,8 +20,6 @@ def get_version():
       raise "Can't find version"
     return version
 
-if 'build' in sys.argv:
-    test_for_sax()
 
 version = get_version()
 
diff --git a/tox.ini b/tox.ini
new file mode 100644 (file)
index 0000000..306a88d
--- /dev/null
+++ b/tox.ini
@@ -0,0 +1,10 @@
+[tox]
+envlist =
+    py{26,27,34,35,36,37},
+
+[testenv]
+changedir = tests
+commands = 
+       make clean
+       make
+whitelist_externals=make