mirror of
https://github.com/getpelican/pelican.git
synced 2026-05-27 18:36:13 +02:00
Testing whether a reader class is enabled *before* calling it, otherwise the test is never reached.
For example, if Markdown hasn't been installed, and you attempt read_file('foo.md') then an exception is raised in MarkdownReader.__init__ as it tries to call Markdown, which is False. The class field "enabled" was not checked before attempting to instantiate MarkdownReader. Instead, there is a later test on the instance, which won't be reached.
This commit is contained in:
parent
675d6c81cd
commit
150478625b
1 changed files with 5 additions and 4 deletions
|
|
@ -347,15 +347,16 @@ def read_file(path, fmt=None, settings=None):
|
|||
if settings is None:
|
||||
settings = {}
|
||||
|
||||
reader = EXTENSIONS[fmt](settings)
|
||||
cls = EXTENSIONS[fmt]
|
||||
if not cls.enabled:
|
||||
raise ValueError("Missing dependencies for %s" % fmt)
|
||||
|
||||
reader = cls(settings)
|
||||
settings_key = '%s_EXTENSIONS' % fmt.upper()
|
||||
|
||||
if settings and settings_key in settings:
|
||||
reader.extensions = settings[settings_key]
|
||||
|
||||
if not reader.enabled:
|
||||
raise ValueError("Missing dependencies for %s" % fmt)
|
||||
|
||||
metadata = parse_path_metadata(
|
||||
path=path, settings=settings, process=reader.process_metadata)
|
||||
content, reader_metadata = reader.read(path)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue