jenkins-bot has submitted this change and it was merged.
Change subject: Update Wikia's MediaWiki version to 1.19.19
......................................................................
Update Wikia's MediaWiki version to 1.19.19
Change-Id: Ie9884df30805ba5156b99086a3a9b0bad8c7b1da
---
M pywikibot/families/lyricwiki_family.py
M pywikibot/families/wikia_family.py
M pywikibot/families/wowwiki_family.py
3 files changed, 3 insertions(+), 3 deletions(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/families/lyricwiki_family.py b/pywikibot/families/lyricwiki_family.py
index 799bb85..3a48529 100644
--- a/pywikibot/families/lyricwiki_family.py
+++ b/pywikibot/families/lyricwiki_family.py
@@ -24,7 +24,7 @@
def version(self, code):
"""Return the version for this family."""
- return '1.19.18'
+ return '1.19.19'
def scriptpath(self, code):
"""Return the script path for this family."""
diff --git a/pywikibot/families/wikia_family.py b/pywikibot/families/wikia_family.py
index 3e02043..81ee442 100644
--- a/pywikibot/families/wikia_family.py
+++ b/pywikibot/families/wikia_family.py
@@ -27,7 +27,7 @@
def version(self, code):
"""Return the version for this family."""
- return "1.19.18"
+ return "1.19.19"
def scriptpath(self, code):
"""Return the script path for this family."""
diff --git a/pywikibot/families/wowwiki_family.py b/pywikibot/families/wowwiki_family.py
index abe5d9f..aff88f7 100644
--- a/pywikibot/families/wowwiki_family.py
+++ b/pywikibot/families/wowwiki_family.py
@@ -65,4 +65,4 @@
def version(self, code):
"""Return the version for this family."""
- return '1.19.18'
+ return '1.19.19'
--
To view, visit https://gerrit.wikimedia.org/r/162863
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie9884df30805ba5156b99086a3a9b0bad8c7b1da
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Grunny <mwgrunny(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: [IMPROV] Use 'assertEqual' and 'assertRaisesRegex'
......................................................................
[IMPROV] Use 'assertEqual' and 'assertRaisesRegex'
In Python 3 'assertEquals' and 'assertRaisesRegexp' have been
deprecated. The new 'assertEqual' already exists in Python 2 but for
'assertRaisesRegex' a alias method was added (but not used everywhere).
Change-Id: Icfd0a61a48cc25886701ffa8b91f54881af553f0
---
M tests/api_tests.py
M tests/aspects.py
M tests/edit_failure_tests.py
M tests/i18n_tests.py
M tests/wikibase_tests.py
5 files changed, 14 insertions(+), 14 deletions(-)
Approvals:
Mpaa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/api_tests.py b/tests/api_tests.py
index a06e6fa..9639ba8 100644
--- a/tests/api_tests.py
+++ b/tests/api_tests.py
@@ -96,7 +96,7 @@
self.assertEqual(self.gen.limit, i)
def test_wrong_limit_setting(self):
- with self.assertRaisesRegexp(
+ with self.assertRaisesRegex(
ValueError,
"invalid literal for int\(\) with base 10: 'test'"):
self.gen.set_maximum_items('test')
diff --git a/tests/aspects.py b/tests/aspects.py
index 1a2ba6d..f86171b 100644
--- a/tests/aspects.py
+++ b/tests/aspects.py
@@ -48,13 +48,13 @@
"""Base class for all tests."""
if sys.version_info[0] < 3:
- def assertRaisesRegex(self, *args):
+ def assertRaisesRegex(self, *args, **kwargs):
"""
Wrapper of unittest.assertRaisesRegexp for Python 2 unittest.
assertRaisesRegexp is deprecated in Python 3.
"""
- return self.assertRaisesRegexp(*args)
+ return self.assertRaisesRegexp(*args, **kwargs)
class TestTimerMixin(TestCaseBase):
diff --git a/tests/edit_failure_tests.py b/tests/edit_failure_tests.py
index 1a11b33..57d3ffd 100644
--- a/tests/edit_failure_tests.py
+++ b/tests/edit_failure_tests.py
@@ -43,12 +43,12 @@
"""Test that spam in content raise the appropriate exception."""
page = pywikibot.Page(self.site, 'Wikipedia:Sandbox')
page.text = 'http://badsite.com'
- self.assertRaisesRegexp(SpamfilterError, 'badsite.com', page.save)
+ self.assertRaisesRegex(SpamfilterError, 'badsite.com', page.save)
def test_nobots(self):
"""Test that {{nobots}} raise the appropriate exception."""
page = pywikibot.Page(self.site, 'User:John Vandenberg/nobots')
- self.assertRaisesRegexp(OtherPageSaveError, 'nobots', page.save)
+ self.assertRaisesRegex(OtherPageSaveError, 'nobots', page.save)
class TestActionFailure(TestCase):
diff --git a/tests/i18n_tests.py b/tests/i18n_tests.py
index 2d33274..c72870b 100644
--- a/tests/i18n_tests.py
+++ b/tests/i18n_tests.py
@@ -218,13 +218,13 @@
def testMultipleWrongParameterLength(self):
"""Test wrong parameter lenght."""
- with self.assertRaisesRegexp(ValueError, "Length of parameter does not match PLURAL occurences"):
+ with self.assertRaisesRegex(ValueError, "Length of parameter does not match PLURAL occurences"):
self.assertEqual(
i18n.twntranslate('de', 'test-multiple-plurals', (1, 2))
% {'action': u'Ändere', 'line': u'drei'},
u'Bot: Ändere drei Zeilen von mehreren Seiten.')
- with self.assertRaisesRegexp(ValueError, "Length of parameter does not match PLURAL occurences"):
+ with self.assertRaisesRegex(ValueError, "Length of parameter does not match PLURAL occurences"):
self.assertEqual(
i18n.twntranslate('de', 'test-multiple-plurals', ["321"])
% {'action': u'Ändere', 'line': u'dreihunderteinundzwanzig'},
@@ -232,19 +232,19 @@
def testMultipleNonNumbers(self):
"""Numbers or string numbers are required for tuple or list items."""
- with self.assertRaisesRegexp(ValueError, "invalid literal for int\(\) with base 10: 'drei'"):
+ with self.assertRaisesRegex(ValueError, "invalid literal for int\(\) with base 10: 'drei'"):
self.assertEqual(
i18n.twntranslate('de', 'test-multiple-plurals', ["drei", "1", 1])
% {'action': u'Ändere', 'line': u'drei'},
u'Bot: Ändere drei Zeilen von einer Seite.')
- with self.assertRaisesRegexp(ValueError, "invalid literal for int\(\) with base 10: 'elf'"):
+ with self.assertRaisesRegex(ValueError, "invalid literal for int\(\) with base 10: 'elf'"):
self.assertEqual(
i18n.twntranslate('de', 'test-multiple-plurals',
{'action': u'Ändere', 'line': "elf", 'page': 2}),
u'Bot: Ändere elf Zeilen von mehreren Seiten.')
def testAllParametersExist(self):
- with self.assertRaisesRegexp(KeyError, repr(u'line')):
+ with self.assertRaisesRegex(KeyError, repr(u'line')):
# all parameters must be inside twntranslate
self.assertEqual(
i18n.twntranslate('de', 'test-multiple-plurals',
diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py
index 73768a8..fddfe33 100644
--- a/tests/wikibase_tests.py
+++ b/tests/wikibase_tests.py
@@ -394,7 +394,7 @@
# ItemPage.fromPage should raise an exception when not lazy loading
# and that exception should refer to the source title 'Test page'
# not the Item being created.
- self.assertRaisesRegexp(pywikibot.NoPage, 'Test page',
+ self.assertRaisesRegex(pywikibot.NoPage, 'Test page',
pywikibot.ItemPage.fromPage,
page, lazy_load=False)
@@ -406,7 +406,7 @@
# without a full debug log.
# It should raise NoPage on the source page, with title 'Test page'
# as that is what the bot operator needs to see in the log output.
- self.assertRaisesRegexp(pywikibot.NoPage, 'Test page', item.get)
+ self.assertRaisesRegex(pywikibot.NoPage, 'Test page', item.get)
class TestRedirects(WikidataTestCase):
@@ -851,7 +851,7 @@
self.wdp = pywikibot.Page(site, self.sites[key]['page_title'])
self.assertRaises(pywikibot.WikiBaseError,
pywikibot.ItemPage.fromPage, self.wdp)
- self.assertRaisesRegexp(pywikibot.WikiBaseError,
+ self.assertRaisesRegex(pywikibot.WikiBaseError,
'no transcluded data',
self.wdp.data_item)
@@ -904,7 +904,7 @@
}
}
diff = self.wdp.toJSON(diffto=self.wdp._content)
- self.assertEquals(diff, expected)
+ self.assertEqual(diff, expected)
if __name__ == '__main__':
--
To view, visit https://gerrit.wikimedia.org/r/162567
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Icfd0a61a48cc25886701ffa8b91f54881af553f0
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Siebrand <siebrand(a)kitano.nl>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Fix up timestripper for Korean and add ko tests
......................................................................
Fix up timestripper for Korean and add ko tests
Change-Id: Iaa72c87ed13a0f65451a7ad717abc94be4a8307f
---
M pywikibot/textlib.py
M tests/timestripper_tests.py
2 files changed, 7 insertions(+), 2 deletions(-)
Approvals:
John Vandenberg: Looks good to me, but someone else must approve
XZise: Looks good to me, approved
Ladsgroup: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index 241e73a..64da90b 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -1223,9 +1223,9 @@
# the last one is workaround for Korean
if any(_.isdigit() for _ in self.origNames2monthNum):
self.is_digit_month = True
- monthR = r'(?P<month>(%s)(?:\u0654)?|(?:1[012]|0?[1-9])\.?(?:\uc6d4)?)' \
+ monthR = r'(?P<month>(%s)|(?:1[012]|0?[1-9])\.)' \
% u'|'.join(escaped_months)
- dayR = r'(?P<day>(3[01]|[12]\d|0?[1-9]))(?:%s)?\.?\s*[01]?\d\.?' % u'\uc77c'
+ dayR = r'(?P<day>(3[01]|[12]\d|0?[1-9]))(?:%s)?\.?\s*(?:[01]?\d\.)?' % u'\uc77c'
else:
self.is_digit_month = False
monthR = r'(?P<month>(%s))' % u'|'.join(escaped_months)
diff --git a/tests/timestripper_tests.py b/tests/timestripper_tests.py
index 0f265e3..6c31248 100644
--- a/tests/timestripper_tests.py
+++ b/tests/timestripper_tests.py
@@ -151,6 +151,11 @@
'match': u'3 février 2010 à 19:48 (CET) 7 février 2010 à 19:48 (CET)',
'nomatch': u'3 March 2010 19:48 (CET) 7 March 2010 19:48 (CET)',
},
+ 'kowiki': {
+ 'family': 'wikipedia',
+ 'code': 'ko',
+ 'match': u'2010년 2월 3일 (수) 19:48 (KST) 2010년 2월 7일 (수) 19:48 (KST)',
+ },
'nowiki': {
'family': 'wikipedia',
'code': 'no',
--
To view, visit https://gerrit.wikimedia.org/r/162294
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iaa72c87ed13a0f65451a7ad717abc94be4a8307f
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Fix LockedPage exception documentation
......................................................................
Fix LockedPage exception documentation
The documentation for LockedPage places it in the
PageRelatedError part of the exception tree, when it belongs in
the PageSaveRelatedError part of the exception tree.
Change-Id: I6280a9a196a1e8ce6d3d0ba067258c9bc98742bc
---
M pywikibot/exceptions.py
1 file changed, 3 insertions(+), 3 deletions(-)
Approvals:
Nullzero: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/exceptions.py b/pywikibot/exceptions.py
index 51880db..ed620e1 100644
--- a/pywikibot/exceptions.py
+++ b/pywikibot/exceptions.py
@@ -20,14 +20,14 @@
- IsNotRedirectPage: Page is not a redirect page
- CircularRedirect: Page is a circular redirect
- SectionError: The section specified by # does not exist
- - LockedPage: Page is locked
- - LockedNoPage: Title is locked against creation
- - CascadeLockedPage: Page is locked due to cascading protection
PageSaveRelatedError: page exceptions within the save operation on a Page.
(alias: PageNotSaved)
- SpamfilterError: MediaWiki spam filter detected a blacklisted URL
- OtherPageSaveError: misc. other save related exception.
+ - LockedPage: Page is locked
+ - LockedNoPage: Title is locked against creation
+ - CascadeLockedPage: Page is locked due to cascading protection
- EditConflict: Edit conflict while uploading the page
- PageDeletedConflict: Page was deleted since being retrieved
- PageCreatedConflict: Page was created by another user
--
To view, visit https://gerrit.wikimedia.org/r/162500
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I6280a9a196a1e8ce6d3d0ba067258c9bc98742bc
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Nullzero <nullzero.free(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: family.py: make Family() comparable with strings
......................................................................
family.py: make Family() comparable with strings
Replace Family.__cmp__() with __eq__() and __ne__().
Now it will compare also to an object which is not an instance
of Family() and without a name attribute by trying to load the
corresponding family.
This will allow comparisons like:
site.family == pywikibot.config.family
Moved Family() from site.py to family.py and converted to staticmethod
Family.load().
Change-Id: Id3da11fd8a6e649bee768dbb42f53e7167fe43e3
---
M pywikibot/family.py
M pywikibot/page.py
M pywikibot/site.py
M pywikibot/textlib.py
M pywikibot/tools.py
M scripts/checkimages.py
M scripts/maintenance/wikimedia_sites.py
A tests/family_tests.py
M tox.ini
9 files changed, 193 insertions(+), 87 deletions(-)
Approvals:
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/family.py b/pywikibot/family.py
index a38f471..1bfd558 100644
--- a/pywikibot/family.py
+++ b/pywikibot/family.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-
+"""Objects representing MediaWiki families."""
#
# (C) Pywikibot team, 2004-2014
#
@@ -12,6 +12,7 @@
import logging
import re
import collections
+import imp
if sys.version_info[0] == 2:
from urlparse import urlparse
@@ -21,12 +22,15 @@
import pywikibot
from pywikibot import config2 as config
from pywikibot.tools import deprecated
+from pywikibot.exceptions import Error
logger = logging.getLogger("pywiki.wiki.family")
-# Parent class for all wiki families
class Family(object):
+
+ """Parent class for all wiki families."""
+
def __init__(self):
if not hasattr(self, 'name'):
self.name = None
@@ -840,6 +844,51 @@
# 'pt': { '_default': [0]}
# }
+ _families = {}
+
+ @staticmethod
+ def load(fam=None, fatal=True):
+ """Import the named family.
+
+ @param fam: family name (if omitted, uses the configured default)
+ @type fam: str
+ @param fatal: if True, the bot will stop running if the given family is
+ unknown. If False, it will only raise a ValueError exception.
+ @param fatal: bool
+ @return: a Family instance configured for the named family.
+
+ """
+ if fam is None:
+ fam = config.family
+ if fam in Family._families:
+ return Family._families[fam]
+
+ if fam in config.family_files:
+ family_file = config.family_files[fam]
+
+ if family_file.startswith('http://') or family_file.startswith('https://'):
+ myfamily = AutoFamily(fam, family_file)
+ Family._families[fam] = myfamily
+ return Family._families[fam]
+
+ try:
+ # Ignore warnings due to dots in family names.
+ import warnings
+ with warnings.catch_warnings():
+ warnings.simplefilter("ignore", RuntimeWarning)
+ myfamily = imp.load_source(fam, config.family_files[fam])
+ except (ImportError, KeyError):
+ if fatal:
+ pywikibot.error(u"""\
+ Error importing the %s family. This probably means the family
+ does not exist. Also check your configuration file."""
+ % fam, exc_info=True)
+ sys.exit(1)
+ else:
+ raise Error("Family %s does not exist" % fam)
+ Family._families[fam] = myfamily.Family()
+ return Family._families[fam]
+
@property
def iwkeys(self):
if self.interwiki_forward:
@@ -1033,11 +1082,23 @@
"""Return list of historical encodings for a specific language Wiki."""
return self.code2encodings(code)
- def __cmp__(self, otherfamily):
+ def __eq__(self, other):
+ """Compare self with other.
+
+ If other is not a Family() object, try to create one.
+ """
+ if not isinstance(other, Family):
+ other = self.load(other, fatal=False)
try:
- return cmp(self.name, otherfamily.name)
+ return self.name == other.name
except AttributeError:
- return cmp(id(self), id(otherfamily))
+ return id(self) == id(other)
+
+ def __ne__(self, other):
+ try:
+ return not self.__eq__(other)
+ except Error:
+ return False
def __hash__(self):
return hash(self.name)
@@ -1092,8 +1153,10 @@
return putText
-# Parent class for all wikimedia families
class WikimediaFamily(Family):
+
+ """#Class for all wikimedia families."""
+
def __init__(self):
super(WikimediaFamily, self).__init__()
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 39cb3ad..4cfced4 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -18,13 +18,16 @@
#
import sys
-import pywikibot
-from pywikibot import config
-from pywikibot.site import Namespace
-from pywikibot.exceptions import AutoblockUser, UserActionRefuse
-from pywikibot.tools import ComparableMixin, deprecated, deprecate_arg
-from pywikibot import textlib
+import logging
+import re
+import unicodedata
+import collections
import hashlib
+
+try:
+ from collections import OrderedDict
+except ImportError:
+ from ordereddict import OrderedDict
if sys.version_info[0] == 2:
import htmlentitydefs
@@ -37,15 +40,14 @@
from urllib.parse import quote_from_bytes, unquote_to_bytes
from urllib.request import urlopen
-import logging
-import re
-import sys
-import unicodedata
-import collections
-try:
- from collections import OrderedDict
-except ImportError:
- from ordereddict import OrderedDict
+import pywikibot
+from pywikibot import config
+from pywikibot.family import Family
+from pywikibot.site import Namespace
+from pywikibot.exceptions import AutoblockUser, UserActionRefuse
+from pywikibot.tools import ComparableMixin, deprecated, deprecate_arg
+from pywikibot import textlib
+
logger = logging.getLogger("pywiki.wiki.page")
@@ -3239,9 +3241,8 @@
"""
if not hasattr(self, 'sitelinks'):
self.get()
- if family is not None and not isinstance(family,
- pywikibot.family.Family):
- family = pywikibot.site.Family(family)
+ if family is not None and not isinstance(family, Family):
+ family = Family.load(family)
for dbname in self.sitelinks:
pg = Page(pywikibot.site.APISite.fromDBName(dbname),
self.sitelinks[dbname])
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 4967aa0..320bc4e 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -14,7 +14,6 @@
#
import datetime
-import imp
import itertools
import os
import re
@@ -27,8 +26,7 @@
import copy
import pywikibot
-from pywikibot import config
-from pywikibot.family import AutoFamily
+import pywikibot.family
from pywikibot.tools import (
itergroup, deprecated, deprecate_arg, UnicodeMixin, ComparableMixin,
)
@@ -51,6 +49,7 @@
SpamfilterError,
UserBlocked,
)
+
from pywikibot.echo import Notification
if sys.version_info[0] > 2:
@@ -102,50 +101,11 @@
def __repr__(self):
return 'LoginStatus(%s)' % (LoginStatus.name(self.state))
-_families = {}
-
-def Family(fam=None, fatal=True):
- """Import the named family.
-
- @param fam: family name (if omitted, uses the configured default)
- @type fam: str
- @param fatal: if True, the bot will stop running if the given family is
- unknown. If False, it will only raise a ValueError exception.
- @param fatal: bool
- @return: a Family instance configured for the named family.
-
- """
- if fam is None:
- fam = config.family
- if fam in _families:
- return _families[fam]
-
- if fam in config.family_files:
- family_file = config.family_files[fam]
-
- if family_file.startswith('http://') or family_file.startswith('https://'):
- myfamily = AutoFamily(fam, family_file)
- _families[fam] = myfamily
- return _families[fam]
-
- try:
- # Ignore warnings due to dots in family names.
- import warnings
- with warnings.catch_warnings():
- warnings.simplefilter("ignore", RuntimeWarning)
- myfamily = imp.load_source(fam, config.family_files[fam])
- except (ImportError, KeyError):
- if fatal:
- pywikibot.error(u"""\
-Error importing the %s family. This probably means the family
-does not exist. Also check your configuration file."""
- % fam, exc_info=True)
- sys.exit(1)
- else:
- raise Error("Family %s does not exist" % fam)
- _families[fam] = myfamily.Family()
- return _families[fam]
+Family = pywikibot.tools.redirect_func(pywikibot.family.Family.load,
+ 'pywikibot.site',
+ 'pywikibot.family.Family',
+ 'Family')
class Namespace(Iterable, ComparableMixin, UnicodeMixin):
@@ -447,7 +407,7 @@
"""
self.__code = code.lower()
if isinstance(fam, basestring) or fam is None:
- self.__family = Family(fam, fatal=False)
+ self.__family = pywikibot.family.Family.load(fam, fatal=False)
else:
self.__family = fam
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index 10088ac..fd065c6 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -18,10 +18,10 @@
import mwparserfromhell
except ImportError:
mwparserfromhell = False
-import pywikibot
import datetime
import re
import sys
+
if sys.version_info[0] == 2:
from HTMLParser import HTMLParser
else:
@@ -29,7 +29,10 @@
basestring = (str,)
unicode = str
-from . import config2 as config
+from pywikibot import config2 as config
+import pywikibot
+from pywikibot.family import Family
+
TEMP_REGEX = re.compile(
'{{(?:msg:)?(?P<name>[^{\|]+?)(?:\|(?P<params>[^{]+?(?:{[^{]+?}[^{]*?)?))?}}')
@@ -416,7 +419,7 @@
# when interwiki links forward to another family, retrieve pages & other
# infos there
if fam.interwiki_forward:
- fam = pywikibot.site.Family(fam.interwiki_forward)
+ fam = Family.load(fam.interwiki_forward)
result = {}
# Ignore interwiki links within nowiki tags, includeonly tags, pre tags,
# and HTML comments
diff --git a/pywikibot/tools.py b/pywikibot/tools.py
index 1cbe087..10c78f6 100644
--- a/pywikibot/tools.py
+++ b/pywikibot/tools.py
@@ -321,7 +321,8 @@
return decorator
-def redirect_func(target, source_module=None, target_module=None):
+def redirect_func(target, source_module=None, target_module=None,
+ old_name=None):
"""
Return a function which can be used to redirect to 'target'.
@@ -338,16 +339,20 @@
'None' (default) it tries to get it from the target. Might not work
with nested classes.
@type target_module: basestring
+ @param old_name: The old function name. If None it uses the name of the
+ new function.
+ @type old_name: basestring
@return: A new function which adds a warning prior to each execution.
@rtype: callable
"""
class Wrapper(object):
- def __init__(self, function, source, target):
- self._function = function
- self.parameters = {'new': function.__name__,
- 'target': target,
- 'source': source}
- self.warning = ('{source}{new} is DEPRECATED, use {target}{new} '
+ def __init__(self):
+ self._function = target
+ self.parameters = {'new': target.__name__,
+ 'old': old_name or target.__name__,
+ 'target': target_module,
+ 'source': source_module}
+ self.warning = ('{source}{old} is DEPRECATED, use {target}{new} '
'instead.').format(**self.parameters)
def call(self, *a, **kw):
@@ -367,7 +372,7 @@
else:
source_module = (sys._getframe(1).f_code.co_filename.rsplit("/", 1)[0]
.replace("/", ".") + ".")
- return Wrapper(target, source_module, target_module).call
+ return Wrapper().call
if __name__ == "__main__":
diff --git a/scripts/checkimages.py b/scripts/checkimages.py
index c851382..980f3ce 100644
--- a/scripts/checkimages.py
+++ b/scripts/checkimages.py
@@ -100,6 +100,7 @@
import pywikibot
from pywikibot import pagegenerators as pg
from pywikibot import config, i18n
+from pywikibot.family import Family
if sys.version_info[0] > 2:
basestring = (str, )
@@ -875,7 +876,7 @@
"""Function to load the white templates."""
# A template as {{en is not a license! Adding also them in the
# whitelist template...
- for langK in pywikibot.site.Family('wikipedia').langs.keys():
+ for langK in Family.load('wikipedia').langs.keys():
self.hiddentemplates.add(pywikibot.Page(self.site,
u'Template:%s' % langK))
# Hidden template loading
diff --git a/scripts/maintenance/wikimedia_sites.py b/scripts/maintenance/wikimedia_sites.py
index fa94029..785b51b 100644
--- a/scripts/maintenance/wikimedia_sites.py
+++ b/scripts/maintenance/wikimedia_sites.py
@@ -18,7 +18,7 @@
import sys
import pywikibot
-from pywikibot.site import Family
+from pywikibot.family import Family
if sys.version_info[0] > 2:
from urllib.request import urlopen
@@ -46,8 +46,8 @@
for family in families or familiesDict.keys():
pywikibot.output('\nChecking family %s:' % family)
- original = Family(family).languages_by_size
- obsolete = Family(family).obsolete
+ original = Family.load(family).languages_by_size
+ obsolete = Family.load(family).obsolete
feed = urlopen(URL % familiesDict[family])
tree = cElementTree.parse(feed)
diff --git a/tests/family_tests.py b/tests/family_tests.py
new file mode 100644
index 0000000..1115d91
--- /dev/null
+++ b/tests/family_tests.py
@@ -0,0 +1,73 @@
+# -*- coding: utf-8 -*-
+"""Tests for the family module."""
+#
+# (C) Pywikibot team, 2014
+#
+# Distributed under the terms of the MIT license.
+#
+__version__ = '$Id$'
+
+from pywikibot.family import Family
+from pywikibot.exceptions import Error
+
+from tests.aspects import (
+ unittest,
+ TestCase,
+)
+
+
+class TestFamily(TestCase):
+
+ """Test cases for Family methods."""
+
+ net = False
+
+ def setUp(self):
+ super(TestCase, self).setUp()
+
+ def tearDown(self):
+ super(TestCase, self).tearDown()
+
+ def test_eq_different_families_by_name(self):
+ """Test that two Family with same name are equal."""
+ family_1 = Family()
+ family_2 = Family()
+ family_1.name = 'a'
+ family_2.name = 'a'
+ self.assertNotEqual(id(family_1), id(family_2))
+ self.assertEqual(family_1, family_2)
+
+ def test_eq_different_families_by_id(self):
+ """Test that two Family with no name attribute are not equal."""
+ family_1 = Family()
+ family_2 = Family()
+ family_1.name = 'a'
+ del family_2.name
+ self.assertNotEqual(id(family_1), id(family_2))
+ self.assertNotEqual(family_1, family_2)
+
+ def test_eq_family_with_string_repr_same_family(self):
+ """Test that Family and string with same name are equal."""
+ family = Family.load('wikipedia', fatal=False)
+ other = 'wikipedia'
+ self.assertEqual(family, other)
+ self.assertFalse(family != other)
+
+ def test_ne_family_with_string_repr_different_family(self):
+ """Test that Family and string with different name are not equal."""
+ family = Family.load('wikipedia', fatal=False)
+ other = 'wikisource'
+ self.assertNotEqual(family, other)
+ self.assertFalse(family == other)
+
+ def test_eq_family_with_string_repr_not_existing_family(self):
+ """Test that Family and string with different name are not equal."""
+ family = Family.load('wikipedia', fatal=False)
+ other = 'unknown'
+ self.assertRaises(Error, family.__eq__, other)
+
+if __name__ == '__main__':
+ try:
+ unittest.main()
+ except SystemExit:
+ pass
diff --git a/tox.ini b/tox.ini
index a3ce817..77c1f04 100644
--- a/tox.ini
+++ b/tox.ini
@@ -32,7 +32,7 @@
./pywikibot/userinterfaces/terminal_interface.py \
./pywikibot/page.py ./pywikibot/version.py ./pywikibot/plural.py \
./pywikibot/botirc.py ./pywikibot/interwiki_graph.py ./pywikibot/tools.py \
- ./pywikibot/bot.py \
+ ./pywikibot/bot.py ./pywikibot/family.py \
./pywikibot/data/__init__.py \
./pywikibot/compat/userlib.py ./pywikibot/compat/catlib.py \
./pywikibot/compat/query.py
--
To view, visit https://gerrit.wikimedia.org/r/156047
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Id3da11fd8a6e649bee768dbb42f53e7167fe43e3
Gerrit-PatchSet: 18
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>