Refactor "is this an iterable that's not a string?" test

This commit is contained in:
James R. Barlow
2016-07-29 15:25:02 -07:00
parent d257c83520
commit f385772d21
2 changed files with 8 additions and 3 deletions
+5
View File
@@ -1,5 +1,6 @@
from enum import IntEnum
import os
from collections.abc import Iterable
class ExitCode(IntEnum):
@@ -22,3 +23,7 @@ def get_program(name):
def page_number(input_file):
return int(os.path.basename(input_file)[0:6])
def is_iterable_notstr(thing):
return isinstance(thing, Iterable) and not isinstance(thing, str)
+3 -3
View File
@@ -31,7 +31,7 @@ from .pdfa import generate_pdfa_def
from . import ghostscript
from . import tesseract
from . import qpdf
from . import ExitCode, page_number
from . import ExitCode, page_number, is_iterable_notstr
import pkg_resources
@@ -552,7 +552,7 @@ def split_pages(
pdfinfo,
pdfinfo_lock):
if isinstance(input_files, list):
if is_iterable_notstr(input_files):
input_file = input_files[0]
else:
input_file = input_files
@@ -1210,7 +1210,7 @@ def traverse_ruffus_exception(e):
if isinstance(e[0], str) and len(e) == 5:
return do_ruffus_exception(e)
elif hasattr(e, '__iter__') and not isinstance(e, str):
elif is_iterable_notstr(e):
for exc in e:
return traverse_ruffus_exception(exc)