Skip to content

Commit

Permalink
Fix review issues
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelsousa committed May 16, 2018
1 parent 7920ede commit e36ff76
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 30 deletions.
19 changes: 2 additions & 17 deletions afdko/Tools/SharedData/FDKScripts/pdfdoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,9 @@
from __future__ import print_function, absolute_import

import os
import sys
import string
import sys
import time
import tempfile
import cStringIO
from types import *
from math import sin, cos, pi, ceil

from . import pdfutils
from .pdfutils import LINEEND # this constant needed in both
Expand Down Expand Up @@ -193,17 +189,6 @@ def SaveToFileObject(self, fileobj):
self.writeTrailer(f)
f.write('%%EOF') # no lineend needed on this one!

# with the Mac, we need to tag the file in a special
#way so the system knows it is a PDF file.
#This supplied by Joe Strout
if os.name == 'mac':
import macfs
try:
macfs.FSSpec(filename).SetCreatorType('CARO','PDF ')
except:
pass


def printPDF(self):
"prints it to standard output. Logs positions for doing trailer"
print("%PDF-1.0")
Expand Down Expand Up @@ -552,7 +537,7 @@ def clear(self):
self.drawables = []

def setStream(self, data):
if type(data) is ListType:
if isinstance(data, list):
data = string.join(data, LINEEND)
self.stream.setStream(data)

Expand Down
20 changes: 7 additions & 13 deletions afdko/Tools/SharedData/FDKScripts/pdfgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@
import time
import tempfile
import cStringIO
from types import *
from math import sin, cos, tan, pi, ceil
from math import sin, cos, tan, pi

from . import pdfdoc
from . import pdfgeom
Expand Down Expand Up @@ -529,9 +528,9 @@ def setMiterLimit(self, limit):

def setDash(self, array=[], phase=0):
"""Two notations. pass two numbers, or an array and phase"""
if type(array) == IntType or type(array) == FloatType:
if isinstance(array, int) or isinstance(array, float):
self._code.append('[%s %s] 0 d' % (array, phase))
elif type(array) == ListType or type(Array) == TupleType:
elif isinstance(array, list) or isinstance(array, tuple):
assert phase <= len(array), "setDash phase must be l.t.e. length of array"
textarray = string.join(map(str, array))
self._code.append('[%s] %s d' % (textarray, phase))
Expand Down Expand Up @@ -578,11 +577,6 @@ def drawInlineImage(self, image, x,y, width=None,height=None):
Also allow file names as well as images. This allows a
caching mechanism"""
# print "drawInlineImage: x=%s, y=%s, width = %s, height=%s " % (x,y, width, height)
try:
import Image
except ImportError:
print('Python Imaging Library not available')
return
try:
import zlib
except ImportError:
Expand All @@ -591,7 +585,7 @@ def drawInlineImage(self, image, x,y, width=None,height=None):

self._currentPageHasImages = 1

if type(image) == StringType:
if isinstance(image, str):
if os.path.splitext(image)[1] in ['.jpg', '.JPG']:
#directly process JPEG files
#open file, needs some error handling!!
Expand Down Expand Up @@ -1043,13 +1037,13 @@ def textLines(self, stuff, trim=1):
since this may be indented, by default it trims whitespace
off each line and from the beginning; set trim=0 to preserve
whitespace."""
if type(stuff) == StringType:
if isinstance(stuff, str):
lines = string.split(string.strip(stuff), '\n')
if trim==1:
lines = map(string.strip,lines)
elif type(stuff) == ListType:
elif isinstance(stuff, list):
lines = stuff
elif type(stuff) == TupleType:
elif isinstance(stuff, tuple):
lines = stuff
else:
assert 1==0, "argument to textlines must be string,, list or tuple"
Expand Down

0 comments on commit e36ff76

Please sign in to comment.