Skip to content

Commit

Permalink
fixes py-pdf#79. PdfFileReader barfs when it gets a unicode _namedDes…
Browse files Browse the repository at this point in the history
…t; moving Str basestring indirection from pagerange to utils, importing into both pdf and pagerange
  • Loading branch information
egbutter committed Mar 12, 2014
1 parent 7bec1b2 commit 300abf9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
5 changes: 1 addition & 4 deletions PyPDF2/pagerange.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions PyPDF2/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 6 additions & 2 deletions PyPDF2/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# vim: sw=4:expandtab:foldmethod=marker
#
# Copyright (c) 2006, Mathieu Fenniak
# All rights reserved.
#
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 300abf9

Please sign in to comment.