Fixed some bugs preventing all tests from passing in Py2.

pull/5/head
Cathal Garvey 2015-05-30 18:02:29 +01:00
parent 79c97ac221
commit a2ad7a6d03
5 changed files with 17 additions and 4 deletions

View File

@ -1,4 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__version__ = '20140915'
if __name__ == '__main__':

View File

@ -1,4 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
import re
from .pdfdevice import PDFTextDevice

View File

@ -1,4 +1,5 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Functions that encapsulate "usual" use-cases for pdfminer, for use making
bundled scripts and for using pdfminer as a module for routine tasks.

View File

@ -10,6 +10,9 @@ INF = (1<<31) - 1
import six #Python 2+3 compatibility
import chardet # For str encoding detection in Py3
if six.PY3:
unicode = str
def make_compat_bytes(in_str):
"In Py2, does nothing. In Py3, converts to bytes, encoding to unicode."
assert isinstance(in_str, str)
@ -20,7 +23,7 @@ def make_compat_bytes(in_str):
def make_compat_str(in_str):
"In Py2, does nothing. In Py3, converts to string, guessing encoding."
assert isinstance(in_str, (bytes, str))
assert isinstance(in_str, (bytes, str, unicode))
if six.PY3 and isinstance(in_str, bytes):
enc = chardet.detect(in_str)
in_str = in_str.decode(enc['encoding'])
@ -29,7 +32,7 @@ def make_compat_str(in_str):
def compatible_encode_method(bytesorstring, encoding='utf-8', erraction='ignore'):
"When Py2 str.encode is called, it often means bytes.encode in Py3. This does either."
if six.PY2:
assert isinstance(bytesorstring, str), ("Error: Assumed was calling"
assert isinstance(bytesorstring, (str, unicode)), ("Error: Assumed was calling"
" encode() on a string in Py2: {}").format(type(bytesorstring))
return bytesorstring.encode(encoding, erraction)
if six.PY3:

View File

@ -1,9 +1,16 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
import six
import nose, logging, os
import tools.dumppdf as dumppdf
if six.PY3:
from tools import dumppdf
elif six.PY2:
import os, sys
# raise Exception("{}\n{}".format(sys.path, os.path.abspath(os.path.curdir)))
sys.path.append(os.path.abspath(os.path.curdir))
import tools.dumppdf as dumppdf
path=os.path.dirname(os.path.abspath(__file__))+'/'