Add whitespaces per PEP 8

Change-Id: Ia1a80643cbb83827f9587dc4bdac4ddc34dbc35d
Code improvements, split code into parts

- findTranslated() becomes a generator
- Split featuredWithInterwiki() into main loop and
- add_template() to place/change the template

Change-Id: I40693c603423ee7aabba53a4226df20c1e81b88b
textlib InterwikiFormat() depends on config

InterwikiFormat implicitly uses Page.title() which by default uses
config settings to dynamically determine whether to include a family and/or
lang prefix to the title.  InterwikiFormat is supposed to format
interwikis relative to 'insite', not config variables such as family.

Explicitly invoke Page.title() with appropriate parameters to override
config settings.

The relevant test failed when config.family was not wikipedia.
In addition to the bug in textlib, the test also depended on config
settings.  Link()'s should be instantiated with a source in these tests.

Change-Id: I9ab8780e659517db7068d4af3164a2f54ce85461
Site: add canonical namespaces to site._namespaces

Needed to identify which namespaces can be accessed by an Extension.
E.g. Proofread Page works on Page and Index namespaces, which keep the
same name as 'canonical' namespaces but not as 'actual' namespaces.

Code improvements as well

Preparation for ProofreadPage class.

Change-Id: I58d67501e00ff9f1afdbdde97ac43bd7aeb40963
Add maintenance script for the API cache

Replace cache entry deletion in TestRequest with a new
script 'cache.py' which reports cache entries with a password
and allows them to be fixed.

cache.py also allows cache entries to be queried and deleted
based on other conditions.

Change-Id: I727af9b6fa10d2231e5d777a1bc6f8602ca03f50
Always store cache in test/apicache for tests

The API caching under the test framework stores
data in tests/apicache when the Request was uncached
in normal operation, and in <base_dir>/apicache if the
request is processed by CachedRequest in normal operation.

This change forces all cached API requests to be stored
in tests/apicache, irrespective of how the test was invoked,
or whether the request would normally be cached or not.

CachedRequest methods _get_cache_dir and _make_dir converted
to static methods for easy monkey-patching, and docstrings added.

Change-Id: Ibc7ec0a90a130fb1c834fd632af7872f1325b3e0
Run travis builds on multiple wikis (try #2)

Will run on en.wp, ar.wp, and test.wd.

Change-Id: Ic7db3bef56169fcf5c29ffcb793af8e4894459f6
Merge "Site: add canonical namespaces to site._namespaces"
rename Claim._formatDataValue() into _formatValue()

and create a new _formatDataValue() method
which returns _formatValue() as 'value' and the value type as 'type'
(technically, this is a breaking change, but at internal level)

for clarity reasons, and also to reduce code duplication in site.py
and in Ibe77c51fc5cf3dae8ece533cc5787bf960f0ebed (yet to come)

this allows claims of "commonsMedia", "globe-coordinate" and "quantity"
datatypes to be added as sources using DataSite.editSource()

Change-Id: If8de1887f34d83a38e1a0b05279c5b8eb68a1e8a
Merge "rename Claim._formatDataValue() into _formatValue()"
Test python 2.7 before 2.6

As only a limited number of builds occur on travis concurrently,
do the py 2.7 tests before the py 2.6 tests.

Change-Id: Ib9ce4e8cb388712f1276e87c79978d2ea8e51c33
replace nicepath() + page.title() with nice_get_address(title())

- we use the site methods instead of the family method
- fix for title(), must be asUrl=True
- use page.site instead of pywikibot.Site()

Change-Id: I40d77625ea5e025f44c26fdafaa226a931d34068
small improvements to category.py

- fix most docstrings according to pep257

- use a single multiline string instead of multiple single-line ones

- use string formatting instead of concatenation where appropriate

- merge several `else if` statements into a tuple lookup

- remove obsolete script name from showHelp

Change-Id: Ie903a2b299db506bb0b4345847cefc537d151094
Merge "replace nicepath() + page.title() with nice_get_address(title())"
fix and reenable cosmetic_changes' standardizePageFooter()

using category.aslink() instead of .title(asLink=True)
in textlib.categoryFormat(), thus preserving the sortKey.

this implicitly reverts I88b01681f59aab91d5f70e788eae3349b87455a8

bug: 66921
Change-Id: Ib0701600a300b2435ac8f2c3b8a55c89faf2c2fe
Fix wikibase tests broken by wiki edit

wikibase:Q5296 English label has changed from 'Main Page'
to 'Wikimedia main page'.  Slightly adjust the logic so that either
is acceptable.

The initial version of the wikibase tests included a minor
code issue causing a test to be ineffective.  In testWikibase, instead
of exercising item2.labels, item.labels is exercised a second time.
item2.getID does not cause get() to be called, so get() needs to
be explicitly in the test sequence.

Change-Id: I75fa36c3b05ba8141c51ce19575b7667f408fd84
page.categories() is no longer preferred to texlib.getCategoryLinks()

the former uses the API, while the latter parses wikitext.

Change-Id: Ib87befc2f5dfa9002499758c1414122d5a88f47e
Merge "textlib InterwikiFormat() depends on config"
Report site&title for lazy loaded ItemPage

When lazy loading the ID of a ItemPage, NoPage exception is thrown if the
item is 'missing'.  Currently the Wikibase API does not distinguish
between a) title not existing on a site, and b) site&title not having
a wikibase item associated with it. Both are 'missing'. Bug 68251.

If the site&title does not exist, the NoPage exception should report
the site&title which does not exist, so this appears in the logging
rather than reporting that 'Item -1' does not exist.

Change-Id: I057bb8e752a6cb190e392847292269cbee1f7194
Another user-agent related fixup

config2 was previously able to be run under python3.
This fixes a recent commit which broke that.

Change-Id: Iec2b9357b09a88cbda61a218d502274179d83da4