Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #81 from sdpython/master
fix an issue with the constuctor of NumberObject
  • Loading branch information
mstamy2 committed Mar 17, 2014
2 parents 7bec1b2 + b1fa236 commit 5dbadaa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
7 changes: 4 additions & 3 deletions PyPDF2/generic.py
Expand Up @@ -236,9 +236,10 @@ def writeToStream(self, stream, encryption_key):


class NumberObject(int, PdfObject):
def __init__(self, value):
int.__init__(self, value)


def __new__(cls, value):
return int.__new__(cls, value)

def as_numeric(self):
return int(b_(repr(self)))

Expand Down
14 changes: 8 additions & 6 deletions PyPDF2/merger.py
Expand Up @@ -34,9 +34,11 @@
from sys import version_info
if version_info < ( 3, 0 ):
from cStringIO import StringIO
StreamIO = StringIO
else:
from io import StringIO
from io import BytesIO
from io import FileIO as file
StreamIO = BytesIO

class _MergedPage(object):
"""
Expand Down Expand Up @@ -95,28 +97,28 @@ def merge(self, position, fileobj, bookmark=None, pages=None, import_bookmarks=T

# If the fileobj parameter is a string, assume it is a path
# and create a file object at that location. If it is a file,
# copy the file's contents into a StringIO stream object; if
# copy the file's contents into a BytesIO (or StreamIO) stream object; if
# it is a PdfFileReader, copy that reader's stream into a
# StringIO stream.
# BytesIO (or StreamIO) stream.
# If fileobj is none of the above types, it is not modified
if type(fileobj) == string_type:
fileobj = file(fileobj, 'rb')
my_file = True
elif isinstance(fileobj, file):
fileobj.seek(0)
filecontent = fileobj.read()
fileobj = StringIO(filecontent)
fileobj = StreamIO(filecontent)
my_file = True
elif isinstance(fileobj, PdfFileReader):
orig_tell = fileobj.stream.tell()
fileobj.stream.seek(0)
filecontent = StringIO(fileobj.stream.read())
filecontent = StreamIO(fileobj.stream.read())
fileobj.stream.seek(orig_tell) # reset the stream to its original location
fileobj = filecontent
my_file = True

# Create a new PdfFileReader instance using the stream
# (either file or StringIO) created above
# (either file or BytesIO or StringIO) created above
pdfr = PdfFileReader(fileobj, strict=self.strict)

# Find the range of pages to merge.
Expand Down

0 comments on commit 5dbadaa

Please sign in to comment.