jenkins-bot has submitted this change and it was merged.
Change subject: PEP257 on pywikibot folder part III ......................................................................
PEP257 on pywikibot folder part III
files: logentries, login, page, pagegenerators, textlib, throttle. tools, version, xmlreader Checked by hand and added some suggestions based on this change: I910fdd7ce36752fa44b9a6654d7b8509e5020dee
Change-Id: Ic65452262d16ba2ec83633125ce1e3145a6f3aef --- M pywikibot/logentries.py M pywikibot/login.py M pywikibot/page.py M pywikibot/pagegenerators.py M pywikibot/textlib.py M pywikibot/throttle.py M pywikibot/version.py M pywikibot/xmlreader.py 8 files changed, 58 insertions(+), 55 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/logentries.py b/pywikibot/logentries.py index 6cd2cc6..dfcb883 100644 --- a/pywikibot/logentries.py +++ b/pywikibot/logentries.py @@ -1,7 +1,5 @@ # -*- coding: utf-8 -*- -""" -Objects representing Mediawiki log entries -""" +"""Objects representing Mediawiki log entries.""" # # (C) Pywikibot team, 2007-2013 # @@ -23,6 +21,7 @@
It also logs debugging information when a key is missing. """ + def __missing__(self, key): pywikibot.debug(u"API log entry received:\n" + repr(self), _logger) @@ -127,7 +126,7 @@ """ Return a list of (str) flags associated with the block entry.
- Raises an Error if the entry is an unblocking log entry + It raises an Error if the entry is an unblocking log entry. """ if hasattr(self, '_flags'): return self._flags @@ -138,8 +137,8 @@ """ Return a datetime.timedelta representing the block duration.
- It returns None if block is indefinite. - Raises an Error if the entry is an unblocking log entry + @return: datetime.timedelta, or None if block is indefinite. + @raises Error: the entry is an unblocking log entry. """ if hasattr(self, '_duration'): return self._duration @@ -154,7 +153,7 @@ """ Return a Timestamp representing the block expiry date.
- Raises an Error if the entry is an unblocking log entry + @raises Error: the entry is an unblocking log entry. """ if hasattr(self, '_expiry'): return self._expiry @@ -185,7 +184,7 @@ return self.data['move']['new_ns']
def new_title(self): - """Page object of the new title""" + """Return page object of the new title.""" if not hasattr(self, '_new_title'): self._new_title = pywikibot.Page(pywikibot.Link(self.data['move']['new_title'])) return self._new_title @@ -217,7 +216,7 @@ class LogEntryFactory(object):
""" - LogEntry Factory + LogEntry Factory.
Only available method is create() """ @@ -257,7 +256,7 @@ @param logdata: <item> returned by the api @type logdata: dict
- @return LogEntry object representing logdata + @return: LogEntry object representing logdata """ return self._creator(logdata)
@@ -266,7 +265,8 @@ """ Return the class corresponding to the @logtype string parameter.
- Returns LogEntry if logtype is unknown or not supported + @return: specified subclass of LogEntry, or LogEntry + @rtype: class """ try: return LogEntryFactory._logtypes[logtype] @@ -276,6 +276,10 @@ def _createFromData(self, logdata): """ Check for logtype from data, and creates the correct LogEntry. + + @param logdata: log entry data + @type logdata: dict + @rtype: LogEntry """ try: logtype = logdata['type'] diff --git a/pywikibot/login.py b/pywikibot/login.py index 1445d4b..feece17 100644 --- a/pywikibot/login.py +++ b/pywikibot/login.py @@ -1,8 +1,6 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -""" -Library to log the robot in to a wiki account. -""" +"""Library to log the bot in to a wiki account.""" # # (C) Rob W.W. Hooft, 2003 # (C) Pywikibot team, 2003-2012 diff --git a/pywikibot/page.py b/pywikibot/page.py index d9287f5..3d5dfe3 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -141,7 +141,8 @@ def namespace(self): """Return the number of the namespace of the page.
- @return: int + @return: namespace of the page + @rtype: int """ return self._link.namespace
@@ -394,7 +395,8 @@ def text(self): """Return the current (edited) wikitext, loading it if necessary.
- @return: unicode + @return: text of the page + @rtype: unicode """ if not hasattr(self, '_text') or self._text is None: try: @@ -3567,7 +3569,8 @@ """ Format the target into the proper JSON value that Wikibase wants.
- @return: dict + @return: JSON value + @rtype: dict """ if self.type == 'wikibase-item': value = {'entity-type': 'item', diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py index 91c973b..0ba02b4 100644 --- a/pywikibot/pagegenerators.py +++ b/pywikibot/pagegenerators.py @@ -215,6 +215,7 @@ This factory is responsible for processing command line arguments that are used by many scripts and that determine which pages to work on. """ + def __init__(self, site=None): self.gens = [] self.namespaces = [] @@ -230,7 +231,6 @@
Only call this after all arguments have been parsed. """ - if gen: self.gens.insert(0, gen)
@@ -889,7 +889,7 @@
@classmethod def __precompile(cls, regex, flag): - """ precompile the regex list if needed. """ + """Precompile the regex list if needed.""" # Enable multiple regexes if not isinstance(regex, list): regex = [regex] @@ -906,6 +906,7 @@ """ Yield pages from another generator whose title matches regex.
Uses regex option re.IGNORECASE depending on the quantifier parameter. + If ignore_namespace is False, the whole page title is compared. NOTE: if you want to check for a match at the beginning of the title, you have to start the regex with "^" @@ -1050,7 +1051,6 @@ @deprecate_arg("lookahead", None) def PreloadingGenerator(generator, step=50): """Yield preloaded pages taken from another generator.""" - # pages may be on more than one site, for example if an interwiki # generator is used, so use a separate preloader for each site sites = {} diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py index 0efe511..10088ac 100644 --- a/pywikibot/textlib.py +++ b/pywikibot/textlib.py @@ -335,8 +335,7 @@ """ Return True if text[index] is disabled, e.g. by a comment or by nowiki tags.
- For the tags parameter, see removeDisabledParts() above. - + For the tags parameter, see L{removeDisabledParts}. """ # Find a marker that is not already in the text. marker = findmarker(text) @@ -508,7 +507,6 @@ 'new' should be a dict with the Site objects as keys, and Page or Link objects as values (i.e., just like the dict returned by getLanguageLinks function). - """ # Find a marker that is not already in the text. marker = findmarker(oldtext) @@ -596,7 +594,6 @@
Return a unicode string that is formatted for inclusion in insite (defaulting to the current site). - """ if insite is None: insite = pywikibot.Site() @@ -654,8 +651,7 @@ """Return a list of category links found in text.
@return: all category links found - @returntype: list of Category objects - + @rtype: list of Category objects """ result = [] if site is None: @@ -688,7 +684,6 @@
Put the string marker after the last replacement (at the end of the text if there is no replacement). - """ # This regular expression will find every link that is possibly an # interwiki link, plus trailing whitespace. The language code is grouped. @@ -728,9 +723,14 @@
def replaceCategoryInPlace(oldtext, oldcat, newcat, site=None): - """Replace the category oldcat with the category newcat. + """ + Replace old category with new one and return the modified text.
+ @param oldtext: Content of the old category + @param oldcat: pywikibot.Category object of the old category + @param newcat: pywikibot.Category object of the new category @return: the modified text + @rtype: unicode """ if site is None: site = pywikibot.Site() @@ -752,11 +752,9 @@ r'^[^\S\n]*[[\s*(%s)\s*:\s*%s\s*((?:|[^]]+)?]])[^\S\n]*\n' % (catNamespace, title), re.I | re.M) if newcat is None: - """ First go through and try the more restrictive regex that removes - an entire line, if the category is the only thing on that line (this - prevents blank lines left over in category lists following a removal.) - """ - + # First go through and try the more restrictive regex that removes + # an entire line, if the category is the only thing on that line (this + # prevents blank lines left over in category lists following a removal.) text = replaceExcept(oldtext, categoryRN, '', ['nowiki', 'comment', 'math', 'pre', 'source']) text = replaceExcept(text, categoryR, '', @@ -773,12 +771,11 @@ """ Replace all existing category links with new category links.
- 'new' should be a list of Category objects or strings - which can be either the raw name or [[Category:..]]. - - If addOnly is True, the old category won't be deleted and the - category(s) given will be added (and so they won't replace anything). - + @param oldtext: The text that needs to be replaced. + @param new: Should be a list of Category objects or strings + which can be either the raw name or [[Category:..]]. + @param addOnly: If addOnly is True, the old category won't be deleted and the + category(s) given will be added (and so they won't replace anything). """ # Find a marker that is not already in the text. marker = findmarker(oldtext) @@ -841,7 +838,6 @@ which can be either the raw name or [[Category:..]].
The string is formatted for inclusion in insite. - """ if not categories: return '' @@ -951,7 +947,6 @@ @return: list of template name and params @rtype: list of tuple """ - # remove commented-out stuff etc. thistxt = removeDisabledParts(text)
@@ -1108,7 +1103,6 @@ You can use items from extract_templates_and_params here to get an equivalent template wiki text (it may happen that the order of the params changes). - """ (template, params) = template_and_params text = u'' @@ -1136,7 +1130,6 @@ If a section parameter contains a internal link, it will match the section with or without a preceding colon which is required for a text link e.g. for categories and files. - """ # match preceding colon for text links section = re.sub(r'\[\[(\:)?', '[[:?', re.escape(section)) @@ -1155,8 +1148,9 @@ """ Class building tzinfo objects for fixed-offset time zones.
- @offset: a number indicating fixed offset in minutes east from UTC - @name: a string with name of the timezone""" + @param offset: a number indicating fixed offset in minutes east from UTC + @param name: a string with name of the timezone + """
def __init__(self, offset, name): self.__offset = datetime.timedelta(minutes=offset) @@ -1248,7 +1242,9 @@
def last_match_and_replace(self, txt, pat): """ - Take the rightmost match, to prevent spurious earlier matches, and replace with marker. + Take the rightmost match and replace with marker. + + It does so to prevent spurious earlier matches. """ m = None cnt = 0 @@ -1279,7 +1275,6 @@
All the following items must be matched, otherwise None is returned: -. year, month, hour, time, day, minute, tzinfo - """ # match date fields dateDict = dict() diff --git a/pywikibot/throttle.py b/pywikibot/throttle.py index ffd4367..003b522 100644 --- a/pywikibot/throttle.py +++ b/pywikibot/throttle.py @@ -1,7 +1,5 @@ # -*- coding: utf-8 -*- -""" -Mechanics to slow down wiki read and/or write rate. -""" +"""Mechanics to slow down wiki read and/or write rate.""" # # (C) Pywikibot team, 2008 # @@ -180,7 +178,7 @@ return thisdelay
def waittime(self, write=False): - """Return waiting time in seconds if a query would be made right now""" + """Return waiting time in seconds if a query would be made right now.""" # Take the previous requestsize in account calculating the desired # delay this time thisdelay = self.getDelay(write=write) diff --git a/pywikibot/version.py b/pywikibot/version.py index 7ca8a0c..c8cb36c 100644 --- a/pywikibot/version.py +++ b/pywikibot/version.py @@ -23,7 +23,7 @@
class ParseError(Exception):
- """ Parsing went wrong. """ + """Parsing went wrong."""
def _get_program_dir(): @@ -260,6 +260,12 @@
Extracts __version__ variable containing Id tag, without importing it. (thus can be done for any file) + + The version variable containing the Id tag is read and + returned. Because it doesn't import it, the version can + be retrieved from any file. + @param filename: Name of the file to get version + @type filename: string """ _program_dir = _get_program_dir() __version__ = None diff --git a/pywikibot/xmlreader.py b/pywikibot/xmlreader.py index e327b6e..56993c4 100644 --- a/pywikibot/xmlreader.py +++ b/pywikibot/xmlreader.py @@ -46,9 +46,8 @@
class XmlEntry:
- """ - Represents a page. - """ + """Represent a page.""" + def __init__(self, title, ns, id, text, username, ipedit, timestamp, editRestriction, moveRestriction, revisionid, comment, redirect):
pywikibot-commits@lists.wikimedia.org