claird / PyPDF4

A utility to read and write PDFs with Python
obsolete-https://pythonhosted.org/PyPDF2/
Other
328 stars 61 forks source link

ASCIIHexCodec decoder not compatible with bytes object #83

Open dcmvdbekerom opened 4 years ago

dcmvdbekerom commented 4 years ago

An exception is thrown when decoding objects with a ASCIIHEXCodec:

    fdata = fobj.getData()
  File "c:\users\dcmvd\documents\github\pypdf4\pypdf\generic.py", line 950, in getData
    decoded._data = decodeStreamData(self)
  File "c:\users\dcmvd\documents\github\pypdf4\pypdf\filters.py", line 757, in decodeStreamData
    data = ASCIIHexCodec.decode(data)
  File "c:\users\dcmvd\documents\github\pypdf4\pypdf\filters.py", line 249, in decode
    elif c.isspace():
AttributeError: 'int' object has no attribute 'isspace'

This is likely legacy Py2 code that was not updated to Py3. The problem can be solved easily by converting data to string in the beginning of the method:

 try:
       data = data.decode()
 except(AttributeError):
       pass

And converting the return value to str/byte depending on which python version is running at the end of the method:

retval = b_(retval)