X-Git-Url: https://git.mdrn.pl/texml.git/blobdiff_plain/f06bfe769b002b2335a03c7a6c871f2263bef6f6..1f6090d7691f530df0faef700944f3b33c8b9f10:/Texml/texmlwr.py?ds=sidebyside diff --git a/Texml/texmlwr.py b/Texml/texmlwr.py index 631517a..0cfa8cc 100644 --- a/Texml/texmlwr.py +++ b/Texml/texmlwr.py @@ -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