jenkins-bot has submitted this change and it was merged.
Change subject: Allow unicode in cache entry description
......................................................................
Allow unicode in cache entry description
The entry description has historically been checked to be a ascii string.
This removes that check, allowing it to contain non-ascii, and adds
documentation for the relevant methods.
The entry description is hashed and converted to a hexdigest to become
a unique cache key. The entry description is stored in the cache entry,
and compared to the request parameters.
Change-Id: I51b8052a8c6b73452d7a486d60d36393eefb25e0
---
M pywikibot/data/api.py
1 file changed, 18 insertions(+), 5 deletions(-)
Approvals:
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index eb97667..5cb880b 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -768,15 +768,19 @@
If this is modified, please also update
scripts/maintenance/cache.py to support
the new key and all previous keys.
+
+ @rtype: unicode
"""
login_status = self.site._loginstatus
if login_status > pywikibot.site.LoginStatus.NOT_LOGGED_IN and \
hasattr(self.site, '_userinfo') and \
'name' in self.site._userinfo:
- # This uses the format of Page.__repr__(), without the encoding
- # it performs. This string cant be encoded otherwise it creates an
- # exception when _create_file_name() tries to encode it again.
+ # This uses the format of Page.__repr__, without performing
+ # config.console_encoding as done by Page.__repr__.
+ # The returned value cant be encoded to anything other than
+ # ascii otherwise it creates an exception when _create_file_name()
+ # tries to encode it as utf-8.
user_key = u'User(User:%s)' % self.site._userinfo['name']
else:
user_key = pywikibot.site.LoginStatus(
@@ -787,6 +791,11 @@
return repr(self.site) + user_key + request_key
def _create_file_name(self):
+ """
+ Return a unique ascii identifier for the cache entry.
+
+ @rtype: str (hexademical; i.e. characters 0-9 and a-f only)
+ """
return hashlib.sha256(
self._uniquedescriptionstr().encode('utf-8')
).hexdigest()
@@ -799,13 +808,17 @@
return dt + self.expiry < datetime.datetime.now()
def _load_cache(self):
- """Return whether the cache can be used."""
+ """Load cache entry for request, if available.
+
+ @return: Whether the request was loaded from the cache
+ @rtype: bool
+ """
self._add_defaults()
try:
filename = self._cachefile_path()
with open(filename, 'rb') as f:
uniquedescr, self._data, self._cachetime = pickle.load(f)
- assert(uniquedescr == str(self._uniquedescriptionstr()))
+ assert(uniquedescr == self._uniquedescriptionstr())
if self._expired(self._cachetime):
self._data = None
return False
--
To view, visit https://gerrit.wikimedia.org/r/169987
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I51b8052a8c6b73452d7a486d60d36393eefb25e0
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(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: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Epydoc syntax issues
......................................................................
Epydoc syntax issues
Change-Id: I368c3588e022900c494008f98e33df4fc876feed
---
M pywikibot/__init__.py
M pywikibot/bot.py
M pywikibot/comms/http.py
M pywikibot/comms/threadedhttp.py
M pywikibot/config2.py
M pywikibot/data/api.py
M pywikibot/data/wikidataquery.py
M pywikibot/date.py
M pywikibot/diff.py
M pywikibot/editor.py
M pywikibot/exceptions.py
M pywikibot/family.py
M pywikibot/i18n.py
M pywikibot/logentries.py
M pywikibot/page.py
M pywikibot/pagegenerators.py
M pywikibot/site.py
M pywikibot/textlib.py
M pywikibot/tools.py
M pywikibot/userinterfaces/gui.py
M pywikibot/userinterfaces/terminal_interface_base.py
M pywikibot/weblib.py
22 files changed, 331 insertions(+), 287 deletions(-)
Approvals:
John Vandenberg: Looks good to me, but someone else must approve
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index c1e0e79..e20d7c4 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -271,13 +271,13 @@
In small angle approximation (and thus in radians):
- Δλ ≈ Δpos / r_φ, where r_φ is the radius of earth at the given latitude.
+ M{Δλ ≈ Δpos / r_φ}, where r_φ is the radius of earth at the given latitude.
Δλ is the error in longitude.
- r_φ = r cos φ, where r is the radius of earth, φ the latitude
+ M{r_φ = r cos φ}, where r is the radius of earth, φ the latitude
- Therefore:
- precision = math.degrees(self._dim/(radius*math.cos(math.radians(self.lat))))
+ Therefore::
+ precision = math.degrees(self._dim/(radius*math.cos(math.radians(self.lat))))
"""
if not self._precision:
radius = 6378137 # TODO: Support other globes
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index caafaca..7b100e1 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -122,12 +122,12 @@
r"""
Convert exception trace to unicode if necessary.
- Make sure that the exception trace is converted to unicode:
- * our pywikibot.Error traces are encoded in our
- console encoding, which is needed for plainly printing them.
- * but when it comes to logging using logging.exception,
- the Python logging module will try to use these traces,
- and it will fail if they are console encoded strings.
+ Make sure that the exception trace is converted to unicode.
+
+ L{exceptions.Error} traces are encoded in our console encoding, which
+ is needed for plainly printing them. However, when logging them
+ using logging.exception, the Python logging module will try to use
+ these traces, and it will fail if they are console encoded strings.
Formatter.formatException also strips the trailing \n, which we need.
"""
@@ -165,9 +165,6 @@
This function must be called before using pywikibot.output(); and must
be called again if the destination stream is changed.
- @param strm: Output stream. If None, re-uses the last stream if one
- was defined, otherwise uses sys.stderr
-
Note: this function is called by handleArgs(), so it should normally
not need to be called explicitly
@@ -175,18 +172,24 @@
Each type of output is handled by an appropriate handler object.
This structure is used to permit eventual development of other
user interfaces (GUIs) without modifying the core bot code.
+
The following output levels are defined:
- DEBUG - only for file logging; debugging messages
- STDOUT - output that must be sent to sys.stdout (for bots that may
- have their output redirected to a file or other destination)
- VERBOSE - optional progress information for display to user
- INFO - normal (non-optional) progress information for display to user
- INPUT - prompts requiring user response
- WARN - user warning messages
- ERROR - user error messages
- CRITICAL - fatal error messages
+ - DEBUG: only for file logging; debugging messages.
+ - STDOUT: output that must be sent to sys.stdout (for bots that may
+ have their output redirected to a file or other destination).
+ - VERBOSE: optional progress information for display to user.
+ - INFO: normal (non-optional) progress information for display to user.
+ - INPUT: prompts requiring user response.
+ - WARN: user warning messages.
+ - ERROR: user error messages.
+ - CRITICAL: fatal error messages.
+
Accordingly, do ''not'' use print statements in bot code; instead,
use pywikibot.output function.
+
+ @param strm: Output stream. If None, re-uses the last stream if one
+ was defined, otherwise uses sys.stderr
+
"""
global _handlers_initialized
@@ -464,18 +467,21 @@
def exception(msg=None, decoder=None, newline=True, tb=False, **kwargs):
"""Output an error traceback to the user via the userinterface.
- @param tb: Set to True in order to output traceback also.
+ Use directly after an 'except' statement::
- Use directly after an 'except' statement:
- ...
- except:
- pywikibot.exception()
- ...
- or alternatively:
- ...
- except Exception as e:
- pywikibot.exception(e)
- ...
+ ...
+ except:
+ pywikibot.exception()
+ ...
+
+ or alternatively::
+
+ ...
+ except Exception as e:
+ pywikibot.exception(e)
+ ...
+
+ @param tb: Set to True in order to output traceback also.
"""
if isinstance(msg, BaseException):
exc_info = 1
@@ -494,14 +500,12 @@
def input(question, password=False):
"""Ask the user a question, return the user's answer.
- Parameters:
- * question - a unicode string that will be shown to the user. Don't add a
- space after the question mark/colon, this method will do this
- for you.
- * password - if True, hides the user's input (for password entry).
-
- Returns a unicode string.
-
+ @param question: a string that will be shown to the user. Don't add a
+ space after the question mark/colon, this method will do this for you.
+ @type question: unicode
+ @param password: if True, hides the user's input (for password entry).
+ @type password: bool
+ @rtype: unicode
"""
# make sure logging system has been initialized
if not _handlers_initialized:
@@ -517,7 +521,7 @@
Ask the user the question and return one of the valid answers.
@param question: The question asked without trailing spaces.
- @type answers: basestring
+ @type question: basestring
@param answers: The valid answers each containing a full length answer and
a shortcut. Each value must be unique.
@type answers: Iterable containing an iterable of length two
@@ -549,7 +553,7 @@
Ask the user a yes/no question and returns the answer as a bool.
@param question: The question asked without trailing spaces.
- @type answers: basestring
+ @type question: basestring
@param default: The result if no answer was entered. It must be a bool or
'y' or 'n' and can be disabled by setting it to None.
@type default: basestring or bool
@@ -581,17 +585,16 @@
The user's input will be case-insensitive, so the hotkeys should be
distinctive case-insensitively.
- Parameters:
- * question - a unicode string that will be shown to the user. Don't add a
- space after the question mark, this method will do this
- for you.
- * answers - a list of strings that represent the options.
- * hotkeys - a list of one-letter strings, one for each answer.
- * default - an element of hotkeys, or None. The default choice that will
+ @param question: a string that will be shown to the user. Don't add a
+ space after the question mark/colon, this method will do this for you.
+ @type question: basestring
+ @param answers: a list of strings that represent the options.
+ @type answers: list of basestring
+ @param hotkeys: a list of one-letter strings, one for each answer.
+ @param default: an element of hotkeys, or None. The default choice that will
be returned when the user just presses Enter.
-
- Returns a one-letter string in lowercase.
-
+ @return: a one-letter string in lowercase.
+ @rtype: str
"""
# make sure logging system has been initialized
if not _handlers_initialized:
@@ -609,6 +612,7 @@
This is required because the -help option loads the module's docstring
and because the module name will be used for the filename of the log.
+ @rtype: unicode
"""
# get commandline arguments
called = pywikibot.argvu[0].strip()
@@ -986,14 +990,14 @@
and puts the page if needed.
Option used:
- * 'always'
+ * 'always'
Keyword args used:
- * 'async' - passed to page.save
- * 'comment' - passed to page.save
- * 'show_diff' - show changes between oldtext and newtext (enabled)
- * 'ignore_save_related_errors' - report and ignore (disabled)
- * 'ignore_server_errors' - report and ignore (disabled)
+ * 'async' - passed to page.save
+ * 'comment' - passed to page.save
+ * 'show_diff' - show changes between oldtext and newtext (enabled)
+ * 'ignore_save_related_errors' - report and ignore (disabled)
+ * 'ignore_server_errors' - report and ignore (disabled)
"""
if oldtext == newtext:
pywikibot.output(u'No changes were needed on %s'
diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py
index 92eeb5d..660e597 100644
--- a/pywikibot/comms/http.py
+++ b/pywikibot/comms/http.py
@@ -219,7 +219,7 @@
used for requests to non wiki pages.
@param site: The Site to connect to
- @type site: L{pywikibot.site.Site}
+ @type site: L{pywikibot.site.BaseSite}
@param uri: the URI to retrieve
@type uri: str
@return: The received data (a unicode string).
diff --git a/pywikibot/comms/threadedhttp.py b/pywikibot/comms/threadedhttp.py
index a34de00..32e55bd 100644
--- a/pywikibot/comms/threadedhttp.py
+++ b/pywikibot/comms/threadedhttp.py
@@ -140,13 +140,13 @@
"""
Constructor.
- @param cookiejar: (optional) CookieJar to use. A new one will be
+ @kwarg cookiejar: (optional) CookieJar to use. A new one will be
used when not supplied.
- @param connection_pool: (optional) Connection pool to use. A new one
+ @kwarg connection_pool: (optional) Connection pool to use. A new one
will be used when not supplied.
- @param max_redirects: (optional) The maximum number of redirects to
+ @kwarg max_redirects: (optional) The maximum number of redirects to
follow. 5 is default.
- @param timeout: (optional) Socket timeout in seconds. Default is
+ @kwarg timeout: (optional) Socket timeout in seconds. Default is
config.socket_timeout. Disable with None.
"""
diff --git a/pywikibot/config2.py b/pywikibot/config2.py
index 7316d9f..18ea59c 100644
--- a/pywikibot/config2.py
+++ b/pywikibot/config2.py
@@ -4,14 +4,14 @@
Provides two family class methods which can be used in
the user-config:
-- register_family_file
-- register_families_folder
+ - register_family_file
+ - register_families_folder
Sets module global base_dir and provides utility methods to
build paths relative to base_dir:
-- makepath
-- datafilepath
-- shortpath
+ - makepath
+ - datafilepath
+ - shortpath
"""
#
# (C) Rob W.W. Hooft, 2003
@@ -136,16 +136,16 @@
def get_base_dir(test_directory=None):
r"""Return the directory in which user-specific information is stored.
- This is determined in the following order -
- 1. If the script was called with a -dir: argument, use the directory
- provided in this argument
- 2. If the user has a PYWIKIBOT2_DIR environment variable, use the value
- of it
- 3. If user-config presents in current directory, use the current directory
- 4. Use (and if necessary create) a 'pywikibot' folder under
- 'Application Data' or 'AppData\Roaming' (Windows) or
- '.pywikibot' directory (Unix and similar) under the user's home
- directory.
+ This is determined in the following order:
+ 1. If the script was called with a -dir: argument, use the directory
+ provided in this argument
+ 2. If the user has a PYWIKIBOT2_DIR environment variable, use the value
+ of it
+ 3. If user-config presents in current directory, use the current directory
+ 4. Use (and if necessary create) a 'pywikibot' folder under
+ 'Application Data' or 'AppData\Roaming' (Windows) or
+ '.pywikibot' directory (Unix and similar) under the user's home
+ directory.
Set PYWIKIBOT2_NO_USER_CONFIG=1 to disable loading user-config.py
@@ -153,6 +153,7 @@
directory. Used to test whether placing a user config file in this
directory will cause it to be selected as the base directory.
@type test_directory: str or None
+ @rtype: unicode
"""
def exists(directory):
directory = os.path.abspath(directory)
@@ -708,12 +709,11 @@
def makepath(path):
"""Return a normalized absolute version of the path argument.
- - if the given path already exists in the filesystem
- the filesystem is not modified.
-
- - otherwise makepath creates directories along the given path
- using the dirname() of the path. You may append
- a '/' to the path if you want it to be a directory path.
+ - if the given path already exists in the filesystem
+ the filesystem is not modified.
+ - otherwise makepath creates directories along the given path
+ using the dirname() of the path. You may append
+ a '/' to the path if you want it to be a directory path.
from holger(a)trillke.net 2002/03/18
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index eb97667..6389e5c 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -203,22 +203,24 @@
>>> sorted(data[u'query'].keys()) # doctest: +IGNORE_UNICODE
['namespaces', 'userinfo']
- @param site: The Site to which the request will be submitted. If not
- supplied, uses the user's configured default Site.
- @param mime: If true, send in "multipart/form-data" format (default False)
- @param mime_params: A dictionary of parameter which should only be
- transferred via mime mode. If not None sets mime to True.
- @param max_retries: (optional) Maximum number of times to retry after
- errors, defaults to 25
- @param retry_wait: (optional) Minimum time to wait after an error,
- defaults to 5 seconds (doubles each retry until max of 120 is
- reached)
- @param format: (optional) Defaults to "json"
-
"""
def __init__(self, **kwargs):
- """Constructor."""
+ """
+ Constructor.
+
+ @kwarg site: The Site to which the request will be submitted. If not
+ supplied, uses the user's configured default Site.
+ @kwarg mime: If true, send in "multipart/form-data" format (default False)
+ @kwarg mime_params: A dictionary of parameter which should only be
+ transferred via mime mode. If not None sets mime to True.
+ @kwarg max_retries: (optional) Maximum number of times to retry after
+ errors, defaults to 25
+ @kwarg retry_wait: (optional) Minimum time to wait after an error,
+ defaults to 5 seconds (doubles each retry until max of 120 is
+ reached)
+ @kwarg format: (optional) Defaults to "json"
+ """
try:
self.site = kwargs.pop("site")
except KeyError:
@@ -1402,11 +1404,11 @@
@type page: Page
@param pagedict: the contents of a "page" element of a query response
@type pagedict: dict
- @param prop: the property names which resulted in pagedict. If a missing
+ @param props: the property names which resulted in pagedict. If a missing
value in pagedict can indicate both 'false' and 'not present' the
property which would make the value present must be in the props
parameter.
- @type prop: iterable of string
+ @type props: iterable of string
"""
if "pageid" in pagedict:
page._pageid = int(pagedict['pageid'])
diff --git a/pywikibot/data/wikidataquery.py b/pywikibot/data/wikidataquery.py
index 7a0626b..c3eaf35 100644
--- a/pywikibot/data/wikidataquery.py
+++ b/pywikibot/data/wikidataquery.py
@@ -56,8 +56,8 @@
Add to this QuerySet using the given joiner.
If the given joiner is not the same as we used before in
- this QuerySet, nest the current one in parens before joining
- - this makes the implicit grouping of the API explicit.
+ this QuerySet, nest the current one in parens before joining.
+ This makes the implicit grouping of the API explicit.
@return: a new query set representing the joining of this one and
the arguments
@@ -208,10 +208,10 @@
The resulting IDs may be used in query strings.
- @param item A single item. One of ItemPages, PropertyPages, int
- or anything that can be fed to int()
+ @param item: A single item. One of ItemPages, PropertyPages, int
+ or anything that can be fed to int()
- @return the int ID of the item
+ @return: the int ID of the item
"""
if isinstance(item, ItemPage) or isinstance(item, PropertyPage):
return item.getID(numeric=True)
@@ -307,9 +307,9 @@
"""
Constructor.
- @param item The root item
- @param forward List of forward properties, can be empty
- @param reverse List of reverse properties, can be empty
+ @param item: The root item
+ @param forward: List of forward properties, can be empty
+ @param reverse: List of reverse properties, can be empty
"""
# check sensible things coming in, as we lose info once we do
# type conversion
@@ -367,9 +367,9 @@
You have to give prop and one of begin or end. Note that times have
to be in UTC, timezones are not supported by the API
- @param prop the property
- @param begin WbTime object representign the beginning of the period
- @param end WbTime object representing the end of the period
+ @param prop: the property
+ @param begin: WbTime object representign the beginning of the period
+ @param end: WbTime object representing the end of the period
"""
queryType = "between"
@@ -474,7 +474,7 @@
"""
Get the query string for a given query or queryset.
- @return query string including labels and props
+ @return: string including labels and props
"""
qStr = "q=%s" % quote(str(q))
@@ -499,7 +499,7 @@
"""
Load the query result from the cache, if possible.
- Returns None if the data is not there or if it is too old.
+ @return: None if the data is not there or if it is too old.
"""
if self.cacheMaxAge <= 0:
return None
@@ -527,7 +527,7 @@
"""
Save data from a query to a cache file, if enabled.
- No return value.
+ @rtype: None
"""
if self.cacheMaxAge <= 0:
return
@@ -575,7 +575,7 @@
"""
Actually run a query over the API.
- @return Python dict of the interpreted JSON or None on failure
+ @return: dict of the interpreted JSON or None on failure
"""
fullQueryString = self.getQueryString(q, labels, props)
diff --git a/pywikibot/date.py b/pywikibot/date.py
index 94f1dc7..350bdf7 100644
--- a/pywikibot/date.py
+++ b/pywikibot/date.py
@@ -188,13 +188,16 @@
"""This function helps in simple list value matching.
!!!!! The index starts at 1, so 1st element has index 1, not 0 !!!!!
- Usually it will be used as a lambda call in a map:
- lambda v: slh(v, [u'January',u'February',...])
- Usage scenarios:
- formats['MonthName']['en'](1) => u'January'
- formats['MonthName']['en'](u'January') => 1
- formats['MonthName']['en'](u'anything else') => raise ValueError
+ Usually it will be used as a lambda call in a map::
+
+ lambda v: slh(v, [u'January',u'February',...])
+
+ Usage scenarios::
+
+ formats['MonthName']['en'](1) => u'January'
+ formats['MonthName']['en'](u'January') => 1
+ formats['MonthName']['en'](u'anything else') => raise ValueError
"""
if isinstance(value, basestring):
@@ -400,23 +403,26 @@
def dh(value, pattern, encf, decf, filter=None):
"""This function helps in year parsing.
- Usually it will be used as a lambda call in a map:
- lambda v: dh(v, u'pattern string', encodingFunc, decodingFunc)
+ Usually it will be used as a lambda call in a map::
- encodingFunc:
+ lambda v: dh(v, u'pattern string', encf, decf)
+
+ @param encf:
Converts from an integer parameter to another integer or a tuple of
integers. Depending on the pattern, each integer will be converted to a
proper string representation, and will be passed as a format argument
- to the pattern:
- pattern % encodingFunc(value)
- This function is a complement of decodingFunc.
+ to the pattern::
- decodingFunc:
+ pattern % encf(value)
+
+ This function is a complement of decf.
+
+ @param decf:
Converts a tuple/list of non-negative integers found in the original
value string
into a normalized value. The normalized value can be passed right back
into dh() to produce the original string. This function is a complement
- of encodingFunc. dh() interprets %d as a decimal and %s as a roman
+ of encf. dh() interprets %d as a decimal and %s as a roman
numeral number.
"""
diff --git a/pywikibot/diff.py b/pywikibot/diff.py
index e7bffe2..7773b7e 100644
--- a/pywikibot/diff.py
+++ b/pywikibot/diff.py
@@ -22,10 +22,6 @@
"""One change hunk between a and b.
- a and b: two sequences of lines.
- grouped_opcode: list of 5-tuples describing how to turn a into b.
- it has the same format as returned by difflib.get_opcodes().
-
Note: parts of this code are taken from by difflib.get_grouped_opcodes().
"""
@@ -35,6 +31,15 @@
PENDING = 0
def __init__(self, a, b, grouped_opcode):
+ """
+ Constructor.
+
+ @param a: sequence of lines
+ @param b: sequence of lines
+ @param grouped_opcode: list of 5-tuples describing how to turn a into b.
+ it has the same format as returned by difflib.get_opcodes().
+
+ """
self.a = a
self.b = b
self.group = grouped_opcode
@@ -203,7 +208,8 @@
def get_blocks(self):
"""Return list with blocks of indexes which compose a and, where applicable, b.
- Format of each block:
+ Format of each block::
+
[-1, (i1, i2), (-1, -1)] -> block a[i1:i2] does not change from a to b
then is there is no corresponding hunk.
[hunk index, (i1, i2), (j1, j2)] -> block a[i1:i2] becomes b[j1:j2]
diff --git a/pywikibot/editor.py b/pywikibot/editor.py
index 0ab7de1..fd00b12 100644
--- a/pywikibot/editor.py
+++ b/pywikibot/editor.py
@@ -77,15 +77,17 @@
"""
Call the editor and thus allows the user to change the text.
- Returns the modified text. Halts the thread's operation until the editor
- is closed.
+ Halts the thread's operation until the editor is closed.
- Returns None if the user didn't save the text file in his text editor.
-
- Parameters:
- * text - a Unicode string
- * jumpIndex - an integer: position at which to put the caret
- * highlight - a substring; each occurence will be highlighted
+ @param text: the text to be edited
+ @type text: unicode
+ @param jumpIndex: position at which to put the caret
+ @type jumpIndex: int
+ @param highlight: each occurence of this substring will be highlighted
+ @type highlight: unicode
+ @return: the modified text, or None if the user didn't save the text
+ file in his text editor
+ @rtype: unicode or None
"""
text = self.convertLinebreaks(text)
if config.editor:
diff --git a/pywikibot/exceptions.py b/pywikibot/exceptions.py
index 90b2e5c..298ef6c 100644
--- a/pywikibot/exceptions.py
+++ b/pywikibot/exceptions.py
@@ -24,8 +24,8 @@
- CircularRedirect: Page is a circular redirect
- SectionError: The section specified by # does not exist
-PageSaveRelatedError: page exceptions within the save operation on a Page.
- (alias: PageNotSaved)
+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
diff --git a/pywikibot/family.py b/pywikibot/family.py
index 645138a..9275f60 100644
--- a/pywikibot/family.py
+++ b/pywikibot/family.py
@@ -1030,10 +1030,10 @@
"""
Return a regex matching the path after the domain.
- It is using L{Family.path} and L{Family.nicepath} with code set to
- 'None'. If that returns a KeyError (L{Family.scriptpath} probably
+ It is using L{path} and L{nicepath} with code set to
+ 'None'. If that returns a KeyError (L{scriptpath} probably
using the C{langs} dictionary) it retries it with the key from
- L{Family.langs} if it only contains one entry and throws an Error
+ C{langs} if it only contains one entry and throws an Error
otherwise. In that case the Family instance should overwrite this
method or supply code independent methods.
diff --git a/pywikibot/i18n.py b/pywikibot/i18n.py
index 7e5b2db..1e2fda9 100644
--- a/pywikibot/i18n.py
+++ b/pywikibot/i18n.py
@@ -33,10 +33,6 @@
def _altlang(code):
"""Define fallback languages for particular languages.
- @param code The language code
- @type code string
- @return a list of strings as language codes
-
If no translation is available to a specified language, translate() will
try each of the specified fallback languages, in order, until it finds
one with a translation, with 'en' and '_default' as a last resort.
@@ -46,6 +42,10 @@
This code is used by other translating methods below.
+ @param code: The language code
+ @type code: string
+ @return: language codes
+ @rtype: list of str
"""
# Akan
if code in ['ak', 'tw']:
@@ -278,18 +278,6 @@
def translate(code, xdict, parameters=None, fallback=False):
"""Return the most appropriate translation from a translation dict.
- @param code The language code
- @type code string or Site object
- @param xdict dictionary with language codes as keys or extended dictionary
- with family names as keys containing language dictionaries or
- a single (unicode) string. May contain PLURAL tags as described
- in twntranslate
- @type xdict dict, string, unicode
- @param parameters For passing (plural) parameters
- @type parameters dict, string, unicode, int
- @param fallback Try an alternate language code
- @type fallback boolean
-
Given a language code and a dictionary, returns the dictionary's value for
key 'code' if this key exists; otherwise tries to return a value for an
alternative language that is most applicable to use on the wiki in
@@ -301,6 +289,18 @@
list.
For PLURAL support have a look at the twntranslate method
+
+ @param code: The language code
+ @type code: string or Site object
+ @param xdict: dictionary with language codes as keys or extended dictionary
+ with family names as keys containing language dictionaries or
+ a single (unicode) string. May contain PLURAL tags as
+ described in twntranslate
+ @type xdict: dict, string, unicode
+ @param parameters: For passing (plural) parameters
+ @type parameters: dict, string, unicode, int
+ @param fallback: Try an alternate language code
+ @type fallback: boolean
"""
family = pywikibot.config.family
@@ -405,32 +405,31 @@
def twntranslate(code, twtitle, parameters=None):
r"""Translate a message with plural support.
- @param code: The language code
- @param twtitle: The TranslateWiki string title, in <package>-<key> format
- @param parameters: For passing (plural) parameters.
-
Support is implemented like in MediaWiki extension. If the TranslateWiki
- message contains a plural tag inside which looks like
- {{PLURAL:<number>|<variant1>|<variant2>[|<variantn>]}}
+ message contains a plural tag inside which looks like::
+
+ {{PLURAL:<number>|<variant1>|<variant2>[|<variantn>]}}
+
it takes that variant calculated by the plural_rules depending on the number
value. Multiple plurals are allowed.
- Examples:
- If we had a test dictionary in test.py like
- msg = {
- 'en': {
- # number value as format sting is allowed
- 'test-plural': u'Bot: Changing %(num)s {{PLURAL:%(num)d|page|pages}}.',
- },
- 'nl': {
- # format sting inside PLURAL tag is allowed
- 'test-plural': u'Bot: Pas {{PLURAL:num|1 pagina|%(num)d pagina\'s}} aan.',
- },
- 'fr': {
- # additional sting inside or outside PLURAL tag is allowed
- 'test-plural': u'Robot: Changer %(descr)s {{PLURAL:num|une page|quelques pages}}.',
- },
- }
+ As an examples, if we had a test dictionary in test.py like::
+
+ msg = {
+ 'en': {
+ # number value as format sting is allowed
+ 'test-plural': u'Bot: Changing %(num)s {{PLURAL:%(num)d|page|pages}}.',
+ },
+ 'nl': {
+ # format sting inside PLURAL tag is allowed
+ 'test-plural': u'Bot: Pas {{PLURAL:num|1 pagina|%(num)d pagina\'s}} aan.',
+ },
+ 'fr': {
+ # additional sting inside or outside PLURAL tag is allowed
+ 'test-plural': u'Robot: Changer %(descr)s {{PLURAL:num|une page|quelques pages}}.',
+ },
+ }
+
>>> from pywikibot import i18n
>>> i18n.messages_package_name = 'tests.i18n'
>>> # use a number
@@ -452,6 +451,11 @@
The translations are retrieved from i18n.<package>, based on the callers
import table.
+
+ @param code: The language code
+ @param twtitle: The TranslateWiki string title, in <package>-<key> format
+ @param parameters: For passing (plural) parameters.
+
"""
# If a site is given instead of a code, use its language
if hasattr(code, 'code'):
diff --git a/pywikibot/logentries.py b/pywikibot/logentries.py
index cdfe41b..5a71ad9 100644
--- a/pywikibot/logentries.py
+++ b/pywikibot/logentries.py
@@ -103,9 +103,10 @@
"""
Return the blocked account or IP.
- * Returns the Page object of username or IP
- if this block action targets a username or IP.
- * Returns the blockid if this log reflects the removal of an autoblock
+ @return: the Page object of username or IP if this block action
+ targets a username or IP, or the blockid if this log reflects
+ the removal of an autoblock
+ @rtype: Page or int
"""
# TODO what for IP ranges ?
if self.isAutoblockRemoval:
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 20519f0..9301a49 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -281,7 +281,7 @@
return hash(unicode(self))
def autoFormat(self):
- """Return L{date.autoFormat} dictName and value, if any.
+ """Return L{date.getAutoFormat} dictName and value, if any.
Value can be a year, date, etc., and dictName is 'YearBC',
'Year_December', or another dictionary name. Please note that two
@@ -310,12 +310,12 @@
retrieved yet, or if force is True. This can raise the following
exceptions that should be caught by the calling code:
- @exception NoPage The page does not exist
- @exception IsRedirectPage The page is a redirect. The argument of the
- exception is the title of the page it
- redirects to.
- @exception SectionError The section does not exist on a page with
- a # link
+ @exception NoPage: The page does not exist
+ @exception IsRedirectPage: The page is a redirect. The argument of the
+ exception is the title of the page it
+ redirects to.
+ @exception SectionError: The section does not exist on a page with
+ a # link
@param force: reload all page attributes, including errors.
@param get_redirect: return the redirect text, do not follow the
@@ -637,7 +637,7 @@
Character count ignores language links and category links.
Can raise the same exceptions as get().
- @return bool
+ @rtype: bool
"""
txt = self.get()
txt = textlib.removeLanguageLinks(txt, site=self.site)
@@ -699,7 +699,7 @@
'Template:Disambig' is always assumed to be default, and will be
appended regardless of its existence.
- @return: bool
+ @rtype: bool
"""
if self.site.has_extension('Disambiguator'):
# If the Disambiguator extension is loaded, use it
@@ -823,7 +823,7 @@
total=None, content=False):
"""Return an iterator for pages that embed this page as a template.
- @param filterRedirects: if True, only iterate redirects; if False,
+ @param filter_redirects: if True, only iterate redirects; if False,
omit redirects; if None, do not filter
@param namespaces: only iterate pages in these namespaces
@param step: limit each API call to this number of pages
@@ -1563,19 +1563,21 @@
If no calls have been made since loadDeletedRevisions(), everything
will be restored.
- Simplest case:
+ Simplest case::
+
Page(...).undelete('This will restore all revisions')
- More complex:
+ More complex::
+
pg = Page(...)
- revs = pg.loadDeletedRevsions()
+ revs = pg.loadDeletedRevisions()
for rev in revs:
if ... #decide whether to undelete a revision
pg.markDeletedRevision(rev) #mark for undeletion
pg.undelete('This will restore only selected revisions.')
@param comment: The undeletion edit summary.
-
+ @type comment: basestring
"""
if comment is None:
pywikibot.output(u'Preparing to undelete %s.'
@@ -1663,8 +1665,10 @@
"""
Remove page from oldCat and add it to newCat.
- @param oldCat and newCat: should be Category objects.
- If newCat is None, the category will be removed.
+ @param oldCat: category to be removed
+ @type oldCat: Category
+ @param newCat: category to be added, if any
+ @type newCat: Category or None
@param comment: string to use as an edit summary
@@ -1676,9 +1680,10 @@
@param include: list of tags not to be disabled by default in relevant
textlib functions, where CategoryLinks can be searched.
- @type: list
+ @type include: list
@return: True if page was saved changed, otherwise False.
+ @rtype: bool
"""
# get list of Category objects the article is in and remove possible
@@ -1906,7 +1911,8 @@
def getFileVersionHistory(self):
"""Return the file's version history.
- @return: A list of dictionaries with the following keys:
+ @return: A list of dictionaries with the following keys::
+
[comment, sha1, url, timestamp, metadata,
height, width, mime, user, descriptionurl, size]
@@ -2058,7 +2064,7 @@
@param total: iterate no more than this number of pages in
total (at all levels)
@param namespaces: only yield pages in the specified namespaces
- @type namespace: int or list of ints
+ @type namespaces: int or list of ints
@param content: if True, retrieve the content of the current version
of each page (default False)
@param sortby: determines the order in which results are generated,
@@ -2636,9 +2642,9 @@
@type site: DataSite
@param title: normalized title of the page
@type title: unicode
- @param ns: namespace
+ @kwarg ns: namespace
@type ns: Namespace instance, or int
- @param entity_type: Wikibase entity type
+ @kwarg entity_type: Wikibase entity type
@type entity_type: str ('item' or 'property')
@raise TypeError: incorrect use of parameters
@@ -2992,10 +2998,10 @@
Edit an entity using Wikibase wbeditentity API.
This function is wrapped around by:
- *editLabels
- *editDescriptions
- *editAliases
- *ItemPage.setSitelinks
+ - editLabels
+ - editDescriptions
+ - editAliases
+ - ItemPage.setSitelinks
@param data: Data to be saved
@type data: dict (must be not None for python 2.6; bug 70707)
@@ -3137,13 +3143,14 @@
"""
Get the ItemPage for a Page that links to it.
- @exception NoPage There is no corresponding ItemPage for the page
@param page: Page to look for corresponding data item
@type page: pywikibot.Page
@param lazy_load: Do not raise NoPage if either page or corresponding
ItemPage does not exist.
@type lazy_load: bool
@return: ItemPage
+
+ @exception NoPage: There is no corresponding ItemPage for the page
"""
if not page.site.has_transcluded_data:
raise pywikibot.WikiBaseError(u'%s has no transcluded data'
@@ -3463,7 +3470,8 @@
"""
A Wikibase entity in the property namespace.
- Should be created as:
+ Should be created as::
+
PropertyPage(DataSite, 'P21')
"""
@@ -3674,8 +3682,8 @@
@param value: The new target value.
@type value: object
- Raises ValueError if value is not of the type
- required for the Claim type.
+ @exception ValueError: if value is not of the type
+ required for the Claim type.
"""
value_class = self.types[self.type]
if not isinstance(value, value_class):
@@ -3690,7 +3698,7 @@
@param value: The new target value.
@type value: object
@param snaktype: The new snak type.
- @type value: str ('value', 'somevalue', or 'novalue')
+ @type snaktype: str ('value', 'somevalue', or 'novalue')
"""
if value:
self.setTarget(value)
@@ -4298,7 +4306,7 @@
def __unicode__(self):
"""Return a unicode string representation.
- @return unicode
+ @return: unicode
"""
return self.astext()
@@ -4506,8 +4514,8 @@
Uses the first encoding that doesn't cause an error.
- @param data: URL-encoded character data to convert
- @type data: str
+ @param title: URL-encoded character data to convert
+ @type title: str
@param encodings: Encodings to attempt to use during conversion.
@type encodings: str, list or Site
@return: unicode
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py
index 940c630..a1eff4d 100644
--- a/pywikibot/pagegenerators.py
+++ b/pywikibot/pagegenerators.py
@@ -1098,12 +1098,12 @@
The provided generator must support parameter 'start', 'end',
'reverse', and 'total' such as site.recentchanges(), site.logevents().
- For example:
+ To fetch revisions in recentchanges in live time::
- To fetch revisions in recentchanges in live time, call
gen = RepeatingGenerator(site.recentchanges, lambda x: x['revid'])
- To fetch new pages in live time, call
+ To fetch new pages in live time::
+
gen = RepeatingGenerator(site.newpages, lambda x: x[0])
Note that other parameters not listed below will be passed
@@ -1696,7 +1696,8 @@
Yield a list of pages based on a MySQL query.
Each query should provide the page namespace and page title. An example
- query that yields all ns0 pages might look like:
+ query that yields all ns0 pages might look like::
+
SELECT
page_namespace,
page_title,
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 9cadefe..62a6e05 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -118,10 +118,11 @@
""" Namespace site data object.
This is backwards compatible with the structure of entries
- in site._namespaces which were a list of
- [customised namespace,
- canonical namespace name?,
- namespace alias*]
+ in site._namespaces which were a list of::
+
+ [customised namespace,
+ canonical namespace name?,
+ namespace alias*]
If the canonical_name is not provided for a namespace between -2
and 15, the MediaWiki 1.14+ built-in names are used.
@@ -944,7 +945,8 @@
def need_version(version):
""" Decorator to require a certain MediaWiki version number.
- @param number: the mw version number required
+ @param version: the mw version number required
+ @type version: str
@return: a decorator to make sure the requirement is satisfied when
the decorated function is called.
"""
@@ -993,10 +995,10 @@
Return the default value for different properties.
If the property is 'restrictions' it returns a dictionary with:
- 'cascadinglevels': 'sysop'
- 'semiprotectedlevels': 'autoconfirmed'
- 'levels': '' (everybody), 'autoconfirmed', 'sysop'
- 'types': 'create', 'edit', 'move', 'upload'
+ - 'cascadinglevels': 'sysop'
+ - 'semiprotectedlevels': 'autoconfirmed'
+ - 'levels': '' (everybody), 'autoconfirmed', 'sysop'
+ - 'types': 'create', 'edit', 'move', 'upload'
Otherwise it returns L{pywikibot.tools.EMPTY_DEFAULT}.
@param key: The property name
@@ -1943,7 +1945,7 @@
time. It requests to expand the text '{{CURRENTTIMESTAMP}}' for older
wikis.
- @return the current server time
+ @return: the current server time
@rtype: L{Timestamp}
"""
if LV(self.version()) >= LV("1.16"):
@@ -2451,12 +2453,12 @@
Most of them were merged into the 'csrf' token. If the token type in
the parameter is not known it will default to the 'csrf' token.
The other token types available are:
- - deleteglobalaccount
- - patrol
- - rollback
- - setglobalaccountstatus
- - userrights
- - watch
+ - deleteglobalaccount
+ - patrol
+ - rollback
+ - setglobalaccountstatus
+ - userrights
+ - watch
@param types: the types of token (e.g., "edit", "move", "delete");
see API documentation for full list of types
@@ -3714,7 +3716,7 @@
* unwatch: remove the page from the watchlist
* preferences: use the preference settings (Default)
* nochange: don't change the watchlist
- @param botflag: if True, mark edit with bot flag
+ @param bot: if True, mark edit with bot flag
@return: True if edit succeeded, False if it failed
"""
@@ -4060,7 +4062,7 @@
"""
Return the protection types available on this site.
- @return protection types available
+ @return: protection types available
@rtype: set of unicode instances
@see: L{Siteinfo._get_default()}
"""
@@ -4070,7 +4072,7 @@
"""
Return the protection levels available on this site.
- @return protection types available
+ @return: protection types available
@rtype: set of unicode instances
@see: L{Siteinfo._get_default()}
"""
@@ -4136,9 +4138,6 @@
"notpatrollable": "The revision %(revid)s can't be patrolled as it's too old."
}
- # test it with:
- # python -m unittest tests.site_tests.SiteUserTestCase.testPatrol
-
def patrol(self, rcid=None, revid=None, revision=None):
"""Return a generator of patrolled pages.
@@ -4158,7 +4157,8 @@
of pages to be patrolled.
@type revision: iterable/iterator which returns a Revision object; it
also supports a single Revision.
- @yield: dict with 'rcid', 'ns' and 'title' of the patrolled page.
+ @rtype: iterator of dict with 'rcid', 'ns' and 'title'
+ of the patrolled page.
"""
# If patrol is not enabled, attr will be set the first time a
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index daa4a13..cd23724 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -89,18 +89,17 @@
regex matching. If allowoverlap is true, overlapping occurrences are all
replaced (watch out when using this, it might lead to infinite loops!).
- Parameters:
- text - a unicode string
- old - a compiled or uncompiled regular expression
- new - a unicode string (which can contain regular
- expression references), or a function which takes
- a match object as parameter. See parameter repl of
- re.sub().
- exceptions - a list of strings which signal what to leave out,
- e.g. ['math', 'table', 'template']
- caseInsensitive - a boolean
- marker - a string that will be added to the last replacement;
- if nothing is changed, it is added at the end
+ @type text: unicode
+ @param old: a compiled or uncompiled regular expression
+ @param new: a unicode string (which can contain regular
+ expression references), or a function which takes
+ a match object as parameter. See parameter repl of
+ re.sub().
+ @param exceptions: a list of strings which signal what to leave out,
+ e.g. ['math', 'table', 'template']
+ @type caseInsensitive: bool
+ @param marker: a string that will be added to the last replacement;
+ if nothing is changed, it is added at the end
"""
if site is None:
@@ -687,7 +686,7 @@
@param include: list of tags which should not be removed by
removeDisabledParts() and where CategoryLinks can be searched.
- @type: list
+ @type include: list
@return: all category links found
@rtype: list of Category objects
@@ -1170,16 +1169,18 @@
"""
Determine whether the page text contains the given section title.
+ It does not care whether a section string may contain spaces or
+ underlines. Both will match.
+
+ 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.
+
@param pagetext: The wikitext of a page
- @type text: unicode or string
+ @type pagetext: unicode or string
@param section: a section of a page including wikitext markups
@type section: unicode or string
- Note: It does not care whether a section string may contain spaces or
- underlines. Both will match.
- 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))
diff --git a/pywikibot/tools.py b/pywikibot/tools.py
index 39f31ca..26d43bd 100644
--- a/pywikibot/tools.py
+++ b/pywikibot/tools.py
@@ -445,7 +445,7 @@
def deprecated(*args, **kwargs):
"""Decorator to output a deprecation warning.
- @param instead: if provided, will be used to specify the replacement
+ @kwarg instead: if provided, will be used to specify the replacement
@type instead: string
"""
def decorator(obj):
diff --git a/pywikibot/userinterfaces/gui.py b/pywikibot/userinterfaces/gui.py
index d29ac00..85bda15 100644
--- a/pywikibot/userinterfaces/gui.py
+++ b/pywikibot/userinterfaces/gui.py
@@ -332,10 +332,15 @@
"""
Provide user with editor to modify text.
- Parameters:
- * text - a Unicode string
- * jumpIndex - an integer: position at which to put the caret
- * highlight - a substring; each occurence will be highlighted
+ @param text: the text to be edited
+ @type text: unicode
+ @param jumpIndex: position at which to put the caret
+ @type jumpIndex: int
+ @param highlight: each occurence of this substring will be highlighted
+ @type highlight: unicode
+ @return: the modified text, or None if the user didn't save the text
+ file in his text editor
+ @rtype: unicode or None
"""
self.text = None
# put given text into our textarea
diff --git a/pywikibot/userinterfaces/terminal_interface_base.py b/pywikibot/userinterfaces/terminal_interface_base.py
index e08c50b..5f37e69 100755
--- a/pywikibot/userinterfaces/terminal_interface_base.py
+++ b/pywikibot/userinterfaces/terminal_interface_base.py
@@ -310,11 +310,15 @@
Uses a Tkinter edit box because we don't have a console editor
- Parameters:
- * text - a Unicode string
- * jumpIndex - an integer: position at which to put the caret
- * highlight - a substring; each occurrence will be highlighted
-
+ @param text: the text to be edited
+ @type text: unicode
+ @param jumpIndex: position at which to put the caret
+ @type jumpIndex: int
+ @param highlight: each occurence of this substring will be highlighted
+ @type highlight: unicode
+ @return: the modified text, or None if the user didn't save the text
+ file in his text editor
+ @rtype: unicode or None
"""
try:
import gui
diff --git a/pywikibot/weblib.py b/pywikibot/weblib.py
index b608e6d..f682fec 100644
--- a/pywikibot/weblib.py
+++ b/pywikibot/weblib.py
@@ -19,13 +19,13 @@
def getInternetArchiveURL(url, timestamp=None):
"""Return archived URL by Internet Archive.
- Parameters:
- url - url to search an archived version for
- timestamp - requested archive date. The version closest to that moment
- is returned. Format: YYYYMMDDhhmmss or part thereof.
-
See [[:mw:Archived Pages]] and https://archive.org/help/wayback_api.php
for more details.
+
+ @param url: url to search an archived version for
+ @param timestamp: requested archive date. The version closest to that
+ moment is returned. Format: YYYYMMDDhhmmss or part thereof.
+
"""
import json
uri = u'https://archive.org/wayback/available?'
@@ -47,13 +47,13 @@
def getWebCitationURL(url, timestamp=None):
"""Return archived URL by Web Citation.
- Parameters:
- url - url to search an archived version for
- timestamp - requested archive date. The version closest to that moment
- is returned. Format: YYYYMMDDhhmmss or part thereof.
-
See http://www.webcitation.org/doc/WebCiteBestPracticesGuide.pdf
for more details
+
+ @param url: url to search an archived version for
+ @param timestamp: requested archive date. The version closest to that
+ moment is returned. Format: YYYYMMDDhhmmss or part thereof.
+
"""
import xml.etree.ElementTree as ET
uri = u'http://www.webcitation.org/query?'
--
To view, visit https://gerrit.wikimedia.org/r/169985
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I368c3588e022900c494008f98e33df4fc876feed
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(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: Siebrand <siebrand(a)kitano.nl>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: [bugfix] Do not raise exception for api warnings
......................................................................
[bugfix] Do not raise exception for api warnings
API warnings in logpages method lead to a blocker and all related
scripts failed. Now warning will be printed using the same code
snippet as in core and the script is kept alive.
bugfix for bug 72749
Change-Id: Id48be5ef525d7b05d4cd58f24b839375e380c99e
---
M wikipedia.py
1 file changed, 21 insertions(+), 1 deletion(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/wikipedia.py b/wikipedia.py
index b57f01c..248431b 100644
--- a/wikipedia.py
+++ b/wikipedia.py
@@ -7897,9 +7897,29 @@
output('%(info)s' % result.get('error'))
raise BadTitle
# FIXME: Throw proper exceptions instead of "Error"
- if 'error' in result or 'warnings' in result:
+ if 'error' in result:
output('%s' % result)
raise Error
+
+ # _handle_warnings from core
+ for mod, warning in result['warnings'].items():
+ if mod == 'info':
+ continue
+ if '*' in warning:
+ text = warning['*']
+ elif 'html' in warning:
+ # Bugzilla 49978
+ text = warning['html']['*']
+ else:
+ pywikibot.warning(
+ u'API warning ({0})of unknown format: {1}'.
+ format(mod, warning))
+ continue
+ # multiple warnings are in text separated by a newline
+ for single_warning in text.splitlines():
+ pywikibot.warning(u"API warning (%s): %s"
+ % (mod, single_warning))
+
for c in result['query']['logevents']:
if (not namespace or c['ns'] in namespace) and \
'actionhidden' not in c.keys():
--
To view, visit https://gerrit.wikimedia.org/r/170075
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Id48be5ef525d7b05d4cd58f24b839375e380c99e
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/compat
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: [IMPROV] Use input_choice or input_yn if possible
......................................................................
[IMPROV] Use input_choice or input_yn if possible
Change-Id: I17fb04b9467acecffa98856668f4a92b81978509
---
M scripts/disambredir.py
M scripts/featured.py
2 files changed, 20 insertions(+), 21 deletions(-)
Approvals:
John Vandenberg: Looks good to me, but someone else must approve
Mpaa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/disambredir.py b/scripts/disambredir.py
index 9e30414..4f3cdcf 100644
--- a/scripts/disambredir.py
+++ b/scripts/disambredir.py
@@ -73,17 +73,15 @@
pywikibot.output(text[max(0, m.start() - context): m.start()] +
'\03{lightred}' + text[m.start(): m.end()] +
'\03{default}' + text[m.end(): m.end() + context])
- while True:
- choice = pywikibot.input(
- u"Option (N=do not change, y=change link to \03{lightpurple}%s\03{default}, r=change and replace text, u=unlink)"
- % targetPage.title())
- try:
- choice = choice[0]
- except:
- choice = 'N'
- if choice in 'nNyYrRuU':
- break
- if choice in "nN":
+ choice = pywikibot.input_choice(
+ 'What should be done with the link?',
+ (('Do not change', 'n'),
+ ('Change link to \03{lightpurple}%s\03{default}'
+ % targetPage.title(), 'y'),
+ ('Change and replace text', 'r'), ('Unlink', 'u')),
+ default='n', automatic_quit=False)
+
+ if choice == 'n':
continue
# The link looks like this:
@@ -101,20 +99,19 @@
if trailing_chars:
link_text += trailing_chars
- if choice in "uU":
+ if choice == 'u':
# unlink - we remove the section if there's any
text = text[:m.start()] + link_text + text[m.end():]
continue
- replaceit = choice in "rR"
if link_text[0].isupper():
new_page_title = targetPage.title()
else:
new_page_title = (targetPage.title()[0].lower() +
targetPage.title()[1:])
- if replaceit and trailing_chars:
+ if choice == 'r' and trailing_chars:
newlink = "[[%s%s]]%s" % (new_page_title, section, trailing_chars)
- elif replaceit or (new_page_title == link_text and not section):
+ elif choice == 'r' or (new_page_title == link_text and not section):
newlink = "[[%s]]" % new_page_title
# check if we can create a link with trailing characters instead of a
# pipelink
diff --git a/scripts/featured.py b/scripts/featured.py
index 270619c..6de45d6 100644
--- a/scripts/featured.py
+++ b/scripts/featured.py
@@ -559,9 +559,10 @@
else:
# insert just before interwiki
if (not interactive or
- pywikibot.input(
- u'Connecting %s -> %s. Proceed? [Y/N]'
- % (source.title(), dest.title())) in ['Y', 'y']):
+ pywikibot.input_yn(
+ u'Connecting %s -> %s. Proceed?'
+ % (source.title(), dest.title()),
+ default=False, automatic_quit=False)):
if self.getOption('side'):
# Placing {{Link FA|xx}} right next to
# corresponding interwiki
@@ -581,9 +582,10 @@
if m2:
if (changed or # Don't force the user to say "Y" twice
not interactive or
- pywikibot.input(
- u'Connecting %s -> %s. Proceed? [Y/N]'
- % (source.title(), dest.title())) in ['Y', 'y']):
+ pywikibot.input_yn(
+ u'Connecting %s -> %s. Proceed?'
+ % (source.title(), dest.title()),
+ default=False, automatic_quit=False)):
text = re.sub(re_Link_remove, '', text)
changed = True
elif task == 'former':
--
To view, visit https://gerrit.wikimedia.org/r/169329
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I17fb04b9467acecffa98856668f4a92b81978509
Gerrit-PatchSet: 2
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: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: PEP257 pywikibot/
......................................................................
PEP257 pywikibot/
Address all remaining pep257 issues, mostly in pywikibot.
Set the mandatory docstrings job to include all files.
Remove the ignore list from the non-mandatory docstrings job.
Change-Id: Ie3960ca8e15dde25bfba6d1afacc0b4d0362b357
---
M generate_family_file.py
M pywikibot/comms/__init__.py
M pywikibot/comms/threadedhttp.py
M pywikibot/compat/__init__.py
M pywikibot/data/wikidataquery.py
M pywikibot/diff.py
M pywikibot/exceptions.py
M pywikibot/families/test_family.py
M pywikibot/logentries.py
M pywikibot/login.py
M pywikibot/throttle.py
M pywikibot/titletranslate.py
M pywikibot/userinterfaces/__init__.py
M pywikibot/userinterfaces/cgi_interface.py
M pywikibot/userinterfaces/gui.py
M pywikibot/userinterfaces/terminal_interface_base.py
M pywikibot/userinterfaces/terminal_interface_unix.py
M pywikibot/userinterfaces/terminal_interface_win32.py
M pywikibot/userinterfaces/win32_unicode.py
M pywikibot/xmlreader.py
M tox.ini
21 files changed, 204 insertions(+), 113 deletions(-)
Approvals:
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/generate_family_file.py b/generate_family_file.py
index f98de19..1850339 100644
--- a/generate_family_file.py
+++ b/generate_family_file.py
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
"""
This script generates a family file from a given URL.
-Hackish, etc. Regexps, yes. Sorry, jwz.
+Hackish, etc. Regexps, yes. Sorry, jwz.
"""
from __future__ import (absolute_import, division,
print_function, unicode_literals)
@@ -54,6 +54,9 @@
class WikiHTMLPageParser(HTMLParser):
+
+ """Wiki HTML page parser."""
+
def __init__(self, *args, **kwargs):
HTMLParser.__init__(self, *args, **kwargs)
self.generator = None
@@ -69,6 +72,9 @@
class FamilyFileGenerator(object):
+
+ """Family file creator."""
+
def __init__(self, url=None, name=None, dointerwiki=None):
if url is None:
url = raw_input("Please insert URL to wiki: ")
@@ -216,6 +222,9 @@
class Wiki(object):
+
+ """Minimal wiki site class."""
+
REwgEnableApi = re.compile(r'wgEnableAPI ?= ?true')
REwgServer = re.compile(r'wgServer ?= ?"([^"]*)"')
REwgScriptPath = re.compile(r'wgScriptPath ?= ?"([^"]*)"')
diff --git a/pywikibot/comms/__init__.py b/pywikibot/comms/__init__.py
index df0dcca..3b768bb 100644
--- a/pywikibot/comms/__init__.py
+++ b/pywikibot/comms/__init__.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
+"""Communication layer."""
#
# (C) Pywikibot team, 2007-2008
#
diff --git a/pywikibot/comms/threadedhttp.py b/pywikibot/comms/threadedhttp.py
index 4279454..a34de00 100644
--- a/pywikibot/comms/threadedhttp.py
+++ b/pywikibot/comms/threadedhttp.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-""" Httplib2 threaded cookie layer
+""" Httplib2 threaded cookie layer.
This class extends httplib2, adding support for:
- Cookies, guarded for cross-site redirects
@@ -42,6 +42,7 @@
class ConnectionPool(object):
+
"""A thread-safe connection pool."""
def __init__(self, maxnum=5):
@@ -119,19 +120,22 @@
class LockableCookieJar(cookielib.LWPCookieJar):
+
"""CookieJar with integrated Lock object."""
+
def __init__(self, *args, **kwargs):
cookielib.LWPCookieJar.__init__(self, *args, **kwargs)
self.lock = threading.Lock()
class Http(httplib2.Http):
+
"""Subclass of httplib2.Http that stores cookies.
Overrides httplib2's internal redirect support to prevent cookies being
eaten by the wrong sites.
-
"""
+
def __init__(self, *args, **kwargs):
"""
Constructor.
@@ -297,6 +301,7 @@
class HttpRequest(object):
+
"""Object wrapper for HTTP requests that need to block origin thread.
Usage:
@@ -322,8 +327,8 @@
self.data will be either:
* a tuple of (dict, unicode) if the request was successful
* an exception
-
"""
+
def __init__(self, *args, **kwargs):
"""
Constructor.
@@ -337,7 +342,9 @@
class HttpProcessor(threading.Thread):
+
"""Thread object to spawn multiple HTTP connection threads."""
+
def __init__(self, queue, cookiejar, connection_pool):
"""
Constructor.
@@ -408,10 +415,12 @@
# ========================================================================
class DummyRequest(object):
+
"""Simulated urllib2.Request object for httplib2.
- Implements only what's necessary for cookielib.CookieJar to work.
+ Implements only what's necessary for cookielib.CookieJar to work.
"""
+
def __init__(self, url, headers=None):
self.url = url
self.headers = headers
@@ -453,10 +462,12 @@
class DummyResponse(object):
+
"""Simulated urllib2.Request object for httplib2.
- Implements only what's necessary for cookielib.CookieJar to work.
+ Implements only what's necessary for cookielib.CookieJar to work.
"""
+
def __init__(self, response):
self.response = response
@@ -465,10 +476,12 @@
class DummyMessage(object):
+
"""Simulated mimetools.Message object for httplib2.
- Implements only what's necessary for cookielib.CookieJar to work.
+ Implements only what's necessary for cookielib.CookieJar to work.
"""
+
def __init__(self, response):
self.response = response
diff --git a/pywikibot/compat/__init__.py b/pywikibot/compat/__init__.py
index e69de29..49d9f46 100644
--- a/pywikibot/compat/__init__.py
+++ b/pywikibot/compat/__init__.py
@@ -0,0 +1 @@
+"""Package to provide compatibility with compat scripts."""
diff --git a/pywikibot/data/wikidataquery.py b/pywikibot/data/wikidataquery.py
index 4e4f583..7a0626b 100644
--- a/pywikibot/data/wikidataquery.py
+++ b/pywikibot/data/wikidataquery.py
@@ -26,11 +26,14 @@
def listify(x):
"""
If given a non-list, encapsulate in a single-element list.
+
+ @rtype: list
"""
return x if isinstance(x, list) else [x]
class QuerySet():
+
"""
A QuerySet represents a set of queries or other query sets.
@@ -43,6 +46,8 @@
def __init__(self, q):
"""
Initialise a query set from a Query or another QuerySet.
+
+ @type q: Query or QuerySet
"""
self.qs = [q]
@@ -54,10 +59,9 @@
this QuerySet, nest the current one in parens before joining
- this makes the implicit grouping of the API explicit.
- @return a new query set representing the joining of this one and
+ @return: a new query set representing the joining of this one and
the arguments
"""
-
if len(self.qs) > 1 and joiner != self.joiner:
left = QuerySet(self)
else:
@@ -73,12 +77,16 @@
def AND(self, args):
"""
Add the given args (Queries or QuerySets) to the Query set as a logical conjuction (AND).
+
+ @type args: Query or QuerySet
"""
return self.addJoiner(args, "AND")
def OR(self, args):
"""
Add the given args (Queries or QuerySets) to the Query set as a logical disjunction (OR).
+
+ @type args: Query or QuerySet
"""
return self.addJoiner(args, "OR")
@@ -88,7 +96,6 @@
@rtype: str
"""
-
def bracketIfQuerySet(q):
if isinstance(q, QuerySet) and q.joiner != self.joiner:
return "(%s)" % q
@@ -121,12 +128,16 @@
def AND(self, ands):
"""
Produce a query set ANDing this query and all the given query/sets.
+
+ @type ands: Query or list of Query
"""
return QuerySet(self).addJoiner(ands, "AND")
def OR(self, ors):
"""
Produce a query set ORing this query and all the given query/sets.
+
+ @type ors: Query or list of Query
"""
return QuerySet(self).addJoiner(ors, "OR")
@@ -141,6 +152,8 @@
def formatList(self, l):
"""
Format and comma-join a list.
+
+ @type l: list
"""
return ",".join([self.formatItem(x) for x in l])
@@ -148,6 +161,8 @@
def isOrContainsOnlyTypes(items, types):
"""
Either this item is one of the given types, or it is a list of only those types.
+
+ @rtype: bool
"""
if isinstance(items, list):
for x in items:
@@ -221,6 +236,7 @@
class HasClaim(Query):
+
"""
This is a Query of the form "claim[prop:val]".
@@ -261,19 +277,20 @@
class NoClaim(HasClaim):
+
+ """Query of the form noclaim[PROPERTY]."""
+
queryType = "noclaim"
class StringClaim(HasClaim):
- """
- Query of the form string[PROPERTY:"STRING",...].
- """
+
+ """Query of the form string[PROPERTY:"STRING",...]."""
+
queryType = "string"
def formatItem(self, x):
- """
- Strings need quote-wrapping.
- """
+ """Add quotes around string."""
return '"%s"' % x
def validate(self):
@@ -281,9 +298,9 @@
class Tree(Query):
- """
- Query of the form tree[ITEM,...][PROPERTY,...]<PROPERTY,...>.
- """
+
+ """Query of the form tree[ITEM,...][PROPERTY,...]<PROPERTY,...>."""
+
queryType = "tree"
def __init__(self, item, forward=[], reverse=[]):
@@ -294,7 +311,6 @@
@param forward List of forward properties, can be empty
@param reverse List of reverse properties, can be empty
"""
-
# check sensible things coming in, as we lose info once we do
# type conversion
if not self.isOrContainsOnlyTypes(item, [int, ItemPage]):
@@ -323,9 +339,9 @@
class Around(Query):
- """
- A query in the form around[PROPERTY,LATITUDE,LONGITUDE,RADIUS].
- """
+
+ """A query in the form around[PROPERTY,LATITUDE,LONGITUDE,RADIUS]."""
+
queryType = "around"
def __init__(self, prop, coord, rad):
@@ -344,6 +360,7 @@
class Between(Query):
+
"""
A query in the form between[PROP, BEGIN, END].
@@ -354,6 +371,7 @@
@param begin WbTime object representign the beginning of the period
@param end WbTime object representing the end of the period
"""
+
queryType = "between"
def __init__(self, prop, begin=None, end=None):
@@ -375,6 +393,7 @@
class Link(Query):
+
"""
A query in the form link[LINK,...], which also includes nolink.
@@ -396,14 +415,19 @@
class NoLink(Link):
+
+ """A query in the form nolink[..]."""
+
queryType = "nolink"
def fromClaim(claim):
"""
Construct from a pywikibot.page Claim object.
- """
+ @type claim: L{pywikibot.page.Claim}
+ @rtype: L{Query}
+ """
if not isinstance(claim, Claim):
raise TypeError("claim must be a page.Claim")
@@ -417,6 +441,7 @@
class WikidataQuery():
+
"""
An interface to the WikidataQuery API.
@@ -464,6 +489,8 @@
def getCacheFilename(self, queryStr):
"""
Encode a query into a unique and universally safe format.
+
+ @rtype: unicode
"""
encQuery = hashlib.sha1(queryStr.encode('utf8')).hexdigest() + ".wdq_cache"
return os.path.join(self.cacheDir, encQuery)
@@ -474,7 +501,6 @@
Returns None if the data is not there or if it is too old.
"""
-
if self.cacheMaxAge <= 0:
return None
@@ -503,7 +529,6 @@
No return value.
"""
-
if self.cacheMaxAge <= 0:
return
@@ -527,6 +552,8 @@
def getDataFromHost(self, queryStr):
"""
Go and fetch a query from the host's API.
+
+ @rtype: dict
"""
url = self.getUrl(queryStr)
@@ -550,7 +577,6 @@
@return Python dict of the interpreted JSON or None on failure
"""
-
fullQueryString = self.getQueryString(q, labels, props)
# try to get cached data first
diff --git a/pywikibot/diff.py b/pywikibot/diff.py
index e118770..e7bffe2 100644
--- a/pywikibot/diff.py
+++ b/pywikibot/diff.py
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
-"""
-User-interface related functions
-"""
+"""Diff module."""
#
# (C) Pywikibot team, 2014
#
@@ -21,6 +19,7 @@
class Hunk(object):
+
"""One change hunk between a and b.
a and b: two sequences of lines.
@@ -61,14 +60,12 @@
def get_header(self):
"""Provide header of unified diff."""
-
a_rng = difflib._format_range_unified(*self.a_rng)
b_rng = difflib._format_range_unified(*self.b_rng)
return '@@ -{} +{} @@{}'.format(a_rng, b_rng, '\n')
def create_diff(self):
"""Generator of diff text for this hunk, without formatting."""
-
# make sure each line ends with '\n' to prevent
# behaviour like http://bugs.python.org/issue2142
def check_line(l):
@@ -94,7 +91,6 @@
def format_diff(self):
"""Color diff lines."""
-
diff = iter(self.diff)
l1, l2 = '', next(diff)
@@ -123,7 +119,6 @@
line_ref: string.
"""
-
color = line[0]
if line_ref is None:
@@ -167,23 +162,25 @@
class PatchManager(object):
+
"""Apply patches to text_a to obtain a new text.
If all hunks are approved, text_b will be obtained.
- letter by letter.
-
"""
def __init__(self, text_a, text_b, n=0, by_letter=False):
"""Constructor.
- text_a: string
- text_b: string
- n: int, line of context as defined in difflib.get_grouped_opcodes().
- by_letter: if text_a and text_b are single lines, comparison can be done
-
+ @param text_a: base text
+ @type text_a: basestring
+ @param text_b: target text
+ @type text_b: basestring
+ @param n: line of context as defined in difflib.get_grouped_opcodes().
+ @type n: int
+ @param by_letter: if text_a and text_b are single lines, comparison can be done
+ letter by letter.
+ @type by_letter: bool
"""
-
if '\n' in text_a or '\n' in text_b:
self.a = text_a.splitlines(1)
self.b = text_b.splitlines(1)
@@ -210,9 +207,7 @@
[-1, (i1, i2), (-1, -1)] -> block a[i1:i2] does not change from a to b
then is there is no corresponding hunk.
[hunk index, (i1, i2), (j1, j2)] -> block a[i1:i2] becomes b[j1:j2]
-
"""
-
blocks = []
i2 = 0
for hunk_idx, group in enumerate(self.groups):
@@ -240,8 +235,7 @@
pywikibot.output(hunk.header + hunk.diff_text)
def review_hunks(self):
- "Review hunks."
-
+ """Review hunks."""
help_msg = ['y -> accept this hunk',
'n -> do not accept this hunk',
's -> do not accept this hunk and stop reviewing',
@@ -292,7 +286,6 @@
def apply(self):
"""Apply changes. If there are undecided changes, ask to review."""
-
if any(h.reviewed == h.PENDING for h in self.hunks):
pywikibot.output("There are unreviewed hunks.\n"
"Please review them before proceeding.\n")
@@ -325,7 +318,6 @@
by_letter: if text_a and text_b are single lines, comparison can be done
"""
-
patch = PatchManager(oldtext, newtext, n=n, by_letter=by_letter)
pywikibot.output('\03{{lightpurple}}\n{:*^50}\03{{default}}\n'.format(' ALL CHANGES '))
diff --git a/pywikibot/exceptions.py b/pywikibot/exceptions.py
index 95d3111..90b2e5c 100644
--- a/pywikibot/exceptions.py
+++ b/pywikibot/exceptions.py
@@ -56,7 +56,7 @@
from pywikibot.tools import UnicodeMixin
-class Error(UnicodeMixin, Exception):
+class Error(UnicodeMixin, Exception): # noqa
"""Pywikibot error"""
@@ -108,7 +108,7 @@
return self.page
-class PageSaveRelatedError(PageRelatedError):
+class PageSaveRelatedError(PageRelatedError): # noqa
"""Saving the page has failed"""
@@ -145,12 +145,12 @@
class NoUsername(Error):
- """Username is not in user-config.py"""
+ """Username is not in user-config.py."""
pass
-class NoPage(PageRelatedError):
+class NoPage(PageRelatedError): # noqa
"""Page does not exist"""
@@ -159,7 +159,7 @@
pass
-class SiteDefinitionError(Error):
+class SiteDefinitionError(Error): # noqa
"""Site does not exist"""
@@ -172,21 +172,21 @@
NoSuchSite = SiteDefinitionError
-class UnknownSite(SiteDefinitionError):
+class UnknownSite(SiteDefinitionError): # noqa
"""Site does not exist in Family"""
pass
-class UnknownFamily(SiteDefinitionError):
+class UnknownFamily(SiteDefinitionError): # noqa
"""Family is not registered"""
pass
-class IsRedirectPage(PageRelatedError):
+class IsRedirectPage(PageRelatedError): # noqa
"""Page is a redirect page"""
@@ -195,7 +195,7 @@
pass
-class IsNotRedirectPage(PageRelatedError):
+class IsNotRedirectPage(PageRelatedError): # noqa
"""Page is not a redirect page"""
@@ -206,7 +206,7 @@
class CircularRedirect(PageRelatedError):
- """Page is a circular redirect
+ """Page is a circular redirect.
Exception argument is the redirect target; this may be the same title
as this page or a different title (in which case the target page directly
@@ -217,14 +217,14 @@
message = u"Page %s is a circular redirect."
-class InvalidTitle(Error):
+class InvalidTitle(Error): # noqa
"""Invalid page title"""
pass
-class LockedPage(PageSaveRelatedError):
+class LockedPage(PageSaveRelatedError): # noqa
"""Page is locked"""
@@ -233,7 +233,7 @@
pass
-class LockedNoPage(LockedPage):
+class LockedNoPage(LockedPage): # noqa
"""Title is locked against creation"""
@@ -242,7 +242,7 @@
pass
-class CascadeLockedPage(LockedPage):
+class CascadeLockedPage(LockedPage): # noqa
"""Page is locked due to cascading protection"""
@@ -251,7 +251,7 @@
pass
-class SectionError(Error):
+class SectionError(Error): # noqa
"""The section specified by # does not exist"""
@@ -270,7 +270,7 @@
pass
-class EditConflict(PageSaveRelatedError):
+class EditConflict(PageSaveRelatedError): # noqa
"""There has been an edit conflict while uploading the page"""
@@ -279,7 +279,7 @@
pass
-class PageDeletedConflict(EditConflict):
+class PageDeletedConflict(EditConflict): # noqa
"""Page was deleted since being retrieved"""
@@ -288,7 +288,7 @@
pass
-class PageCreatedConflict(EditConflict):
+class PageCreatedConflict(EditConflict): # noqa
"""Page was created by another user"""
@@ -317,7 +317,7 @@
super(SpamfilterError, self).__init__(page)
-class ServerError(Error):
+class ServerError(Error): # noqa
"""Got unexpected server response"""
@@ -331,7 +331,7 @@
pass
-class Server504Error(Error):
+class Server504Error(Error): # noqa
"""Server timed out with HTTP 504 code"""
@@ -349,14 +349,14 @@
pass
-class UserBlocked(Error):
+class UserBlocked(Error): # noqa
"""Your username or IP has been blocked"""
pass
-class PageNotFound(Error):
+class PageNotFound(Error): # noqa
"""Page not found in list"""
@@ -383,23 +383,29 @@
class UserActionRefuse(Error):
+
+ """User action was refused."""
+
pass
class WikiBaseError(Error):
+
+ """Wikibase related error."""
+
pass
class CoordinateGlobeUnknownException(WikiBaseError, NotImplementedError):
- """ This globe is not implemented yet in either WikiBase or pywikibot """
+ """This globe is not implemented yet in either WikiBase or pywikibot."""
pass
class EntityTypeUnknownException(WikiBaseError):
- """The requested entity type is not recognised on this site"""
+ """The requested entity type is not recognised on this site."""
pass
diff --git a/pywikibot/families/test_family.py b/pywikibot/families/test_family.py
index c2cc459..8d72b7c 100644
--- a/pywikibot/families/test_family.py
+++ b/pywikibot/families/test_family.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-
+"""Family module for test.wikipedia.org."""
__version__ = '$Id$'
from pywikibot import family
@@ -7,6 +7,9 @@
# The test wikipedia family
class Family(family.WikimediaFamily):
+
+ """Family class for test.wikipedia.org."""
+
def __init__(self):
super(Family, self).__init__()
self.name = 'test'
diff --git a/pywikibot/logentries.py b/pywikibot/logentries.py
index dfcb883..cdfe41b 100644
--- a/pywikibot/logentries.py
+++ b/pywikibot/logentries.py
@@ -83,6 +83,9 @@
class BlockEntry(LogEntry):
+
+ """Block log entry."""
+
_expectedType = 'block'
def __init__(self, apidata):
@@ -162,22 +165,37 @@
class ProtectEntry(LogEntry):
+
+ """Protection log entry."""
+
_expectedType = 'protect'
class RightsEntry(LogEntry):
+
+ """Rights log entry."""
+
_expectedType = 'rights'
class DeleteEntry(LogEntry):
+
+ """Deletion log entry."""
+
_expectedType = 'delete'
class UploadEntry(LogEntry):
+
+ """Upload log entry."""
+
_expectedType = 'upload'
class MoveEntry(LogEntry):
+
+ """Move log entry."""
+
_expectedType = 'move'
def new_ns(self):
@@ -200,14 +218,23 @@
class ImportEntry(LogEntry):
+
+ """Import log entry."""
+
_expectedType = 'import'
class PatrolEntry(LogEntry):
+
+ """Patrol log entry."""
+
_expectedType = 'patrol'
class NewUsersEntry(LogEntry):
+
+ """New user log entry."""
+
_expectedType = 'newusers'
# TODO entries for merge,suppress,makebot,gblblock,renameuser,globalauth,gblrights ?
diff --git a/pywikibot/login.py b/pywikibot/login.py
index 13eef79..ee05bd1 100644
--- a/pywikibot/login.py
+++ b/pywikibot/login.py
@@ -32,6 +32,9 @@
class LoginManager:
+
+ """Site login manager."""
+
@deprecated_args(username="user", verbose=None)
def __init__(self, password=None, sysop=False, site=None, user=None):
if site is not None:
diff --git a/pywikibot/throttle.py b/pywikibot/throttle.py
index 003b522..5cdc30d 100644
--- a/pywikibot/throttle.py
+++ b/pywikibot/throttle.py
@@ -27,7 +27,7 @@
class Throttle(object):
- """Control rate of access to wiki server
+ """Control rate of access to wiki server.
Calling this object blocks the calling thread until at least 'delay'
seconds have passed since the previous call.
@@ -36,6 +36,7 @@
rate of access.
"""
+
def __init__(self, site, mindelay=None, maxdelay=None, writedelay=None,
multiplydelay=True):
self.lock = threading.RLock()
diff --git a/pywikibot/titletranslate.py b/pywikibot/titletranslate.py
index 891f7c9..cf60b41 100644
--- a/pywikibot/titletranslate.py
+++ b/pywikibot/titletranslate.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
+"""Title translate module."""
#
# (C) Rob W.W. Hooft, 2003
# (C) Yuri Astrakhan, 2005
@@ -18,7 +19,7 @@
def translate(page, hints=None, auto=True, removebrackets=False, site=None,
family=None):
"""
- Goes through all entries in 'hints'. Returns a list of links to pages.
+ Return a list of links to pages on other sites based on hints.
Entries for single page titles list those pages. Page titles for entries
such as "all:" or "xyz:" or "20:" are first built from the page title of
@@ -122,9 +123,7 @@
def getPoisonedLinks(pl):
- """Return a list of known corrupted links that should be removed if seen
-
- """
+ """Return a list of known corrupted links that should be removed if seen."""
result = []
pywikibot.output(u'getting poisoned links for %s' % pl.title())
dictName, value = date.getAutoFormat(pl.site.code, pl.title())
diff --git a/pywikibot/userinterfaces/__init__.py b/pywikibot/userinterfaces/__init__.py
index 5041b19..120ec4e 100644
--- a/pywikibot/userinterfaces/__init__.py
+++ b/pywikibot/userinterfaces/__init__.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
+"""User interfaces."""
#
# (C) Pywikibot team, 2007
#
diff --git a/pywikibot/userinterfaces/cgi_interface.py b/pywikibot/userinterfaces/cgi_interface.py
index 21fd9ff..79572f7 100644
--- a/pywikibot/userinterfaces/cgi_interface.py
+++ b/pywikibot/userinterfaces/cgi_interface.py
@@ -1,7 +1,11 @@
+"""CGI user interface."""
import sys
class UI:
+
+ """CGI user interface."""
+
def __init__(self):
pass
diff --git a/pywikibot/userinterfaces/gui.py b/pywikibot/userinterfaces/gui.py
index f141d9b..d29ac00 100644
--- a/pywikibot/userinterfaces/gui.py
+++ b/pywikibot/userinterfaces/gui.py
@@ -32,12 +32,14 @@
class TextEditor(ScrolledText):
+
"""A text widget with some editing enhancements.
A lot of code here is copied or adapted from the idlelib/EditorWindow.py
file in the standard Python distribution.
"""
+
def __init__(self, master=None, **kwargs):
# get default settings from user's IDLE configuration
currentTheme = idleConf.CurrentTheme()
@@ -231,6 +233,8 @@
class EditBoxWindow(Tkinter.Frame):
+ """Edit box window."""
+
def __init__(self, parent=None, **kwargs):
if parent is None:
# create a new window
@@ -387,6 +391,8 @@
# the following class isn't used anywhere in the framework: ####
class ListBoxWindow:
+ """List box window."""
+
# called when user pushes the OK button.
# closes the window.
def pressedOK(self):
diff --git a/pywikibot/userinterfaces/terminal_interface_base.py b/pywikibot/userinterfaces/terminal_interface_base.py
index ee234e2..e08c50b 100755
--- a/pywikibot/userinterfaces/terminal_interface_base.py
+++ b/pywikibot/userinterfaces/terminal_interface_base.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
+"""Base for terminal user interfaces."""
#
# (C) Pywikibot team, 2003-2014
#
@@ -41,6 +42,9 @@
class UI:
+
+ """Base for terminal user interfaces."""
+
def __init__(self):
self.stdin = sys.stdin
self.stdout = sys.stdout
@@ -61,7 +65,6 @@
others write theirs to sys.stderr.
"""
-
if default_stream == 'stdout':
default_stream = self.stdout
elif default_stream == 'stderr':
@@ -187,7 +190,6 @@
Unlike raw_input, this function automatically adds a space after the
question.
"""
-
# sound the terminal bell to notify the user
if config.ring_bell:
sys.stdout.write('\07')
@@ -350,6 +352,7 @@
class TerminalHandler(logging.Handler):
+
"""A handler class that writes logging records to a terminal.
This class does not close the stream,
@@ -391,16 +394,21 @@
class TerminalFormatter(logging.Formatter):
+
+ """Terminal logging formatter."""
+
pass
class MaxLevelFilter(logging.Filter):
+
"""Filter that only passes records at or below a specific level.
(setting handler level only passes records at or *above* a specified level,
so this provides the opposite functionality)
"""
+
def __init__(self, level=None):
self.level = level
diff --git a/pywikibot/userinterfaces/terminal_interface_unix.py b/pywikibot/userinterfaces/terminal_interface_unix.py
index da6f43e..bb6384d 100755
--- a/pywikibot/userinterfaces/terminal_interface_unix.py
+++ b/pywikibot/userinterfaces/terminal_interface_unix.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
+"""User interface for unix terminals."""
#
# (C) Pywikibot team, 2003-2014
#
@@ -31,6 +32,9 @@
class UnixUI(terminal_interface_base.UI):
+
+ """User interface for unix terminals."""
+
def printColorized(self, text, targetStream):
totalcount = 0
for key, value in unixColors.items():
diff --git a/pywikibot/userinterfaces/terminal_interface_win32.py b/pywikibot/userinterfaces/terminal_interface_win32.py
index 098ae80..7e3fd89 100755
--- a/pywikibot/userinterfaces/terminal_interface_win32.py
+++ b/pywikibot/userinterfaces/terminal_interface_win32.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
+"""User interface for Win32 terminals."""
#
# (C) Pywikibot team, 2003-2013
#
@@ -40,12 +41,18 @@
# Compat for python <= 2.5
class Win32BaseUI(terminal_interface_base.UI):
+
+ """User interface for Win32 terminals without ctypes."""
+
def __init__(self):
terminal_interface_base.UI.__init__(self)
self.encoding = 'ascii'
class Win32CtypesUI(Win32BaseUI):
+
+ """User interface for Win32 terminals using ctypes."""
+
def __init__(self):
Win32BaseUI.__init__(self)
from .win32_unicode import stdin, stdout, stderr, argv
diff --git a/pywikibot/userinterfaces/win32_unicode.py b/pywikibot/userinterfaces/win32_unicode.py
index ae9048d..b92b273 100755
--- a/pywikibot/userinterfaces/win32_unicode.py
+++ b/pywikibot/userinterfaces/win32_unicode.py
@@ -1,4 +1,4 @@
-# Stdout, stderr and argv support:
+""" Stdout, stderr and argv support for unicode. """
##############################################
# Support for unicode in windows cmd.exe
# Posted on Stack Overflow [1], available under CC-BY-SA [2]
@@ -121,6 +121,9 @@
LPVOID)(("ReadConsoleW", windll.kernel32))
class UnicodeInput:
+
+ """Unicode terminal input class."""
+
def __init__(self, hConsole, name, bufsize=1024):
self._hConsole = hConsole
self.bufsize = bufsize
@@ -144,6 +147,9 @@
LPVOID)(("WriteConsoleW", windll.kernel32))
class UnicodeOutput:
+
+ """Unicode terminal output class."""
+
def __init__(self, hConsole, stream, fileno, name):
self._hConsole = hConsole
self._stream = stream
diff --git a/pywikibot/xmlreader.py b/pywikibot/xmlreader.py
index 4f19a73..dceeb4b 100644
--- a/pywikibot/xmlreader.py
+++ b/pywikibot/xmlreader.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
-
"""
+XML reading module.
+
Each XmlEntry object represents a page, as read from an XML source
The XmlDump class reads a pages_current XML dump (like the ones offered on
@@ -77,6 +78,7 @@
There surely are more elegant ways to do this.
"""
+
def __init__(self, filename, handler):
threading.Thread.__init__(self)
self.filename = filename
@@ -98,6 +100,7 @@
If True, parse all revisions instead of only the latest one.
Default: False.
"""
+
def __init__(self, filename, allrevisions=False):
self.filename = filename
if allrevisions:
diff --git a/tox.ini b/tox.ini
index 2ece018..5aa95f7 100644
--- a/tox.ini
+++ b/tox.ini
@@ -14,41 +14,12 @@
deps = flake8
[testenv:flake8-docstrings]
-commands = flake8 {posargs} --ignore=D102,D103,E122,E127,E241,E265
+commands = flake8 {posargs}
deps = flake8>=2.2.5
flake8-docstrings
[testenv:flake8-docstrings-mandatory]
-# Add any new file which is pep257 compatible
-commands = flake8 --ignore=D102,D103,E122,E127,E241,E265 \
- ./setup.py \
- ./generate_user_files.py \
- ./pywikibot/__init__.py \
- ./pywikibot/bot.py \
- ./pywikibot/botirc.py \
- ./pywikibot/config2.py \
- ./pywikibot/echo.py \
- ./pywikibot/editor.py \
- ./pywikibot/family.py \
- ./pywikibot/fixes.py \
- ./pywikibot/i18n.py \
- ./pywikibot/interwiki_graph.py \
- ./pywikibot/page.py \
- ./pywikibot/plural.py \
- ./pywikibot/site.py \
- ./pywikibot/pagegenerators.py \
- ./pywikibot/tools.py \
- ./pywikibot/version.py \
- ./pywikibot/weblib.py \
- ./pywikibot/comms/http.py \
- ./pywikibot/compat/userlib.py \
- ./pywikibot/compat/catlib.py \
- ./pywikibot/compat/query.py \
- ./pywikibot/data/__init__.py \
- ./pywikibot/data/api.py \
- ./pywikibot/userinterfaces/transliteration.py \
- ./pywikibot/userinterfaces/terminal_interface.py \
- ./scripts/ ./tests/
+commands = flake8 --ignore=D102,D103,E122,E127,E241,E265
deps = flake8>=2.2.5
flake8-docstrings
--
To view, visit https://gerrit.wikimedia.org/r/169755
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie3960ca8e15dde25bfba6d1afacc0b4d0362b357
Gerrit-PatchSet: 2
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: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: PEP257 scripts/
......................................................................
PEP257 scripts/
Used # noqa on Exception docstrings to avoid functional changes to
exception handling.
Change-Id: I07bb75e52ac9cbbf845e08a364526ed049e445a0
---
M scripts/add_text.py
M scripts/archivebot.py
M scripts/blockpageschecker.py
M scripts/blockreview.py
M scripts/capitalize_redirects.py
M scripts/casechecker.py
M scripts/cfd.py
M scripts/interwiki.py
M scripts/maintenance/__init__.py
M scripts/maintenance/compat2core.py
M scripts/maintenance/make_i18n_dict.py
M scripts/maintenance/wikimedia_sites.py
M scripts/makecat.py
M tox.ini
14 files changed, 155 insertions(+), 138 deletions(-)
Approvals:
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/add_text.py b/scripts/add_text.py
index d90e0cd..a9489dc 100644
--- a/scripts/add_text.py
+++ b/scripts/add_text.py
@@ -1,8 +1,10 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-"""
-This is a Bot written by Filnik to add a text at the end of the page but above
-categories, interwiki and template for the stars of the interwiki (default).
+r"""
+This is a Bot to add a text at the end of the content of the page.
+
+By default it adds the text above categories, interwiki and template
+for the stars of the interwiki.
Alternatively it may also add a text at the top of the page.
These command line parameters can be used to specify which pages to work on:
diff --git a/scripts/archivebot.py b/scripts/archivebot.py
index d57e2fc..2342d55 100644
--- a/scripts/archivebot.py
+++ b/scripts/archivebot.py
@@ -111,29 +111,39 @@
class MalformedConfigError(pywikibot.Error):
+
"""There is an error in the configuration template."""
class MissingConfigError(pywikibot.Error):
- """The config is missing in the header (either it's in one of the threads
- or transcluded from another page).
+ """
+ The config is missing in the header.
+
+ It's in one of the threads or transcluded from another page.
"""
class AlgorithmError(MalformedConfigError):
+
"""Invalid specification of archiving algorithm."""
class ArchiveSecurityError(pywikibot.Error):
- """Archive is not a subpage of page being archived and key not specified
- (or incorrect).
+ """
+ Page title is not a valid archive of page being archived.
+
+ The page title is neither a subpage of the page being archived,
+ nor does it match the key specified in the archive configuration template.
"""
def str2localized_duration(site, string):
- """Translate a duration written in the shorthand notation (ex. "24h", "7d")
+ """
+ Localise a shorthand duration.
+
+ Translates a duration written in the shorthand notation (ex. "24h", "7d")
into an expression in the local language of the wiki ("24 hours", "7 days").
"""
if string[-1] == 'd':
@@ -148,7 +158,10 @@
def str2time(string):
- """Accepts a string defining a time period:
+ """
+ Return a timedelta for a shorthand duration.
+
+ Accepts a string defining a time period:
7d - 7 days
36h - 36 hours
Returns the corresponding timedelta object.
@@ -162,7 +175,10 @@
def str2size(string):
- """Accepts a string defining a size:
+ """
+ Return a size for a shorthand size.
+
+ Accepts a string defining a size:
1337 - 1337 bytes
150K - 150 kilobytes
2M - 2 megabytes
@@ -209,8 +225,10 @@
class DiscussionThread(object):
- """An object representing a discussion thread on a page, that is something
- of the form:
+ """
+ An object representing a discussion thread on a page.
+
+ It represents something that is of the form:
== Title of thread ==
@@ -270,8 +288,10 @@
class DiscussionPage(pywikibot.Page):
- """A class that represents a single discussion page as well as an archive
- page. Feed threads to it and run an update() afterwards.
+ """
+ A class that represents a single page of discussion threads.
+
+ Feed threads to it and run an update() afterwards.
"""
def __init__(self, source, archiver, params=None):
@@ -362,6 +382,7 @@
class PageArchiver(object):
"""A class that encapsulates all archiving methods.
+
__init__ expects a pywikibot.Page object.
Execute by running the .run() method.
"""
@@ -431,6 +452,7 @@
def feed_archive(self, archive, thread, max_archive_size, params=None):
"""Feed the thread to one of the archives.
+
If it doesn't exist yet, create it.
If archive name is an empty string (or None),
discard the thread (/dev/null).
diff --git a/scripts/blockpageschecker.py b/scripts/blockpageschecker.py
index 52fd2fb..23785c9 100755
--- a/scripts/blockpageschecker.py
+++ b/scripts/blockpageschecker.py
@@ -1,11 +1,11 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
-This is a script originally written by Wikihermit and then rewritten by Filnik,
-to delete the templates used to warn in the pages that a page is blocked, when
-the page isn't blocked at all. Indeed, very often sysops block the pages for a
-setted time but then the forget to delete the warning! This script is useful if
-you want to delete those useless warning left in these pages.
+A bot to remove stale protection templates from pages that are not protected.
+
+Very often sysops block the pages for a setted time but then the forget to
+remove the warning! This script is useful if you want to remove those useless
+warning left in these pages.
Parameters:
diff --git a/scripts/blockreview.py b/scripts/blockreview.py
index 9abbe12..b4790bd 100644
--- a/scripts/blockreview.py
+++ b/scripts/blockreview.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
"""
This bot implements a blocking review process for de-wiki first.
+
For other sites this bot script must be changed.
This script is run by [[de:User:xqt]]. It should
@@ -27,6 +28,9 @@
class BlockreviewBot:
+
+ """Block review bot."""
+
# notes
note_admin = {
'de': u"""
@@ -78,10 +82,11 @@
def __init__(self, dry=False):
"""
- Constructor. Parameters:
- * generator - The page generator that determines on which pages
+ Constructor.
+
+ @param generator: The page generator that determines on which pages
to work on.
- * dry - If True, doesn't do any real changes, but only shows
+ @param dry: If True, doesn't do any real changes, but only shows
what would have been changed.
"""
self.site = pywikibot.Site()
@@ -109,7 +114,7 @@
% page.title(asLink=True))
def treat(self, userPage):
- """Loads the given page, does some changes, and saves it."""
+ """Load the given page, does some changes, and saves it."""
talkText = self.load(userPage)
if not talkText:
# sanity check. No talk page found.
@@ -256,7 +261,7 @@
ns=3)
def load(self, page):
- """Loads the given page, does some changes, and saves it."""
+ """Load the given page and return the page text."""
try:
# Load the page
text = page.get()
diff --git a/scripts/capitalize_redirects.py b/scripts/capitalize_redirects.py
index d74921c..a86b6e9 100644
--- a/scripts/capitalize_redirects.py
+++ b/scripts/capitalize_redirects.py
@@ -1,8 +1,9 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-
"""
-Bot to create capitalized redirects where the first character of the first
+Bot to create capitalized redirects.
+
+It creates redirects where the first character of the first
word is uppercase and the remaining characters and words are lowercase.
Command-line arguments:
@@ -40,6 +41,9 @@
class CapitalizeBot(Bot):
+
+ """Capitalization Bot."""
+
def __init__(self, generator, **kwargs):
self.availableOptions.update({
'titlecase': False,
diff --git a/scripts/casechecker.py b/scripts/casechecker.py
index 8bc2b23..97d84fe 100644
--- a/scripts/casechecker.py
+++ b/scripts/casechecker.py
@@ -1,8 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-""" Script to enumerate all pages on the wiki and find all titles
-with mixed latin and cyrilic alphabets.
-"""
+"""Bot to find all pages on the wiki with mixed latin and cyrilic alphabets."""
#
# (C) Pywikibot team, 2006-2014
#
@@ -83,6 +81,9 @@
class CaseChecker(object):
+
+ """Case checker."""
+
# These words are always in one language, even though they could be typed
# in both
alwaysInLocal = [u'СССР', u'Как', u'как']
diff --git a/scripts/cfd.py b/scripts/cfd.py
index c29e19d..8687735 100644
--- a/scripts/cfd.py
+++ b/scripts/cfd.py
@@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
"""
-This script processes the Categories for discussion working page. It parses
-out the actions that need to be taken as a result of CFD discussions (as posted
-to the working page by an administrator) and performs them.
+This script processes the Categories for discussion working page.
+
+It parses out the actions that need to be taken as a result of CFD discussions
+(as posted to the working page by an administrator) and performs them.
Syntax: python cfd.py
@@ -46,6 +47,9 @@
class ReCheck:
+
+ """Helper class."""
+
def __init__(self):
self.result = None
diff --git a/scripts/interwiki.py b/scripts/interwiki.py
index 89a04a6..396a085 100755
--- a/scripts/interwiki.py
+++ b/scripts/interwiki.py
@@ -1,8 +1,9 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
-Script to check language links for general pages. This works by downloading the
-page, and using existing translations plus hints from the command line to
+Script to check language links for general pages.
+
+Uses existing translations of a page, plus hints from the command line, to
download the equivalent pages from other languages. All of such pages are
downloaded as well and checked for interwiki links recursively until there are
no more links that are encountered. A rationalization process then selects the
@@ -369,7 +370,7 @@
"""An attempt to save a page with changed interwiki has failed."""
-class LinkMustBeRemoved(SaveError):
+class LinkMustBeRemoved(SaveError): # noqa
"""
An interwiki link has to be removed, but this can't be done because of user
@@ -380,6 +381,8 @@
class GiveUpOnPage(pywikibot.Error):
"""The user chose not to work on this page and its linked pages any more."""
+
+ pass
# Subpage templates. Must be in lower case,
@@ -456,6 +459,7 @@
"""
Container class for global settings.
+
Use of globals outside of this is to be avoided.
"""
@@ -624,9 +628,10 @@
class StoredPage(pywikibot.Page):
"""
- Store the Page contents on disk to avoid sucking too much
- memory when a big number of Page objects will be loaded
- at the same time.
+ Store the Page contents on disk.
+
+ This is to avoid sucking too much memory when a big number of Page objects
+ will be loaded at the same time.
"""
# Please prefix the class members names by SP
@@ -695,6 +700,7 @@
"""
Structure to manipulate a set of pages.
+
Allows filtering efficiently by Site.
"""
@@ -723,7 +729,7 @@
self.size = 0
def filter(self, site):
- """Iterates over pages that are in Site site."""
+ """Iterate over pages that are in Site site."""
try:
for page in self.tree[site]:
yield page
@@ -748,7 +754,7 @@
pass
def removeSite(self, site):
- """Removes all pages from Site site."""
+ """Remove all pages from Site site."""
try:
self.size -= len(self.tree[site])
del self.tree[site]
@@ -756,7 +762,7 @@
pass
def siteCounts(self):
- """Yields (Site, number of pages in site) pairs"""
+ """Yield (Site, number of pages in site) pairs."""
for site, d in self.tree.items():
yield site, len(d)
@@ -768,10 +774,10 @@
class Subject(object):
- """
- Class to follow the progress of a single 'subject' (i.e. a page with
- all its translations)
+ u"""
+ Class to follow the progress of a single 'subject'.
+ (i.e. a page with all its translations)
Subject is a transitive closure of the binary relation on Page:
"has_a_langlink_pointing_to".
@@ -826,9 +832,12 @@
"""
def __init__(self, originPage=None, hints=None):
- """Constructor. Takes as arguments the Page on the home wiki
- plus optionally a list of hints for translation
- """
+ """
+ Constructor.
+
+ Takes as arguments the Page on the home wiki
+ plus optionally a list of hints for translation
+ """
if globalvar.contentsondisk:
if originPage:
originPage = StoredPage(originPage)
@@ -869,6 +878,8 @@
def getFoundDisambig(self, site):
"""
+ Return the first disambiguation found.
+
If we found a disambiguation on the given site while working on the
subject, this method returns it. If several ones have been found, the
first one will be returned.
@@ -881,6 +892,8 @@
def getFoundNonDisambig(self, site):
"""
+ Return the first non-disambiguation found.
+
If we found a non-disambiguation on the given site while working on the
subject, this method returns it. If several ones have been found, the
first one will be returned.
@@ -894,6 +907,8 @@
def getFoundInCorrectNamespace(self, site):
"""
+ Return the first page in the extended namespace.
+
If we found a page that has the expected namespace on the given site
while working on the subject, this method returns it. If several ones
have been found, the first one will be returned.
@@ -942,7 +957,9 @@
def openSites(self):
"""
- Iterator. Yields (site, count) pairs:
+ Iterator.
+
+ Yields (site, count) pairs:
* site is a site where we still have work to do on
* count is the number of items in that Site that need work on
"""
@@ -950,6 +967,8 @@
def whatsNextPageBatch(self, site):
"""
+ Return the next page batch.
+
By calling this method, you 'promise' this instance that you will
preload all the 'site' Pages that are in the todo list.
@@ -972,7 +991,7 @@
return result
def makeForcedStop(self, counter):
- """Ends work on the page before the normal end."""
+ """End work on the page before the normal end."""
for site, count in self.todo.siteCounts():
counter.minus(site, count)
self.todo = PageTree()
@@ -980,8 +999,9 @@
def addIfNew(self, page, counter, linkingPage):
"""
- Adds the pagelink given to the todo list, but only if we didn't know
- it before. If it is added, update the counter accordingly.
+ Add the pagelink given to the todo list, if it hasnt been seen yet.
+
+ If it is added, update the counter accordingly.
Also remembers where we found the page, regardless of whether it had
already been found before or not.
@@ -1020,8 +1040,7 @@
def namespaceMismatch(self, linkingPage, linkedPage, counter):
"""
- Checks whether or not the given page has another namespace
- than the origin page.
+ Check whether or not the given page has a different namespace.
Returns True if the namespaces are different and the user
has selected not to follow the linked page.
@@ -1110,8 +1129,7 @@
def disambigMismatch(self, page, counter):
"""
- Checks whether or not the given page has the another disambiguation
- status than the origin page.
+ Check whether the given page has a different disambiguation status.
Returns a tuple (skip, alternativePage).
@@ -1247,6 +1265,8 @@
def batchLoaded(self, counter):
"""
+ Notify that the promised batch of pages was loaded.
+
This is called by a worker to tell us that the promised batch of
pages was loaded.
In other words, all the pages in self.pending have already
@@ -1603,11 +1623,12 @@
return result
def finish(self):
- """Round up the subject, making any necessary changes. This method
- should be called exactly once after the todo list has gone empty.
+ """
+ Round up the subject, making any necessary changes.
+
+ This should be called exactly once after the todo list has gone empty.
"""
-
if not self.isDone():
raise Exception("Bugcheck: finish called before done")
if not self.workonme:
@@ -1805,7 +1826,7 @@
del page._contents
def replaceLinks(self, page, newPages):
- """Returns True if saving was successful."""
+ """Return True if saving was successful."""
if globalvar.localonly:
# In this case only continue on the Page we started with
if page != self.originPage:
@@ -2087,11 +2108,15 @@
class InterwikiBot(object):
- """A class keeping track of a list of subjects, controlling which pages
- are queried from which languages when."""
+
+ """
+ A class keeping track of a list of subjects.
+
+ It controls which pages are queried from which languages when.
+ """
def __init__(self):
- """Constructor. We always start with empty lists."""
+ """Constructor."""
self.subjects = []
# We count how many pages still need to be loaded per site.
# This allows us to find out from which site to retrieve pages next
@@ -2111,9 +2136,12 @@
self.plus(site, count)
def setPageGenerator(self, pageGenerator, number=None, until=None):
- """Add a generator of subjects. Once the list of subjects gets
- too small, this generator is called to produce more Pages
- """
+ """
+ Add a generator of subjects.
+
+ Once the list of subjects gets too small,
+ this generator is called to produce more Pages.
+ """
self.pageGenerator = pageGenerator
self.generateNumber = number
self.generateUntil = until
@@ -2136,10 +2164,12 @@
return dumpfn
def generateMore(self, number):
- """Generate more subjects. This is called internally when the
- list of subjects becomes too small, but only if there is a
- PageGenerator
- """
+ """Generate more subjects.
+
+ This is called internally when the
+ list of subjects becomes too small, but only if there is a
+ PageGenerator
+ """
fs = self.firstSubject()
if fs and (not globalvar.quiet):
pywikibot.output(u"NOTE: The first unfinished subject is %s"
@@ -2206,11 +2236,12 @@
return self.subjects[0]
def maxOpenSite(self):
- """Return the site that has the most
- open queries plus the number. If there is nothing left, return
- None. Only languages that are TODO for the first Subject
- are returned.
- """
+ """
+ Return the site that has the most open queries plus the number.
+
+ If there is nothing left, return None.
+ Only languages that are TODO for the first Subject are returned.
+ """
max = 0
maxlang = None
if not self.firstSubject():
@@ -2318,14 +2349,14 @@
return len(self) == 0 and self.pageGenerator is None
def plus(self, site, count=1):
- """This is a routine that the Subject class expects in a counter."""
+ """Helper routine that the Subject class expects in a counter."""
try:
self.counts[site] += count
except KeyError:
self.counts[site] = count
def minus(self, site, count=1):
- """This is a routine that the Subject class expects in a counter."""
+ """Helper routine that the Subject class expects in a counter."""
self.counts[site] -= count
def run(self):
diff --git a/scripts/maintenance/__init__.py b/scripts/maintenance/__init__.py
index c47da75..ee430b4 100644
--- a/scripts/maintenance/__init__.py
+++ b/scripts/maintenance/__init__.py
@@ -1 +1,2 @@
# THIS DIRECTORY IS TO HOLD BOT SCRIPTS FOR THE NEW FRAMEWORK
+"""Maintenance scripts."""
diff --git a/scripts/maintenance/compat2core.py b/scripts/maintenance/compat2core.py
index 90b318f..5311aab 100644
--- a/scripts/maintenance/compat2core.py
+++ b/scripts/maintenance/compat2core.py
@@ -1,8 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
-This is a helper script to convert compat 1.0 scripts to the new core 2.0
-framework.
+A helper script to convert compat 1.0 scripts to the new core 2.0 framework.
NOTE: Please be aware that this script is not able to convert your codes
completely. It may support you with some automatic replacements and it gives
@@ -113,6 +112,8 @@
class ConvertBot(object):
+ """Script conversion bot."""
+
def __init__(self, filename=None, warnonly=False):
self.source = filename
self.warnonly = warnonly
diff --git a/scripts/maintenance/make_i18n_dict.py b/scripts/maintenance/make_i18n_dict.py
index cd55a70..590ead5 100644
--- a/scripts/maintenance/make_i18n_dict.py
+++ b/scripts/maintenance/make_i18n_dict.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
"""
-Generate a i18n file from a given script
+Generate a i18n file from a given script.
usage:
@@ -28,6 +28,8 @@
class i18nBot(object):
+ """I18n bot."""
+
def __init__(self, script, *args):
modules = script.split('.')
self.scriptname = modules[0]
diff --git a/scripts/maintenance/wikimedia_sites.py b/scripts/maintenance/wikimedia_sites.py
index 785b51b..83f2080 100644
--- a/scripts/maintenance/wikimedia_sites.py
+++ b/scripts/maintenance/wikimedia_sites.py
@@ -1,8 +1,5 @@
# -*- coding: utf-8 -*-
-"""
-This script checks the language list of each Wikimedia multiple-language site
-against the language lists
-"""
+"""Script that updates the language lists in Wikimedia family files."""
#
# (C) xqt, 2009-2014
# (C) Pywikibot team, 2008-2014
diff --git a/scripts/makecat.py b/scripts/makecat.py
index 0b28870..b92cbd3 100644
--- a/scripts/makecat.py
+++ b/scripts/makecat.py
@@ -48,7 +48,7 @@
def isdate(s):
- """returns true if s is a date or year."""
+ """Return true if s is a date or year."""
dict, val = date.getAutoFormat(pywikibot.Site().language(), s)
return dict is not None
diff --git a/tox.ini b/tox.ini
index e13d4d9..2ece018 100644
--- a/tox.ini
+++ b/tox.ini
@@ -48,60 +48,7 @@
./pywikibot/data/api.py \
./pywikibot/userinterfaces/transliteration.py \
./pywikibot/userinterfaces/terminal_interface.py \
- ./scripts/__init__.py \
- ./scripts/basic.py \
- ./scripts/category.py \
- ./scripts/category_redirect.py \
- ./scripts/claimit.py \
- ./scripts/clean_sandbox.py \
- ./scripts/commons_link.py \
- ./scripts/commonscat.py \
- ./scripts/coordinate_import.py \
- ./scripts/cosmetic_changes.py \
- ./scripts/create_categories.py \
- ./scripts/data_ingestion.py \
- ./scripts/delete.py \
- ./scripts/editarticle.py \
- ./scripts/flickrripper.py \
- ./scripts/freebasemappingupload.py \
- ./scripts/harvest_template.py \
- ./scripts/illustrate_wikidata.py \
- ./scripts/image.py \
- ./scripts/imagerecat.py \
- ./scripts/imagetransfer.py \
- ./scripts/imageuncat.py \
- ./scripts/isbn.py \
- ./scripts/listpages.py \
- ./scripts/login.py \
- ./scripts/lonelypages.py \
- ./scripts/newitem.py \
- ./scripts/misspelling.py \
- ./scripts/movepages.py \
- ./scripts/noreferences.py \
- ./scripts/nowcommons.py \
- ./scripts/pagefromfile.py \
- ./scripts/protect.py \
- ./scripts/redirect.py \
- ./scripts/reflinks.py \
- ./scripts/replace.py \
- ./scripts/replicate_wiki.py \
- ./scripts/revertbot.py \
- ./scripts/script_wui.py \
- ./scripts/selflink.py \
- ./scripts/shell.py \
- ./scripts/spamremove.py \
- ./scripts/template.py \
- ./scripts/templatecount.py \
- ./scripts/touch.py \
- ./scripts/transferbot.py \
- ./scripts/unlink.py \
- ./scripts/unusedfiles.py \
- ./scripts/version.py \
- ./scripts/watchlist.py \
- ./scripts/weblinkchecker.py \
- ./scripts/welcome.py \
- ./scripts/maintenance/cache.py \
- ./tests/
+ ./scripts/ ./tests/
deps = flake8>=2.2.5
flake8-docstrings
--
To view, visit https://gerrit.wikimedia.org/r/169689
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I07bb75e52ac9cbbf845e08a364526ed049e445a0
Gerrit-PatchSet: 3
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: Siebrand <siebrand(a)kitano.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: [IMPROV] PageTitleFilterPageGenerator: docstring more specific
......................................................................
[IMPROV] PageTitleFilterPageGenerator: docstring more specific
The docstring explicitly says that the titles need to be regexable
strings. Also simplified the test if there is an entry for family/code
in ignore_list.
Change-Id: I1ef136bcd6d9d1cd2d891024b85dfed414b83eef
---
M pywikibot/pagegenerators.py
1 file changed, 4 insertions(+), 4 deletions(-)
Approvals:
Nullzero: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py
index fab7ccd..28c4136 100644
--- a/pywikibot/pagegenerators.py
+++ b/pywikibot/pagegenerators.py
@@ -923,14 +923,14 @@
"""
Yield only those pages are not listed in the ignore list.
- @param ignore_list: family names are mapped to dictionaries
- in which language codes are mapped to lists of page titles
+ @param ignore_list: family names are mapped to dictionaries in which
+ language codes are mapped to lists of page titles. Each title must
+ be a valid regex as they are compared using L{re.search}.
@type ignore_list: dict
"""
def is_ignored(page):
- if page.site.family.name in ignore_list and \
- page.site.code in ignore_list[page.site.family.name]:
+ if page.site.code in ignore_list.get(page.site.family.name, {}):
for ig in ignore_list[page.site.family.name][page.site.code]:
if re.search(ig, page.title()):
return True
--
To view, visit https://gerrit.wikimedia.org/r/169671
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I1ef136bcd6d9d1cd2d891024b85dfed414b83eef
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: Nullzero <nullzero.free(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>