http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10431
Revision: 10431
Author: xqt
Date: 2012-06-30 15:47:10 +0000 (Sat, 30 Jun 2012)
Log Message:
-----------
fix for non plural languages when plural_rules returns just 0
Modified Paths:
--------------
branches/rewrite/pywikibot/i18n.py
Modified: branches/rewrite/pywikibot/i18n.py
===================================================================
--- branches/rewrite/pywikibot/i18n.py 2012-06-30 11:11:05 UTC (rev 10430)
+++ branches/rewrite/pywikibot/i18n.py 2012-06-30 15:47:10 UTC (rev 10431)
@@ -389,12 +389,15 @@
lang = code.pop()
# we only need the lang or _default, not a _altlang code
# maybe we should implement this to i18n.translate()
+ # TODO: check against plural_rules[lang]['nplurals']
try:
- plural_func = plural_rules[lang]['plural']
+ index = plural_rules[lang]['plural'](num)
except KeyError:
- plural_func = plural_rules['_default']['plural']
- # TODO: check against plural_rules[lang]['nplurals']
- repl = variants.split('|')[plural_func(num)]
+ index = plural_rules['_default']['plural'](num)
+ except TypeError:
+ # we got an int
+ index = plural_rules[lang]['plural']
+ repl = variants.split('|')[index]
trans = re.sub(PATTERN, repl, trans)
if param:
try:
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10428
Revision: 10428
Author: xqt
Date: 2012-06-29 16:13:07 +0000 (Fri, 29 Jun 2012)
Log Message:
-----------
enable multiple links in a file link,
regex stolen from textlib.replaceexcept for nested templates,
bugfix for bug #3538973
Modified Paths:
--------------
trunk/pywikipedia/cosmetic_changes.py
Modified: trunk/pywikipedia/cosmetic_changes.py
===================================================================
--- trunk/pywikipedia/cosmetic_changes.py 2012-06-29 15:35:31 UTC (rev 10427)
+++ trunk/pywikipedia/cosmetic_changes.py 2012-06-29 16:13:07 UTC (rev 10428)
@@ -208,10 +208,10 @@
old instances standardizeInterwiki and standardizeCategories
The page footer has the following section in that sequence:
1. categories
- 2a TODO:template beyond categories
- 2. additional information depending on local site policy
- 3. stars templates for featured and good articles
- 4. interwiki links
+ 2. ## TODO: template beyond categories ##
+ 3. additional information depending on local site policy
+ 4. stars templates for featured and good articles
+ 5. interwiki links
"""
starsList = [
u'bueno',
@@ -279,8 +279,6 @@
% star, re.I)
found = regex.findall(starstext)
if found != []:
- if pywikibot.verbose:
- print found
text = regex.sub('', text)
allstars += found
@@ -296,8 +294,6 @@
regex = re.compile(iw_reg)
found = regex.findall(text)
if found:
- if pywikibot.verbose:
- print found
hasCommentLine = True
text = regex.sub('', text)
@@ -319,7 +315,7 @@
self.site.language() == 'nn' or
(interwikiLinks and hasCommentLine) and
self.site.language() == 'fr'):
- text = text + '\r\n\r\n' + iw_msg
+ text += '\r\n\r\n' + iw_msg
# Adding stars templates
if allstars:
text = text.strip()+self.site.family.interwiki_text_separator
@@ -731,7 +727,7 @@
old = digits[digits.keys()[0]]
# do not change inside file links
namespaces = list(self.site.namespace(6, all=True))
- pattern = re.compile(u'\[\[(' + '|'.join(namespaces) + '):.+?\.\w+? *(\|[^\[]*?(\[\[[^\[]*?\]\][^\[]*?)?)?\]\]',
+ pattern = re.compile(u'\[\[(' + '|'.join(namespaces) + '):.+?\.\w+? *(\|((\[\[.*?\]\])|.)*)?\]\]',
re.UNICODE)
exceptions.append(pattern)
text = pywikibot.replaceExcept(text, u',', u'،', exceptions)
@@ -744,7 +740,7 @@
text = pywikibot.replaceExcept(text, u'ك', u'ک', exceptions)
text = pywikibot.replaceExcept(text, ur'[ىي]', u'ی', exceptions)
# replace persian/arabic digits
- for i in xrange(0,10):
+ for i in xrange(0, 10):
text = pywikibot.replaceExcept(text, old[i], new[i], exceptions)
# do not change digits in class, style and table params
pattern = re.compile(u'\w+=(".+?"|\d+)', re.UNICODE)
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10426
Revision: 10426
Author: xqt
Date: 2012-06-28 07:49:49 +0000 (Thu, 28 Jun 2012)
Log Message:
-----------
invalid replacements inside file links; fix for bug #3538506
update from trunk r10425
Modified Paths:
--------------
branches/rewrite/scripts/cosmetic_changes.py
Modified: branches/rewrite/scripts/cosmetic_changes.py
===================================================================
--- branches/rewrite/scripts/cosmetic_changes.py 2012-06-28 06:55:52 UTC (rev 10425)
+++ branches/rewrite/scripts/cosmetic_changes.py 2012-06-28 07:49:49 UTC (rev 10426)
@@ -741,8 +741,8 @@
# This only works if there are only two items in digits dict
old = digits[digits.keys()[0]]
# do not change inside file links
- namespaces = list(self.site.namespace(6, all = True))
- pattern = re.compile(u'\[\[(' + '|'.join(namespaces) + '):.+?\..+?\]\]',
+ namespaces = list(self.site.namespace(6, all=True))
+ pattern = re.compile(u'\[\[(' + '|'.join(namespaces) + '):.+?\.\w+? *(\|[^\[]*?(\[\[[^\[]*?\]\][^\[]*?)?)?\]\]',
re.UNICODE)
exceptions.append(pattern)
text = pywikibot.replaceExcept(text, u',', u'،', exceptions)
@@ -754,8 +754,8 @@
text = pywikibot.replaceExcept(text, u'ه', u'ھ', exceptions)
text = pywikibot.replaceExcept(text, u'ك', u'ک', exceptions)
text = pywikibot.replaceExcept(text, ur'[ىي]', u'ی', exceptions)
- # replace persian digits
- for i in range(0,10):
+ # replace persian/arabic digits
+ for i in xrange(0,10):
text = pywikibot.replaceExcept(text, old[i], new[i], exceptions)
# do not change digits in class, style and table params
pattern = re.compile(u'\w+=(".+?"|\d+)', re.UNICODE)
@@ -764,7 +764,8 @@
pattern = re.compile(u'<[/]*?[^</]+?[/]*?>', re.UNICODE)
exceptions.append(pattern)
exceptions.append('table') #exclude tables for now
- for i in range(0,10):
+ # replace digits
+ for i in xrange(0, 10):
text = pywikibot.replaceExcept(text, str(i), new[i], exceptions)
return text
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10425
Revision: 10425
Author: xqt
Date: 2012-06-28 06:55:52 +0000 (Thu, 28 Jun 2012)
Log Message:
-----------
invalid replacements inside file links; fix for bug #3538506
Modified Paths:
--------------
trunk/pywikipedia/cosmetic_changes.py
Modified: trunk/pywikipedia/cosmetic_changes.py
===================================================================
--- trunk/pywikipedia/cosmetic_changes.py 2012-06-26 21:18:08 UTC (rev 10424)
+++ trunk/pywikipedia/cosmetic_changes.py 2012-06-28 06:55:52 UTC (rev 10425)
@@ -208,6 +208,7 @@
old instances standardizeInterwiki and standardizeCategories
The page footer has the following section in that sequence:
1. categories
+ 2a TODO:template beyond categories
2. additional information depending on local site policy
3. stars templates for featured and good articles
4. interwiki links
@@ -729,8 +730,8 @@
# This only works if there are only two items in digits dict
old = digits[digits.keys()[0]]
# do not change inside file links
- namespaces = list(self.site.namespace(6, all = True))
- pattern = re.compile(u'\[\[(' + '|'.join(namespaces) + '):.+?\..+?\]\]',
+ namespaces = list(self.site.namespace(6, all=True))
+ pattern = re.compile(u'\[\[(' + '|'.join(namespaces) + '):.+?\.\w+? *(\|[^\[]*?(\[\[[^\[]*?\]\][^\[]*?)?)?\]\]',
re.UNICODE)
exceptions.append(pattern)
text = pywikibot.replaceExcept(text, u',', u'،', exceptions)
@@ -742,8 +743,8 @@
text = pywikibot.replaceExcept(text, u'ه', u'ھ', exceptions)
text = pywikibot.replaceExcept(text, u'ك', u'ک', exceptions)
text = pywikibot.replaceExcept(text, ur'[ىي]', u'ی', exceptions)
- # replace persian digits
- for i in range(0,10):
+ # replace persian/arabic digits
+ for i in xrange(0,10):
text = pywikibot.replaceExcept(text, old[i], new[i], exceptions)
# do not change digits in class, style and table params
pattern = re.compile(u'\w+=(".+?"|\d+)', re.UNICODE)
@@ -752,13 +753,14 @@
pattern = re.compile(u'<[/]*?[^</]+?[/]*?>', re.UNICODE)
exceptions.append(pattern)
exceptions.append('table') #exclude tables for now
+ # replace digits
+ for i in xrange(0, 10):
+ text = pywikibot.replaceExcept(text, str(i), new[i], exceptions)
##fixing pipe and trailing for fa. Thanks ZxxZxxZ
if self.site.lang=='fa':
faChrs = u'ءاآأإئؤبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهیةيك' + u'ًٌٍَُِّْٓٔ'
text = re.sub(u'\[\[([^\]\|]*)]]([%s]+)' % faChrs, ur'[[\1|\1\2]]', text)
text = re.sub(u'\[\[([^\]\|]*)\|(.+?)]]([%s]+)' % faChrs, ur'[[\1|\2\3]]', text)
- for i in range(0,10):
- text = pywikibot.replaceExcept(text, str(i), new[i], exceptions)
return text
# Retrieved from "http://commons.wikimedia.org/wiki/Commons:Tools/pywiki_file_description_cle…"
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10423
Revision: 10423
Author: valhallasw
Date: 2012-06-26 19:12:25 +0000 (Tue, 26 Jun 2012)
Log Message:
-----------
Terminal_interface improvements when using a dumb console
- allow output of non-errors to stdout while keeping errors in stderr
- do not use getpass when stdin is not a tty (so that it will crash instead
of hang when called with an emptyy stdin, such as in cron)
Modified Paths:
--------------
branches/rewrite/pywikibot/bot.py
branches/rewrite/pywikibot/config2.py
branches/rewrite/pywikibot/userinterfaces/terminal_interface.py
Modified: branches/rewrite/pywikibot/bot.py
===================================================================
--- branches/rewrite/pywikibot/bot.py 2012-06-26 19:10:02 UTC (rev 10422)
+++ branches/rewrite/pywikibot/bot.py 2012-06-26 19:12:25 UTC (rev 10423)
@@ -144,7 +144,7 @@
root_logger.handlers = [] # remove any old handlers
# configure handler(s) for display to user interface
- ui.init_handlers(root_logger)
+ ui.init_handlers(root_logger, **config.userinterface_init_kwargs)
# if user has enabled file logging, configure file handler
if moduleName in config.log or '*' in config.log:
Modified: branches/rewrite/pywikibot/config2.py
===================================================================
--- branches/rewrite/pywikibot/config2.py 2012-06-26 19:10:02 UTC (rev 10422)
+++ branches/rewrite/pywikibot/config2.py 2012-06-26 19:12:25 UTC (rev 10423)
@@ -178,6 +178,11 @@
# tkinter isn't yet ready
userinterface = 'terminal'
+# this can be used to pass variables to the UI init function
+# useful for e.g.
+# userinterface_init_kwargs = {'default_stream': 'stdout'}
+userinterface_init_kwargs = {}
+
# i18n setting for user interface language
# default is config.mylang or 'en'
userinterface_lang = None
Modified: branches/rewrite/pywikibot/userinterfaces/terminal_interface.py
===================================================================
--- branches/rewrite/pywikibot/userinterfaces/terminal_interface.py 2012-06-26 19:10:02 UTC (rev 10422)
+++ branches/rewrite/pywikibot/userinterfaces/terminal_interface.py 2012-06-26 19:12:25 UTC (rev 10423)
@@ -116,7 +116,7 @@
colorTagR = re.compile('\03{(?P<name>%s)}' % '|'.join(windowsColors.keys()))
class UI(object):
- def init_handlers(self, root_logger):
+ def init_handlers(self, root_logger, default_stream=sys.stderr):
"""Initialize the handlers for user output.
This method initializes handler(s) for output levels VERBOSE (if
@@ -125,8 +125,14 @@
others write theirs to sys.stderr.
"""
+
+ if default_stream == 'stdout':
+ default_stream = sys.stdout
+ elif default_stream == 'stderr':
+ default_stream = sys.stderr
+
# default handler for display to terminal
- default_handler = TerminalHandler(strm=sys.stderr)
+ default_handler = TerminalHandler(strm=default_stream)
if config.verbose_output:
default_handler.setLevel(VERBOSE)
else:
@@ -172,7 +178,7 @@
try:
pywikibot.logoutput(question + ' ', newline=False,
_level=pywikibot.INPUT)
- if password:
+ if password and sys.stdin.isatty():
import getpass
text = getpass.getpass('')
# See PYWP-13 / http://bugs.python.org/issue11236