Skip to content

Commit

Permalink
Ensure that pypdfOrd() always returns an int object
Browse files Browse the repository at this point in the history
Fixes py-pdf#40
  • Loading branch information
kurtmckee committed May 7, 2019
1 parent 47bc9fd commit 6177c44
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions pypdf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,22 +292,12 @@ def pypdfStr(b):

def pypdfOrd(b):
"""
Abstracts the conversion from a single-character string to the
corresponding integer value over versions 2.7.x and 3 of Python.
:type b: Union[int, bytes, str, unicode]
:rtype: int
"""
# In case of bugs, try to look here! Should the condition be brought like
# it used to be in the comment below?
# if sys.version_info[0] < 3 or type(b) == str:
# (``str is bytes == True`` in Python 2)
if isinstance(b, str):
return ord(b)
elif sys.version_info < (3, 0) and isinstance(b, unicode):
return ord(b)
# TO-DO The code below should be changed (b could be ANYTHING!) but I have
# no idea of what (and how much) previous code could be depending on this
# behavior
else:
if isinstance(b, int):
return b
return ord(b)


def pypdfChr(c):
Expand Down

0 comments on commit 6177c44

Please sign in to comment.