From 1279e418ee523eebd068646606cb40cbad5f8d40 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Tue, 8 Dec 2015 16:46:18 +0100 Subject: [PATCH] pdfjs: Replace inline-removal with own function Easier to unit-test and easier to understand for other programmers. --- qutebrowser/browser/pdfjs.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/qutebrowser/browser/pdfjs.py b/qutebrowser/browser/pdfjs.py index 792f07928..0df44d70b 100644 --- a/qutebrowser/browser/pdfjs.py +++ b/qutebrowser/browser/pdfjs.py @@ -107,7 +107,7 @@ def get_pdfjs_res(path): # First try a system wide installation # System installations might strip off the 'build/' or 'web/' prefixes. # qute expects them, so we need to adjust for it. - names_to_try = [path, path[path.index('/') + 1:]] + names_to_try = [path, _remove_prefix(path)] for system_path in SYSTEM_PDFJS_PATHS: content = _read_from_system(system_path, names_to_try) if content is not None: @@ -130,6 +130,19 @@ def get_pdfjs_res(path): return text_content.encode('utf-8') +def _remove_prefix(path): + """Remove the web/ or build/ prefix of a pdfjs-file-path. + + Args: + path: Path as string where the prefix should be stripped off. + """ + prefixes = {'web/', 'build/'} + if any(path.startswith(prefix) for prefix in prefixes): + return path.split('/', maxsplit=1)[1] + # Return the unchanged path if no prefix is found + return path + + def _read_from_system(system_path, names): """Try to read a file with one of the given names in system_path.