From 300abf9a97364b856b84393e1267e701767a6b05 Mon Sep 17 00:00:00 2001 From: egbutter Date: Wed, 12 Mar 2014 17:09:28 -0400 Subject: [PATCH] fixes #79. PdfFileReader barfs when it gets a unicode _namedDest; moving Str basestring indirection from pagerange to utils, importing into both pdf and pagerange --- PyPDF2/pagerange.py | 5 +---- PyPDF2/pdf.py | 4 ++-- PyPDF2/utils.py | 8 ++++++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/PyPDF2/pagerange.py b/PyPDF2/pagerange.py index 143de83eb..2b628cdee 100644 --- a/PyPDF2/pagerange.py +++ b/PyPDF2/pagerange.py @@ -8,10 +8,7 @@ """ import re - -# "Str" maintains compatibility with Python 2.x. -# The next line is obfuscated like this so 2to3 won't change it. -Str = getattr(__builtins__, "basestring", str) +from .utils import Str _INT_RE = r"(0|-?[1-9]\d*)" # A decimal int, don't allow "-0". PAGE_RANGE_RE = "^({int}|({int}?(:{int}?(:{int}?)?)))$".format(int=_INT_RE) diff --git a/PyPDF2/pdf.py b/PyPDF2/pdf.py index bae15af47..f8e9ba9c3 100644 --- a/PyPDF2/pdf.py +++ b/PyPDF2/pdf.py @@ -61,7 +61,7 @@ import codecs from .generic import * from .utils import readNonWhitespace, readUntilWhitespace, ConvertFunctionsToVirtualList -from .utils import b_, u_, ord_, chr_, str_, string_type, formatWarning +from .utils import Str, b_, u_, ord_, chr_, str_, string_type, formatWarning if version_info < ( 2, 4 ): from sets import ImmutableSet as frozenset @@ -1004,7 +1004,7 @@ def _buildOutline(self, node): if dest: if isinstance(dest, ArrayObject): outline = self._buildDestination(title, dest) - elif isinstance(dest, str) and dest in self._namedDests: + elif isinstance(dest, Str) and dest in self._namedDests: outline = self._namedDests[dest] outline[NameObject("/Title")] = title else: diff --git a/PyPDF2/utils.py b/PyPDF2/utils.py index 47e9eb127..3e1b88571 100644 --- a/PyPDF2/utils.py +++ b/PyPDF2/utils.py @@ -1,5 +1,3 @@ -# vim: sw=4:expandtab:foldmethod=marker -# # Copyright (c) 2006, Mathieu Fenniak # All rights reserved. # @@ -33,6 +31,12 @@ __author__ = "Mathieu Fenniak" __author_email__ = "biziqe@mathieu.fenniak.net" + +# "Str" maintains compatibility with Python 2.x. +# The next line is obfuscated like this so 2to3 won't change it. +Str = getattr(__builtins__, "basestring", str) + + #custom implementation of warnings.formatwarning def formatWarning(message, category, filename, lineno, line=None): file = filename.replace("/", "\\").rsplit("\\", 1)[1] # find the file name