Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.skipTest(
'{0} is not running on a replicated database cluster.'
.format(mysite)
)
mythrottle = DummyThrottle(mysite)
mysite._throttle = mythrottle
params = {'action': 'query',
'titles': self.get_mainpage().title(),
'maxlag': -1}
req = api.Request(site=mysite, parameters=params)
try:
req.submit()
except SystemExit:
pass # expected exception from DummyThrottle instance
except api.APIError as e:
pywikibot.warning(
'Wrong api.lagpattern regex, cannot retrieve lag value')
raise e
self.assertIsInstance(mythrottle._lagvalue, int)
self.assertGreaterEqual(mythrottle._lagvalue, 0)
self.assertIsInstance(mythrottle.retry_after, int)
self.assertGreaterEqual(mythrottle.retry_after, 0)
"""
Display pages that link to the current page, sorted per namespace.
Number of pages to display per namespace is provided by:
- self.getOption('isorphan')
"""
refs = self.current_page.ref_table
if not refs:
return
total = sum(len(v) for v in refs.values())
if total > 1:
pywikibot.warning('There are {} pages that link to {}.'
.format(total, self.current_page))
else:
pywikibot.warning('There is a page that links to {}.'
.format(self.current_page))
show_n_pages = self.getOption('isorphan')
width = len(max((ns.canonical_prefix() for ns in refs), key=len))
for ns in sorted(refs):
n_pages_in_ns = len(refs[ns])
plural = '' if n_pages_in_ns == 1 else 's'
ns_name = ns.canonical_prefix() if ns != ns.MAIN else 'Main:'
ns_id = '[{0}]'.format(ns.id)
pywikibot.output(
' {0!s:<{width}} {1:>6} {2:>10} page{pl}'.format(
ns_name, ns_id, n_pages_in_ns, width=width, pl=plural))
if show_n_pages: # do not show marker if 0 pages are requested.
for page in islice_with_ellipsis(refs[ns], show_n_pages):
pywikibot.output(' {0!s}'.format(page.title()))
def treat(self, page):
"""
Load the given page, make the required changes, and save it.
@param page: the page to treat
@type page: pywikibot.Page
"""
self.current_page = page
page.get()
wikicode = mwparserfromhell.parse(page.text)
for el in wikicode.ifilter_tags():
if el.tag in self.getOption('tags'):
try:
result = self.process_lines(el.contents)
except PoemError as e:
pywikibot.warning(e)
continue
if result:
lines, numbering, lines_count = result
if lines != el.contents:
scheme = self.detect_numbering(numbering, lines_count)
if scheme:
el.contents = lines
for attr, val in scheme.items():
el.add(attr, val)
if self.getOption('preferred'):
# change the tag name to the preferred form
el.tag = self.getOption('preferred')
else:
pywikibot.warning(u'a reliable line numbering scheme could not be obtained')
newtext = unicode(wikicode)
summary = self.getOption('summary')
# convert any Special:BotPassword usernames to main account equivalent
main_username = self.username
if '@' in self.username:
warn(
'When using BotPasswords it is recommended that you store '
'your login credentials in a password_file instead. See '
'{}/BotPasswords for instructions and more information.'
.format(__url__))
main_username = self.username.partition('@')[0]
try:
data = self.site.allusers(start=main_username, total=1)
user = next(iter(data))
except pywikibot.data.api.APIError as e:
if e.code == 'readapidenied':
pywikibot.warning('Could not check user %s exists on %s'
% (main_username, self.site))
return
else:
raise
if user['name'] != main_username:
# Report the same error as server error code NotExists
raise NoUsername("Username '%s' does not exist on %s"
% (main_username, self.site))
def status(self):
"""Return Proofread Page status."""
try:
return self.site.proofread_levels[self.ql]
except KeyError:
pywikibot.warning('Not valid status set for %s: quality level = %s'
% (self.title(as_link=True), self.ql))
return None
'Where have you saved your signatures?')
elif arg == '-sign':
globalvar.defaultSign = val or pywikibot.input(
'Which signature to use?')
globalvar.defaultSign += timeselected
elif arg == '-limit':
globalvar.queryLimit = int(val or pywikibot.input(
'How many of the latest new users would you like to load?'))
elif arg == '-numberlog':
globalvar.dumpToLog = int(val or pywikibot.input(
'After how many welcomed users would you like to update the '
'welcome log?'))
elif arg in mapping:
setattr(globalvar, *mapping[arg])
else:
pywikibot.warning('Unknown option "{}"'.format(arg))
data = {'sitelinks': [], 'labels': []}
for p in toImport:
data['sitelinks'].append({'site': p.site.dbName(), 'title': p.title()})
lng = lang(p)
if lng not in importInto.labels:
data['labels'].append({'language': lng, 'value': intelLabel(importInto, p)})
summary = pywikibot.i18n.translate(importInto.site, import_summary,
{'sitelinks': u', '.join(dbNames[:-2] + [u' and '.join(dbNames[-2:])]),
'count': len(dbNames),
'source': page.site.dbName()
})
try:
importInto.editEntity(data, summary=summary)
pywikibot.output(u'\03{{lightgreen}}successfully imported {} sitelinks and {} labels'.format(len(data['sitelinks']), len(data['labels'])))
except Exception, e:
pywikibot.warning(e)
return
treat(page=page, comment=comment)
return
toRemove = [link for link in toRemove if link.site.family == page.site.family]
if len(toRemove) > 0:
counter = 0
for langlink in toRemove:
temp = removeLanglink(text, langlink)
if temp != text:
counter += 1
text = temp
if counter == len(toRemove) and text != page.text:
pywikibot.showDiff(page.text, text)
page.text = text
if comment is None:
try:
# When running in autonomous mode without -force switch, make sure we
# don't remove any items, but allow addition of the new ones
if self.conf.autonomous and not self.conf.force and len(removing) > 0:
for rmsite in removing:
# Sometimes sites have an erroneous link to itself as an
# interwiki
if rmsite == page.site:
continue
rmPage = old[rmsite]
# put it to new means don't delete it
if (
not self.conf.cleanup or
unicode(rmPage) not in self.conf.remove
):
new[rmsite] = rmPage
pywikibot.warning(
'%s is either deleted or has a mismatching '
'disambiguation state.'
% rmPage)
# Re-Check what needs to get done
mods, mcomment, adding, removing, modifying = compareLanguages(
old,
new,
page.site,
self.conf.summary
)
if not mods:
if not self.conf.quiet:
pywikibot.output(u'No changes needed on page %s' % page)
return False
# Show a message in purple.