Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions iocp.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@
import ConfigParser

# Import optional third-party libraries
IMPORTS = []
try:
from PyPDF2 import PdfFileReader
IMPORTS.append('pypdf2')
except ImportError:
pass
try:
Expand All @@ -59,17 +57,14 @@
from pdfminer.converter import TextConverter
from pdfminer.pdfinterp import PDFPageInterpreter
from pdfminer.layout import LAParams
IMPORTS.append('pdfminer')
except ImportError:
pass
try:
from bs4 import BeautifulSoup
IMPORTS.append('beautifulsoup')
except ImportError:
pass
try:
import requests
IMPORTS.append('requests')
except ImportError:
pass

Expand Down Expand Up @@ -104,11 +99,11 @@ def __init__(self, patterns_ini=None, input_format='pdf', dedup=False, library='

self.library = library
if input_format == 'pdf':
if library not in IMPORTS:
if library not in sys.modules:
e = 'Selected PDF parser library not found: %s' % (library)
raise ImportError(e)
elif input_format == 'html':
if 'beautifulsoup' not in IMPORTS:
if 'beautifulsoup' not in sys.modules:
e = 'HTML parser library not found: BeautifulSoup'
raise ImportError(e)

Expand Down Expand Up @@ -269,7 +264,7 @@ def parse_html(self, f, fpath):
def parse(self, path):
try:
if path.startswith('http://') or path.startswith('https://'):
if 'requests' not in IMPORTS:
if 'requests' not in sys.modules:
e = 'HTTP library not found: requests'
raise ImportError(e)
headers = { 'User-Agent': 'Mozilla/5.0 Gecko Firefox' }
Expand Down
2 changes: 1 addition & 1 deletion output.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def print_error(self, fpath, exception):

class OutputHandler_csv(OutputHandler):
def __init__(self):
self.csv_writer = csv.writer(sys.stdout, delimiter = '\t')
self.csv_writer = csv.writer(sys.stdout, delimiter = '\t', quoting=csv.QUOTE_NONNUMERIC)

def print_match(self, fpath, page, name, match):
self.csv_writer.writerow((fpath, page, name, match))
Expand Down