Skip to content

Commit

Permalink
Remove every implicit use of textlib
Browse files Browse the repository at this point in the history
follows:
* Iabede1697aa1f5c8e3039b2b404029bc6cfd55ff
* I6cc16f23fe9fbb851b26725557525619c3051a26

Change-Id: I0437028a32da219205fc30aec3921474132e1cc8
  • Loading branch information
ricordisamoa committed Aug 19, 2014
1 parent 24e87fc commit 1a14561
Show file tree
Hide file tree
Showing 15 changed files with 155 additions and 166 deletions.
24 changes: 11 additions & 13 deletions scripts/add_text.py
Expand Up @@ -77,9 +77,7 @@
import time

import pywikibot
from pywikibot import config
from pywikibot import i18n
from pywikibot import pagegenerators
from pywikibot import config, i18n, pagegenerators, textlib

docuReplacements = {
'&params;': pagegenerators.parameterHelp,
Expand Down Expand Up @@ -173,23 +171,23 @@ def add_text(page, addText, summary=None, regexSkip=None,
addText = addText.replace('\\n', config.line_separator)
if (reorderEnabled):
# Getting the categories
categoriesInside = pywikibot.getCategoryLinks(newtext, site)
categoriesInside = textlib.getCategoryLinks(newtext, site)
# Deleting the categories
newtext = pywikibot.removeCategoryLinks(newtext, site)
newtext = textlib.removeCategoryLinks(newtext, site)
# Getting the interwiki
interwikiInside = pywikibot.getLanguageLinks(newtext, site)
interwikiInside = textlib.getLanguageLinks(newtext, site)
# Removing the interwiki
newtext = pywikibot.removeLanguageLinks(newtext, site)
newtext = textlib.removeLanguageLinks(newtext, site)

# Adding the text
newtext += u"%s%s" % (config.line_separator, addText)
# Reputting the categories
newtext = pywikibot.replaceCategoryLinks(newtext,
categoriesInside, site,
True)
newtext = textlib.replaceCategoryLinks(newtext,
categoriesInside, site,
True)
# Dealing the stars' issue
allstars = []
starstext = pywikibot.removeDisabledParts(text)
starstext = textlib.removeDisabledParts(text)
for star in starsList:
regex = re.compile('(\{\{(?:template:|)%s\|.*?\}\}[\s]*)'
% star, re.I)
Expand All @@ -203,8 +201,8 @@ def add_text(page, addText, summary=None, regexSkip=None,
for element in allstars:
newtext += '%s%s' % (element.strip(), config.LS)
# Adding the interwiki
newtext = pywikibot.replaceLanguageLinks(newtext, interwikiInside,
site)
newtext = textlib.replaceLanguageLinks(newtext, interwikiInside,
site)
else:
newtext += u"%s%s" % (config.line_separator, addText)
else:
Expand Down
6 changes: 3 additions & 3 deletions scripts/catall.py
Expand Up @@ -23,7 +23,7 @@

import sys
import pywikibot
from pywikibot import i18n
from pywikibot import i18n, textlib


def choosecats(pagetext):
Expand Down Expand Up @@ -69,8 +69,8 @@ def make_categories(page, list, site=None):
for p in list:
cattitle = "%s:%s" % (site.category_namespace(), p)
pllist.append(pywikibot.Page(site, cattitle))
page.put_async(pywikibot.replaceCategoryLinks(page.get(), pllist,
site=page.site),
page.put_async(textlib.replaceCategoryLinks(page.get(), pllist,
site=page.site),
comment=i18n.twtranslate(site.code, 'catall-changing'))


Expand Down
4 changes: 2 additions & 2 deletions scripts/category.py
Expand Up @@ -105,7 +105,7 @@
import bz2
import pywikibot
from pywikibot import config, pagegenerators
from pywikibot import i18n
from pywikibot import i18n, textlib
from pywikibot import deprecate_arg, deprecated

# This is required for the text that is shown when you run this script
Expand Down Expand Up @@ -397,7 +397,7 @@ def treat(self, page):
catpl = self.sorted_by_last_name(catpl, page)
pywikibot.output(u'Adding %s' % catpl.title(asLink=True))
cats.append(catpl)
text = pywikibot.replaceCategoryLinks(text, cats, site=page.site)
text = textlib.replaceCategoryLinks(text, cats, site=page.site)
if not self.save(text, page, newcatTitle, old_text=old_text):
pywikibot.output(u'Page %s not saved.'
% page.title(asLink=True))
Expand Down
186 changes: 93 additions & 93 deletions scripts/cosmetic_changes.py

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions scripts/featured.py
Expand Up @@ -55,7 +55,7 @@
# (C) Maxim Razin, 2005
# (C) Leonardo Gregianin, 2005-2008
# (C) xqt, 2009-2014
# (C) Pywikibot team, 2005-2012
# (C) Pywikibot team, 2005-2014
#
# Distributed under the terms of the MIT license.
#
Expand All @@ -65,7 +65,7 @@
import pickle
import re
import pywikibot
from pywikibot import i18n
from pywikibot import i18n, textlib
from pywikibot.pagegenerators import PreloadingGenerator
from pywikibot.config2 import LS # line separator

Expand Down Expand Up @@ -566,12 +566,12 @@ def compile_link(site, templates):
text[m1.end():])
else:
# Moving {{Link FA|xx}} to top of interwikis
iw = pywikibot.getLanguageLinks(text, tosite)
text = pywikibot.removeLanguageLinks(text, tosite)
iw = textlib.getLanguageLinks(text, tosite)
text = textlib.removeLanguageLinks(text, tosite)
text += u"%s{{%s|%s}}%s" % (LS, add_tl[0],
fromsite.code, LS)
text = pywikibot.replaceLanguageLinks(text,
iw, tosite)
text = textlib.replaceLanguageLinks(text,
iw, tosite)
changed = True
if remove_tl:
if m2:
Expand Down
10 changes: 5 additions & 5 deletions scripts/flickrripper.py
Expand Up @@ -25,7 +25,7 @@
"""
#
# (C) Multichill, 2009
# (C) Pywikibot team, 2009-2013
# (C) Pywikibot team, 2009-2014
#
# Distributed under the terms of the MIT license.
#
Expand All @@ -39,7 +39,7 @@
import base64
import time
import pywikibot
from pywikibot import config
from pywikibot import config, textlib
import upload

try:
Expand Down Expand Up @@ -236,9 +236,9 @@ def buildDescription(flinfoDescription=u'', flickrreview=False, reviewer=u'',
"""
description = u'== {{int:filedesc}} ==\n%s' % flinfoDescription
if removeCategories:
description = pywikibot.removeCategoryLinks(description,
pywikibot.Site(
'commons', 'commons'))
description = textlib.removeCategoryLinks(description,
pywikibot.Site(
'commons', 'commons'))
if override:
description = description.replace(u'{{cc-by-sa-2.0}}\n', u'')
description = description.replace(u'{{cc-by-2.0}}\n', u'')
Expand Down
4 changes: 2 additions & 2 deletions scripts/harvest_template.py
Expand Up @@ -32,7 +32,7 @@

import re
import pywikibot
from pywikibot import pagegenerators as pg, WikidataBot
from pywikibot import pagegenerators as pg, textlib, WikidataBot

docuReplacements = {'&params;': pywikibot.pagegenerators.parameterHelp}

Expand Down Expand Up @@ -125,7 +125,7 @@ def processPage(self, page):
pywikibot.output(u'%s item %s has claims for all properties. Skipping' % (page, item.title()))
else:
pagetext = page.get()
templates = pywikibot.extract_templates_and_params(pagetext)
templates = textlib.extract_templates_and_params(pagetext)
for (template, fielddict) in templates:
# Clean up template
try:
Expand Down
4 changes: 2 additions & 2 deletions scripts/imagerecat.py
Expand Up @@ -40,7 +40,7 @@
import xml.etree.ElementTree

import pywikibot
from pywikibot import pagegenerators
from pywikibot import pagegenerators, textlib

category_blacklist = []
countries = []
Expand Down Expand Up @@ -390,7 +390,7 @@ def filterParents(categories):

def saveImagePage(imagepage, newcats, usage, galleries, onlyFilter):
""" Remove the old categories and add the new categories to the image. """
newtext = pywikibot.removeCategoryLinks(imagepage.text, imagepage.site)
newtext = textlib.removeCategoryLinks(imagepage.text, imagepage.site)
if not onlyFilter:
newtext = removeTemplates(newtext)
newtext = newtext + getCheckCategoriesTemplate(usage, galleries,
Expand Down
9 changes: 4 additions & 5 deletions scripts/imagetransfer.py
Expand Up @@ -36,8 +36,7 @@
import sys
import pywikibot
import upload
from pywikibot import config
from pywikibot import i18n
from pywikibot import config, i18n, textlib

copy_message = {
'ar': u"هذه الصورة تم نقلها من %s. الوصف الأصلي كان:\r\n\r\n%s",
Expand Down Expand Up @@ -178,9 +177,9 @@ def transferImage(self, sourceImagePage):
self.targetSite.sitename())].iteritems():
new = '{{%s}}' % new
old = re.compile('{{%s}}' % old)
description = pywikibot.replaceExcept(description, old, new,
['comment', 'math',
'nowiki', 'pre'])
description = textlib.replaceExcept(description, old, new,
['comment', 'math',
'nowiki', 'pre'])

description = i18n.translate(self.targetSite, copy_message,
fallback=True) % (sourceSite, description)
Expand Down
14 changes: 5 additions & 9 deletions scripts/interwiki.py
Expand Up @@ -337,7 +337,7 @@
# (C) Daniel Herding, 2004
# (C) Yuri Astrakhan, 2005-2006
# (C) xqt, 2009-2014
# (C) Pywikibot team, 2007-2013
# (C) Pywikibot team, 2007-2014
#
# Distributed under the terms of the MIT license.
#
Expand All @@ -354,11 +354,7 @@
import socket
import webbrowser
import pywikibot
from pywikibot import config
from pywikibot import pagegenerators
from pywikibot import i18n
from pywikibot import interwiki_graph
from pywikibot import titletranslate
from pywikibot import config, i18n, pagegenerators, textlib, interwiki_graph, titletranslate

docuReplacements = {
'&pagegenerators_help;': pagegenerators.parameterHelp
Expand Down Expand Up @@ -1919,9 +1915,9 @@ def replaceLinks(self, page, newPages):
pywikibot.output(u"Changes to be made: %s" % mods)
oldtext = page.get()
template = (page.namespace() == 10)
newtext = pywikibot.replaceLanguageLinks(oldtext, new,
site=page.site,
template=template)
newtext = textlib.replaceLanguageLinks(oldtext, new,
site=page.site,
template=template)
# This is for now. Later there should be different funktions for each
# kind
if not botMayEdit(page):
Expand Down
4 changes: 2 additions & 2 deletions scripts/makecat.py
Expand Up @@ -43,7 +43,7 @@
import sys
import codecs
import pywikibot
from pywikibot import date, pagegenerators, i18n
from pywikibot import date, pagegenerators, i18n, textlib


def isdate(s):
Expand Down Expand Up @@ -89,7 +89,7 @@ def include(pl, checklinks=True, realinclude=True, linkterm=None):
pl.change_category(actualworkingcat)
break
else:
pl.put(pywikibot.replaceCategoryLinks(
pl.put(textlib.replaceCategoryLinks(
text, cats + [actualworkingcat], site=pl.site))
if cl:
if checkforward:
Expand Down
10 changes: 5 additions & 5 deletions scripts/noreferences.py
Expand Up @@ -42,7 +42,7 @@

import re
import pywikibot
from pywikibot import i18n, pagegenerators, Bot
from pywikibot import i18n, pagegenerators, textlib, Bot

# This is required for the text that is shown when you run this script
# with the parameter -help.
Expand Down Expand Up @@ -443,7 +443,7 @@ def __iter__(self):
import xmlreader
dump = xmlreader.XmlDump(self.xmlFilename)
for entry in dump.parse():
text = pywikibot.removeDisabledParts(entry.text)
text = textlib.removeDisabledParts(entry.text)
if self.refR.search(text) and not self.referencesR.search(text):
yield pywikibot.Page(pywikibot.Site(), entry.title)

Expand Down Expand Up @@ -479,7 +479,7 @@ def lacksReferences(self, text):
"""
Checks whether or not the page is lacking a references tag.
"""
oldTextCleaned = pywikibot.removeDisabledParts(text)
oldTextCleaned = textlib.removeDisabledParts(text)
if self.referencesR.search(oldTextCleaned) or \
self.referencesTagR.search(oldTextCleaned):
if self.getOption('verbose'):
Expand Down Expand Up @@ -516,7 +516,7 @@ def addReferences(self, oldText):
while index < len(oldText):
match = sectionR.search(oldText, index)
if match:
if pywikibot.isDisabled(oldText, match.start()):
if textlib.isDisabled(oldText, match.start()):
pywikibot.output(
'Existing %s section is commented out, skipping.'
% section)
Expand All @@ -543,7 +543,7 @@ def addReferences(self, oldText):
while index < len(oldText):
match = sectionR.search(oldText, index)
if match:
if pywikibot.isDisabled(oldText, match.start()):
if textlib.isDisabled(oldText, match.start()):
pywikibot.output(
'Existing %s section is commented out, won\'t add '
'the references in front of it.' % section)
Expand Down
4 changes: 2 additions & 2 deletions scripts/reflinks.py
Expand Up @@ -54,7 +54,7 @@
import StringIO

import pywikibot
from pywikibot import i18n, pagegenerators, xmlreader, Bot
from pywikibot import i18n, pagegenerators, textlib, xmlreader, Bot
import noreferences

docuReplacements = {
Expand Down Expand Up @@ -512,7 +512,7 @@ def run(self):

# for each link to change
for match in linksInRef.finditer(
pywikibot.removeDisabledParts(page.get())):
textlib.removeDisabledParts(page.get())):

link = match.group(u'url')
# debugging purpose
Expand Down
18 changes: 9 additions & 9 deletions scripts/replace.py
Expand Up @@ -128,7 +128,7 @@
import pywikibot
from pywikibot import pagegenerators
from pywikibot import editor as editarticle
from pywikibot import i18n
from pywikibot import i18n, textlib
import webbrowser

# Imports predefined replacements tasks from fixes.py
Expand Down Expand Up @@ -186,7 +186,7 @@ def __iter__(self):
and not self.isTextExcepted(entry.text):
new_text = entry.text
for old, new in self.replacements:
new_text = pywikibot.replaceExcept(
new_text = textlib.replaceExcept(
new_text, old, new, self.excsInside, self.site)
if new_text != entry.text:
yield pywikibot.Page(self.site, entry.title)
Expand Down Expand Up @@ -257,7 +257,7 @@ def __init__(self, generator, replacements, exceptions={},
regular expressions.
inside-tags
A list of strings. These strings must be keys from the
exceptionRegexes dictionary in pywikibot.replaceExcept().
exceptionRegexes dictionary in textlib.replaceExcept().
"""
self.generator = generator
Expand Down Expand Up @@ -315,9 +315,9 @@ def doReplacements(self, original_text):
for old, new in self.replacements:
if self.sleep is not None:
time.sleep(self.sleep)
new_text = pywikibot.replaceExcept(new_text, old, new, exceptions,
allowoverlap=self.allowoverlap,
site=self.site)
new_text = textlib.replaceExcept(new_text, old, new, exceptions,
allowoverlap=self.allowoverlap,
site=self.site)
return new_text

def run(self):
Expand Down Expand Up @@ -363,9 +363,9 @@ def run(self):
cats = page.categories(nofollow_redirects=True)
if self.addedCat not in cats:
cats.append(self.addedCat)
new_text = pywikibot.replaceCategoryLinks(new_text,
cats,
site=page.site)
new_text = textlib.replaceCategoryLinks(new_text,
cats,
site=page.site)
# Show the title of the page we're working on.
# Highlight the title in purple.
pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
Expand Down

0 comments on commit 1a14561

Please sign in to comment.