Update PyRTF to Python 3

This commit is contained in:
Fran Boon
2020-02-12 09:54:21 +00:00
parent ec40c1b5a9
commit e89d2bc7fa
6 changed files with 45 additions and 20 deletions

View File

@@ -1,3 +1,7 @@
import sys
PY2 = sys.version_info[0] == 2
class ViewKind :
"""An integer (0-5) that represents the view mode of the document."""

View File

@@ -1,10 +1,16 @@
from __future__ import print_function
from types import IntType, FloatType, LongType, StringTypes
from copy import deepcopy
from binascii import hexlify
from copy import deepcopy
from binascii import hexlify
from Constants import *
from Styles import *
from .Constants import *
from .Styles import *
if PY2:
NumberTypes = (int, float, long)
StringType = basestring
else:
NumberTypes = (int, float)
StringType = str
class UnhandledParamError( Exception ) :
def __init__( self, param ) :
@@ -587,7 +593,7 @@ class Table :
def AddRow( self, *cells ) :
height = None
if isinstance( cells[ 0 ], (IntType, FloatType, LongType) ):
if isinstance( cells[ 0 ], NumberTypes ):
height = int( cells[ 0 ] )
cells = cells[ 1 : ]

View File

@@ -9,9 +9,14 @@ The TextPropertySet can be used for text or in a Paragraph Style.
"""
from types import StringType
from copy import deepcopy
from copy import deepcopy
from .Constants import PY2
if PY2:
StringType = basestring
else:
StringType = str
#
# We need some basic Type like fonts, colours and paper definitions

View File

@@ -1,6 +1,11 @@
from types import StringType, ListType, TupleType
from copy import deepcopy
from Elements import *
from .Elements import *
from .Constants import PY2
if PY2:
StringType = basestring
else:
StringType = str
DEFAULT_TAB_WIDTH = 720
@@ -438,7 +443,7 @@ class Renderer :
elif clss == Table :
self.WriteTableElement( element )
elif clss == StringType :
elif ininstance(element, StringType) :
self.WriteParagraphElement( Paragraph( element ) )
elif clss in [ RawCode, Image ] :

View File

@@ -6,7 +6,7 @@ At present there are only two, Text and Paragraph but ListStyles will be added s
"""
from PropertySets import *
from .PropertySets import *
class TextStyle :
def __init__( self, text_props, name=None, shading_props=None ) :

View File

@@ -1,12 +1,17 @@
from PropertySets import *
from Elements import *
from Styles import *
from Renderer import *
from .PropertySets import *
from .Elements import *
from .Styles import *
from .Renderer import *
from .Constants import PY2
if PY2:
from cStringIO import StringIO as BytesIO
else:
from io import BytesIO
def dumps(doc):
import cStringIO
s=cStringIO.StringIO()
r=Renderer()
r.Write(doc,s)
s = BytesIO()
r = Renderer()
r.Write(doc, s)
return s.getvalue()