delay initialization of PathFormat objects

This allows the DeviantArt group-check to be moved inside the
Extractor.items() method which in turn allows for better exception
handling.

As a new general rule:
Never raise exceptions during extractor initialization.
This commit is contained in:
Mike Fährmann
2017-12-29 22:15:57 +01:00
parent c24e0e70a7
commit 88bb0798fd
2 changed files with 12 additions and 11 deletions

View File

@@ -29,21 +29,19 @@ class DeviantartExtractor(Extractor):
self.offset = 0 self.offset = 0
self.flat = self.config("flat", True) self.flat = self.config("flat", True)
self.original = self.config("original", True) self.original = self.config("original", True)
self.user = match.group(1) if match else None
if match: self.group = False
self.user = match.group(1)
self.group = not self.api.user_profile(self.user)
if self.group:
self.subcategory = "group-" + self.subcategory
else:
self.user = None
self.group = False
def skip(self, num): def skip(self, num):
self.offset += num self.offset += num
return num return num
def items(self): def items(self):
if self.user:
self.group = not self.api.user_profile(self.user)
if self.group:
self.subcategory = "group-" + self.subcategory
yield Message.Version, 1 yield Message.Version, 1
for deviation in self.deviations(): for deviation in self.deviations():
if isinstance(deviation, tuple): if isinstance(deviation, tuple):

View File

@@ -137,8 +137,8 @@ class DownloadJob(Job):
def __init__(self, url, parent=None): def __init__(self, url, parent=None):
Job.__init__(self, url, parent) Job.__init__(self, url, parent)
self.pathfmt = util.PathFormat(self.extractor) self.pathfmt = None
self.sleep = self.extractor.config("sleep") self.sleep = None
self.downloaders = {} self.downloaders = {}
self.out = output.select() self.out = output.select()
@@ -155,6 +155,9 @@ class DownloadJob(Job):
def handle_directory(self, keywords): def handle_directory(self, keywords):
"""Set and create the target directory for downloads""" """Set and create the target directory for downloads"""
if not self.pathfmt:
self.pathfmt = util.PathFormat(self.extractor)
self.sleep = self.extractor.config("sleep")
self.pathfmt.set_directory(keywords) self.pathfmt.set_directory(keywords)
def handle_queue(self, url, keywords): def handle_queue(self, url, keywords):