Fix already marked articles was reshown bug
Since we search for matching states for articles to include or exclude in a loop, we could not control the outer loop via default break/ continue. Python docs recommend using Exceptions and try/except structures to realise that most conveniently. https://docs.python.org/3/faq/design.html#why-is-there-no-goto Related Task: [FS#138](https://fs.golderweb.de/index.php?do=details&task_id=138)
This commit is contained in:
@@ -515,45 +515,66 @@ class RedFamWorker( RedFam ):
|
||||
@type filter_redirects bool/None
|
||||
|
||||
"""
|
||||
|
||||
# Helper to leave multidimensional loop
|
||||
# https://docs.python.org/3/faq/design.html#why-is-there-no-goto
|
||||
class Continue(Exception):
|
||||
pass
|
||||
|
||||
class Break(Exception):
|
||||
pass
|
||||
|
||||
# Iterate over articles in redfam
|
||||
for article in self.articlesList:
|
||||
|
||||
# To be able to control outer loop from inside child loops
|
||||
try:
|
||||
|
||||
# Not all list elements contain articles
|
||||
if not article:
|
||||
break
|
||||
raise Break()
|
||||
|
||||
page = pywikibot.Page(pywikibot.Link(article), pywikibot.Site())
|
||||
page = pywikibot.Page( pywikibot.Link(article),
|
||||
pywikibot.Site() )
|
||||
|
||||
# Filter existing pages if requested with filter_existing=False
|
||||
if page.exists():
|
||||
self.article_remove_status( "deleted", title=article )
|
||||
if filter_existing is False:
|
||||
continue
|
||||
# Filter non existing Pages if requested with filter_existing=True
|
||||
raise Continue()
|
||||
# Filter non existing Pages if requested with
|
||||
# filter_existing=True
|
||||
else:
|
||||
self.article_add_status( "deleted", title=article )
|
||||
if filter_existing:
|
||||
continue
|
||||
raise Continue()
|
||||
|
||||
# Filter redirects if requested with filter_redirects=True
|
||||
if page.isRedirectPage():
|
||||
self.article_add_status( "redirect", title=article )
|
||||
if filter_redirects:
|
||||
continue
|
||||
raise Continue()
|
||||
# Filter noredirects if requested with filter_redirects=False
|
||||
else:
|
||||
self.article_remove_status("redirect", title=article )
|
||||
if filter_redirects is False:
|
||||
continue
|
||||
raise Continue()
|
||||
|
||||
# Exclude by article status
|
||||
for status in exclude_article_status:
|
||||
if self.article_has_status( status, title=article ):
|
||||
continue
|
||||
raise Continue()
|
||||
|
||||
# Only include by article status
|
||||
for status in onlyinclude_article_status:
|
||||
if not self.article_has_status( status, title=article ):
|
||||
raise Continue()
|
||||
|
||||
# Proxy loop control to outer loop
|
||||
except Continue:
|
||||
continue
|
||||
except Break:
|
||||
break
|
||||
|
||||
# Yield filtered pages
|
||||
yield page
|
||||
|
||||
Reference in New Issue
Block a user