jenkins-bot has submitted this change and it was merged.
Change subject: bugfix, code improvements ......................................................................
bugfix, code improvements
- fix identation error comming with https://mediawiki.org/wiki/Special:Code/pywikipedia/2337 - use set for better performance instead of searching in a list (maybe the the set should be returned) - bugfix for verbose variable - synchronize parts with compat
Change-Id: I88702e01270735890c903864f027e402508cd162 --- M pywikibot/titletranslate.py 1 file changed, 17 insertions(+), 18 deletions(-)
Approvals: Ladsgroup: Looks good to me, approved Alex S.H. Lin: Checked; Looks good to me, but someone else must approve jenkins-bot: Verified
diff --git a/pywikibot/titletranslate.py b/pywikibot/titletranslate.py index 8421ef3..2a9bae6 100644 --- a/pywikibot/titletranslate.py +++ b/pywikibot/titletranslate.py @@ -2,7 +2,7 @@ # # (C) Rob W.W. Hooft, 2003 # (C) Yuri Astrakhan, 2005 -# (C) Pywikibot team, 2003-2010 +# (C) Pywikibot team, 2003-2014 # # Distributed under the terms of the MIT license. # @@ -12,6 +12,7 @@
import pywikibot import pywikibot.date as date +from pywikibot import config
def translate(page, hints=None, auto=True, removebrackets=False, site=None, @@ -27,7 +28,7 @@ to all known target languages and inserted into the list.
""" - result = [] + result = set() if site is None and page: site = page.site if family is None and site: @@ -55,8 +56,8 @@ newname = page.title() # ... unless we do want brackets if removebrackets: - newname = re.sub(re.compile(r"\W*?(.*?)\W*?", re.UNICODE), - u" ", newname) + newname = re.sub(re.compile(r"\W*?(.*?)\W*?", + re.UNICODE), u" ", newname) try: number = int(codes) codes = site.family.languages_by_size[:number] @@ -71,10 +72,9 @@ if newcode in site.languages(): if newcode != site.code: x = pywikibot.Link(newname, site.getSite(code=newcode)) - if x not in result: - result.append(x) + result.add(x) else: - if pywikibot.verbose: + if config.verbose_output: pywikibot.output(u"Ignoring unknown language code %s" % newcode)
@@ -82,20 +82,20 @@ # existing interwiki links. if auto and page: # search inside all dictionaries for this link - dictName, value = date.getAutoFormat(page.site.code, - page.title()) + sitelang = page.site.code + dictName, value = date.getAutoFormat(sitelang, page.title()) if dictName: if not (dictName == 'yearsBC' and - page.site.code in date.maxyearBC and - value > date.maxyearBC[page.site.code]) or \ + sitelang in date.maxyearBC and + value > date.maxyearBC[sitelang]) or \ (dictName == 'yearsAD' and - page.site.code in date.maxyearAD and - value > date.maxyearAD[page.site.code]): + sitelang in date.maxyearAD and + value > date.maxyearAD[sitelang]): pywikibot.output( u'TitleTranslate: %s was recognized as %s with value %d' % (page.title(), dictName, value)) for entryLang, entry in date.formats[dictName].items(): - if entryLang != page.site.code: + if entryLang != sitelang: if (dictName == 'yearsBC' and entryLang in date.maxyearBC and value > date.maxyearBC[entryLang]): @@ -104,15 +104,14 @@ entryLang in date.maxyearAD and value > date.maxyearAD[entryLang]): pass - else: + else: newname = entry(value) x = pywikibot.Link( newname, pywikibot.Site(code=entryLang, fam=site.family)) - if x not in result: - result.append(x) # add new page - return result + result.add(x) + return list(result)
bcDateErrors = [u'[[ko:%d년]]']