Revision: 6683 Author: nicdumz Date: 2009-04-23 07:34:01 +0000 (Thu, 23 Apr 2009)
Log Message: ----------- Creating a Link factory method to create langlinks from the sanitized data returned by the API.
Modified Paths: -------------- branches/rewrite/pywikibot/page.py branches/rewrite/pywikibot/site.py
Modified: branches/rewrite/pywikibot/page.py =================================================================== --- branches/rewrite/pywikibot/page.py 2009-04-23 07:31:29 UTC (rev 6682) +++ branches/rewrite/pywikibot/page.py 2009-04-23 07:34:01 UTC (rev 6683) @@ -1970,6 +1970,28 @@
return link
+ @staticmethod + def langlinkUnSafe(lang, title, source): + """ + Create a "lang:title" Link linked from source. + Assumes that the lang & title come clean, no checks are made. + """ + link = Link.__new__(Link) + + link._site = pywikibot.Site(lang, source.family.name) + link._section = None + link._source = source + + if ':' in title: + ns, t = title.split(':', 1) + link._namespace = link._site.ns_index(ns.lower()) + link._title = t + else: + link._title = title + link._namespace = 0 + + return link + # Utility functions for parsing page titles
def html2unicode(text, ignore = []):
Modified: branches/rewrite/pywikibot/site.py =================================================================== --- branches/rewrite/pywikibot/site.py 2009-04-23 07:31:29 UTC (rev 6682) +++ branches/rewrite/pywikibot/site.py 2009-04-23 07:34:01 UTC (rev 6683) @@ -1381,9 +1381,9 @@ if 'langlinks' not in pageitem: continue for linkdata in pageitem['langlinks']: - yield pywikibot.Link('%s:%s' % (linkdata['lang'], - linkdata['*']), - source=self) + yield pywikibot.Link.langlinkUnsafe(linkdata['lang'], + linkdata['*'], + source=self)
def page_extlinks(self, page): """Iterate all external links on page, yielding URL strings."""
pywikipedia-svn@lists.wikimedia.org