Refactor "is this an iterable that's not a string?" test
This commit is contained in:
@@ -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
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user