diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py index fb452c7581..b4346158b8 100644 --- a/pywikibot/__init__.py +++ b/pywikibot/__init__.py @@ -12,7 +12,6 @@ import datetime import difflib -import logging import math import re import sys @@ -28,11 +27,56 @@ # who want to continue using both from pywikibot import config2 as config -from pywikibot.bot import * -from pywikibot.exceptions import * -from pywikibot.textlib import * +from pywikibot.bot import ( + output, warning, error, critical, debug, stdout, exception, + input, inputChoice, handleArgs, showHelp, ui, log, + calledModuleName, Bot, WikidataBot, +) +from pywikibot.exceptions import ( + Error, InvalidTitle, BadTitle, NoPage, SectionError, + NoSuchSite, NoUsername, UserBlocked, + PageRelatedError, IsRedirectPage, IsNotRedirectPage, + PageNotSaved, UploadWarning, LockedPage, EditConflict, + ServerError, FatalServerError, Server504Error, + CaptchaError, SpamfilterError, CircularRedirect, + WikiBaseError, CoordinateGlobeUnknownException, +) +from pywikibot.textlib import ( + unescape, replaceExcept, removeDisabledParts, removeHTMLParts, + isDisabled, interwikiFormat, interwikiSort, + getLanguageLinks, replaceLanguageLinks, + removeLanguageLinks, removeLanguageLinksAndSeparator, + getCategoryLinks, categoryFormat, replaceCategoryLinks, + removeCategoryLinks, removeCategoryLinksAndSeparator, + replaceCategoryInPlace, compileLinkR, extract_templates_and_params, +) +from pywikibot.tools import UnicodeMixin from pywikibot.i18n import translate +__all__ = [ + 'config', 'ui', 'UnicodeMixin', 'translate', + 'Page', 'ImagePage', 'Category', 'Link', 'User', + 'ItemPage', 'PropertyPage', 'Claim', 'TimeStripper', + 'html2unicode', 'url2unicode', 'unicode2html', + 'stdout', 'output', 'warning', 'error', 'critical', 'debug', 'exception', + 'input', 'inputChoice', 'handleArgs', 'showHelp', 'ui', 'log', + 'calledModuleName', 'Bot', 'WikidataBot', + 'Error', 'InvalidTitle', 'BadTitle', 'NoPage', 'SectionError', + 'NoSuchSite', 'NoUsername', 'UserBlocked', + 'PageRelatedError', 'IsRedirectPage', 'IsNotRedirectPage', + 'PageNotSaved', 'UploadWarning', 'LockedPage', 'EditConflict', + 'ServerError', 'FatalServerError', 'Server504Error', + 'CaptchaError', 'SpamfilterError', 'CircularRedirect', + 'WikiBaseError', 'CoordinateGlobeUnknownException', + 'unescape', 'replaceExcept', 'removeDisabledParts', 'removeHTMLParts', + 'isDisabled', 'interwikiFormat', 'interwikiSort', + 'getLanguageLinks', 'replaceLanguageLinks', + 'removeLanguageLinks', 'removeLanguageLinksAndSeparator', + 'getCategoryLinks', 'categoryFormat', 'replaceCategoryLinks', + 'removeCategoryLinks', 'removeCategoryLinksAndSeparator', + 'replaceCategoryInPlace', 'compileLinkR', 'extract_templates_and_params', +] + class Timestamp(datetime.datetime): @@ -416,16 +460,16 @@ def wrapper(*__args, **__kw): if old_arg in __kw: if new_arg: if new_arg in __kw: - pywikibot.warning( + warning( u"%(new_arg)s argument of %(meth_name)s replaces %(old_arg)s; cannot use both." % locals()) else: - pywikibot.warning( + warning( u"%(old_arg)s argument of %(meth_name)s is deprecated; use %(new_arg)s instead." % locals()) __kw[new_arg] = __kw[old_arg] else: - pywikibot.debug( + debug( u"%(old_arg)s argument of %(meth_name)s is deprecated." % locals(), _logger) del __kw[old_arg] @@ -481,7 +525,7 @@ def Site(code=None, fam=None, user=None, sysop=None, interface=None): key = '%s:%s:%s' % (fam, code, user) if key not in _sites or not isinstance(_sites[key], __Site): _sites[key] = __Site(code=code, fam=fam, user=user, sysop=sysop) - pywikibot.debug(u"Instantiating Site object '%(site)s'" + debug(u"Instantiating Site object '%(site)s'" % {'site': _sites[key]}, _logger) return _sites[key] @@ -581,7 +625,7 @@ def stopme(): _logger = "wiki" if not stopped: - pywikibot.debug(u"stopme() called", _logger) + debug(u"stopme() called", _logger) def remaining(): remainingPages = page_put_queue.qsize() - 1 @@ -616,7 +660,7 @@ def remaining(): # only need one drop() call because all throttles use the same global pid try: list(_sites.values())[0].throttle.drop() - pywikibot.log(u"Dropped throttle(s).") + log(u"Dropped throttle(s).") except IndexError: pass diff --git a/pywikibot/botirc.py b/pywikibot/botirc.py index ee08540b05..f2138d32e9 100644 --- a/pywikibot/botirc.py +++ b/pywikibot/botirc.py @@ -18,22 +18,12 @@ # scripts, instead of writing each one from scratch. -import logging.handlers -# all output goes thru python std library "logging" module - import re from ircbot import SingleServerIRCBot -from irclib import nm_to_n _logger = "botirc" -# logging levels -from logging import DEBUG, INFO, WARNING, ERROR, CRITICAL -STDOUT = 16 -VERBOSE = 18 -INPUT = 25 - import pywikibot diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py index 2e875fb538..92d62d555d 100644 --- a/pywikibot/textlib.py +++ b/pywikibot/textlib.py @@ -610,7 +610,7 @@ def interwikiFormat(links, insite=None): link = title.replace('[[:', '[[') s.append(link) except AttributeError: - s.append(getSite(site).linkto(links[site], othersite=insite)) + s.append(pywikibot.Site(code=site).linkto(links[site], othersite=insite)) if insite.lang in insite.family.interwiki_on_one_line: sep = u' ' else: diff --git a/pywikibot/version.py b/pywikibot/version.py index 26bc0dc820..0377614514 100644 --- a/pywikibot/version.py +++ b/pywikibot/version.py @@ -203,7 +203,7 @@ def getfileversion(filename): """ _program_dir = _get_program_dir() __version__ = None - size, mtime = None, None + mtime = None fn = os.path.join(_program_dir, filename) if os.path.exists(fn): for line in open(fn, 'r').readlines(): diff --git a/pywikibot/weblib.py b/pywikibot/weblib.py index 11054dd196..017965a141 100644 --- a/pywikibot/weblib.py +++ b/pywikibot/weblib.py @@ -60,7 +60,7 @@ def getWebCitationURL(url, timestamp=None): query = {'returnxml': 'true', 'url': url} - if not timestamp is None: + if timestamp is not None: query['date'] = timestamp uri = uri + urllib.urlencode(query) diff --git a/scripts/blockreview.py b/scripts/blockreview.py index 6dac7b1808..f47383190b 100644 --- a/scripts/blockreview.py +++ b/scripts/blockreview.py @@ -24,6 +24,7 @@ import pywikibot from pywikibot.compat import query +from pywikibot import i18n class BlockreviewBot: diff --git a/scripts/replicate_wiki.py b/scripts/replicate_wiki.py index a7defbcac9..113ab8ff4e 100644 --- a/scripts/replicate_wiki.py +++ b/scripts/replicate_wiki.py @@ -31,9 +31,11 @@ # import sys -from pywikibot import * from itertools import imap +import pywikibot +from pywikibot import config, Page + def namespaces(site): """dict from namespace number to prefix""" @@ -67,7 +69,7 @@ def __init__(self, options): sites = options.destination_wiki - self.original = Site(original_wiki, family) + self.original = pywikibot.Site(original_wiki, family) self.original.login() if options.namespace and 'help' in options.namespace: @@ -76,7 +78,7 @@ def __init__(self, options): pywikibot.output('%s %s' % (k, nsd[k])) sys.exit() - self.sites = map(lambda s: Site(s, family), sites) + self.sites = map(lambda s: pywikibot.Site(s, family), sites) self.differences = {} self.user_diff = {}