Skip to content

Commit

Permalink
Merge "[IMPR] Provide a new generator which yields a subclass of Page"
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Mar 5, 2017
2 parents 28e9013 + 7167cb8 commit 9143efd
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions pywikibot/pagegenerators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1805,26 +1805,22 @@ def CombinedPageGenerator(generators):
return itertools.chain(*generators)


def CategoryGenerator(generator):
"""Yield pages from another generator as Category objects.
Makes sense only if it is ascertained that only categories are being
retrieved.
"""
for page in generator:
yield pywikibot.Category(page)


def FileGenerator(generator):
def PageClassGenerator(generator):
"""
Yield pages from another generator as FilePage objects.
Yield pages from another generator as Page subclass objects.
Makes sense only if it is ascertained
that only images are being retrieved.
The page class type depends on the page namespace.
Objects may be Category, FilePage, Userpage or Page.
"""
for page in generator:
yield pywikibot.FilePage(page)
if page.namespace() == page.site.namespaces.USER:
yield pywikibot.User(page)
elif page.namespace() == page.site.namespaces.FILE:
yield pywikibot.FilePage(page)
elif page.namespace() == page.site.namespaces.CATEGORY:
yield pywikibot.Category(page)
else:
yield page


def PageWithTalkPageGenerator(generator, return_talk_only=False):
Expand Down Expand Up @@ -2851,7 +2847,10 @@ def __iter__(self):


# Deprecated old names available for compatibility with compat.
ImageGenerator = redirect_func(FileGenerator, old_name='ImageGenerator')
ImageGenerator = redirect_func(PageClassGenerator, old_name='ImageGenerator')
FileGenerator = redirect_func(PageClassGenerator, old_name='FileGenerator')
CategoryGenerator = redirect_func(PageClassGenerator,
old_name='CategoryGenerator')
UnCategorizedTemplatesGenerator = redirect_func(
UnCategorizedTemplateGenerator, old_name='UnCategorizedTemplatesGenerator')
RecentchangesPageGenerator = redirect_func(
Expand Down

0 comments on commit 9143efd

Please sign in to comment.