Revision: 7874
Author: xqt
Date: 2010-01-13 07:15:42 +0000 (Wed, 13 Jan 2010)
Log Message:
-----------
Update from rewrite
Modified Paths:
--------------
trunk/pywikipedia/date.py
trunk/pywikipedia/families/mac_wikia_family.py
trunk/pywikipedia/families/meta_family.py
trunk/pywikipedia/families/strategy_family.py
trunk/pywikipedia/families/wikipedia_family.py
trunk/pywikipedia/families/wowwiki_family.py
trunk/pywikipedia/family.py
trunk/pywikipedia/login.py
trunk/pywikipedia/pagegenerators.py
trunk/pywikipedia/userlib.py
Modified: trunk/pywikipedia/date.py
===================================================================
--- trunk/pywikipedia/date.py 2010-01-13 07:10:29 UTC (rev 7873)
+++ trunk/pywikipedia/date.py 2010-01-13 07:15:42 UTC (rev 7874)
@@ -19,7 +19,6 @@
import re
import wikipedia
-
#
# Different collections of well known formats
#
@@ -147,7 +146,6 @@
return dh_noConv( value, pattern, formatLimits['MillenniumBC'][0] )
-
def decSinglVal( v ):
return v[0]
@@ -199,34 +197,34 @@
to accept all other values"""
return True
-def monthName(lang,ind):
+def monthName(lang, ind):
return formats['MonthName'][lang](ind)
# Helper for KN: digits representation
-_knDigits=u'೦೧೨೩೪೫೬೭೮೯'
-_knDigitsToLocal=dict([(ord(unicode(i)), _knDigits[i]) for i in range(10)])
-_knLocalToDigits=dict([(ord(_knDigits[i]), unicode(i)) for i in range(10)])
+_knDigits = u'೦೧೨೩೪೫೬೭೮೯'
+_knDigitsToLocal = dict([(ord(unicode(i)), _knDigits[i]) for i in range(10)])
+_knLocalToDigits = dict([(ord(_knDigits[i]), unicode(i)) for i in range(10)])
# Helper for Urdu/Persian languages
-_faDigits=u'۰۱۲۳۴۵۶۷۸۹'
-_faDigitsToLocal=dict([(ord(unicode(i)), _faDigits[i]) for i in range(10)])
-_faLocalToDigits=dict([(ord(_faDigits[i]), unicode(i)) for i in range(10)])
+_faDigits = u'۰۱۲۳۴۵۶۷۸۹'
+_faDigitsToLocal = dict([(ord(unicode(i)), _faDigits[i]) for i in range(10)])
+_faLocalToDigits = dict([(ord(_faDigits[i]), unicode(i)) for i in range(10)])
# Helper for HI:, MR:
-_hiDigits=u'०१२३४५६७८९'
-_hiDigitsToLocal=dict([(ord(unicode(i)), _hiDigits[i]) for i in range(10)])
-_hiLocalToDigits=dict([(ord(_hiDigits[i]), unicode(i)) for i in range(10)])
+_hiDigits = u'०१२३४५६७८९'
+_hiDigitsToLocal = dict([(ord(unicode(i)), _hiDigits[i]) for i in range(10)])
+_hiLocalToDigits = dict([(ord(_hiDigits[i]), unicode(i)) for i in range(10)])
# Helper for BN:
-_bnDigits=u'০১২৩৪৫৬৭৮৯'
-_bnDigitsToLocal=dict([(ord(unicode(i)), _bnDigits[i]) for i in range(10)])
-_bnLocalToDigits=dict([(ord(_bnDigits[i]), unicode(i)) for i in range(10)])
+_bnDigits = u'০১২৩৪৫৬৭৮৯'
+_bnDigitsToLocal = dict([(ord(unicode(i)), _bnDigits[i]) for i in range(10)])
+_bnLocalToDigits = dict([(ord(_bnDigits[i]), unicode(i)) for i in range(10)])
# Helper for GU:
-_guDigits=u'૦૧૨૩૪૫૬૭૮૯'
-_guDigitsToLocal=dict([(ord(unicode(i)), _guDigits[i]) for i in range(10)])
-_guLocalToDigits=dict([(ord(_guDigits[i]), unicode(i)) for i in range(10)])
+_guDigits = u'૦૧૨૩૪૫૬૭૮૯'
+_guDigitsToLocal = dict([(ord(unicode(i)), _guDigits[i]) for i in range(10)])
+_guLocalToDigits = dict([(ord(_guDigits[i]), unicode(i)) for i in range(10)])
def intToLocalDigitsStr( value, digitsToLocalDict ):
# Encode an integer value into a textual form.
@@ -279,7 +277,7 @@
'T' : ( _decimalDigits, lambda v: unicode(v+543), lambda v: int(v)-543 ),
}
-# Allows to search for '(%%)|(%d)|(%R)|...", and allows one digit 1-9 too set
the size of zero-padding for numbers
+# Allows to search for '(%%)|(%d)|(%R)|...", and allows one digit 1-9 to set
the size of zero-padding for numbers
_reParameters = re.compile(u'|'.join([ u'(%%[1-9]?%s)' % s for s in
_digitDecoders.keys() ]))
# A map of sitecode+pattern to (re matching object and corresponding
decoders)
@@ -301,7 +299,7 @@
for s in _reParameters.split(pattern):
if s is None:
pass
- elif len(s) in [2,3] and s[0]=='%' and s[-1] in _digitDecoders and
(len(s)==2 or s[1] in _decimalDigits):
+ elif len(s) in [2, 3] and s[0] == '%' and s[-1] in _digitDecoders
and (len(s) == 2 or s[1] in _decimalDigits):
# Must match a "%2d" or "%d" style
dec = _digitDecoders[s[-1]]
if type(dec) in _stringTypes:
@@ -741,7 +739,7 @@
'ca' : lambda m: multi( m, [
(lambda v: dh_decAD( v, u'Dècada de %d' ), lambda p: p == 1970),
(lambda v: dh_decAD( v, u'Dècada del %d' ), alwaysTrue)]),
-
+
#1970s => '1970-1979'
'cs' : lambda m: multi( m, [
(lambda v: dh_constVal( v, 1, u'1-9'),
lambda p: p == 1),
@@ -1033,29 +1031,29 @@
(lambda v: dh_centuryBC( v, u'%dde eeu v.C.' ),
alwaysTrue)]),
'bg' : lambda v: dh_centuryBC( v, u'%d век пр.н.е.' ),
'br' : lambda m: multi( m, [
- (lambda v: dh_constVal( v, 1, u'Iañ kantved kt JK'),
lambda p: p == 1),
- (lambda v: dh_constVal( v, 2, u'Eil kantved kt JK'),
lambda p: p == 2),
- (lambda v: dh_centuryBC( v, u'%Re kantved kt JK'),
lambda p: p in [2,3]),
- (lambda v: dh_centuryBC( v, u'%Rvet kantved kt JK'),
alwaysTrue)]),
+ (lambda v: dh_constVal( v, 1, u'Iañ kantved kt JK'), lambda
p: p == 1),
+ (lambda v: dh_constVal( v, 2, u'Eil kantved kt JK'), lambda
p: p == 2),
+ (lambda v: dh_centuryBC( v, u'%Re kantved kt JK'), lambda
p: p in [2,3]),
+ (lambda v: dh_centuryBC( v, u'%Rvet kantved kt JK'),
alwaysTrue)]),
'ca' : lambda v: dh_centuryBC( v, u'Segle %R aC' ),
'cs' : lambda v: dh_centuryBC( v, u'%d. století př. n. l.' ),
'da' : lambda v: dh_centuryBC( v, u'%d. århundrede f.Kr.' ),
'de' : lambda v: dh_centuryBC( v, u'%d. Jahrhundert v. Chr.' ),
'el' : lambda v: dh_centuryBC( v, u'%dος αιώνας π.Χ.' ),
'en' : lambda m: multi( m, [
- (lambda v: dh_centuryBC( v, u'%dst century BC' ),
lambda p: p == 1 or (p > 20 and p%10 == 1)),
- (lambda v: dh_centuryBC( v, u'%dnd century BC' ),
lambda p: p == 2 or (p > 20 and p%10 == 2)),
- (lambda v: dh_centuryBC( v, u'%drd century BC' ),
lambda p: p == 3 or (p > 20 and p%10 == 3)),
- (lambda v: dh_centuryBC( v, u'%dth century BC' ),
alwaysTrue)]),
+ (lambda v: dh_centuryBC( v, u'%dst century BC' ), lambda
p: p == 1 or (p > 20 and p%10 == 1)),
+ (lambda v: dh_centuryBC( v, u'%dnd century BC' ), lambda
p: p == 2 or (p > 20 and p%10 == 2)),
+ (lambda v: dh_centuryBC( v, u'%drd century BC' ), lambda
p: p == 3 or (p > 20 and p%10 == 3)),
+ (lambda v: dh_centuryBC( v, u'%dth century BC' ),
alwaysTrue)]),
'eo' : lambda v: dh_centuryBC( v, u'%d-a jarcento a.K.' ),
'es' : lambda v: dh_centuryBC( v, u'Siglo %R adC' ),
'et' : lambda v: dh_centuryBC( v, u'%d. aastatuhat eKr' ),
'fi' : lambda m: multi( m, [
- (lambda v: dh_constVal( v, 1, u'Ensimmäinen vuosisata eaa.'),
lambda p: p == 1),
- (lambda v: dh( v, u'%d00-luku eaa.', lambda i: i-1, lambda ii:
ii[0]+1 ), alwaysTrue)]),
+ (lambda v: dh_constVal( v, 1, u'Ensimmäinen vuosisata eaa.'),
lambda p: p == 1),
+ (lambda v: dh( v, u'%d00-luku eaa.', lambda i: i-1, lambda ii:
ii[0]+1 ), alwaysTrue)]),
'fr' : lambda m: multi( m, [
- (lambda v: dh_centuryBC( v, u'%Rer siècle av. J.-C.' ),
lambda p: p == 1),
- (lambda v: dh_centuryBC( v, u'%Re siècle av. J.-C.' ),
alwaysTrue)]),
+ (lambda v: dh_centuryBC( v, u'%Rer siècle av. J.-C.' ),
lambda p: p == 1),
+ (lambda v: dh_centuryBC( v, u'%Re siècle av. J.-C.' ),
alwaysTrue)]),
'he' : lambda v: dh_centuryBC( v, u'המאה ה־%d לפני הספירה' ),
'hr' : lambda v: dh_centuryBC( v, u'%d. stoljeće p.n.e.' ),
'id' : lambda v: dh_centuryBC( v, u'Abad ke-%d SM' ),
@@ -1491,21 +1489,21 @@
# In addition, tuple contains start, end, and step values that will be used to
test the formats table for internal consistency.
#
formatLimits = {
- 'MonthName' : (lambda v: 1<=v and v<13, 1,13),
- 'Number' : (lambda v: 0<=v and v<1000000, 0,1001),
+ 'MonthName' : (lambda v: 1 <=v and v < 13, 1, 13),
+ 'Number' : (lambda v: 0 <=v and v < 1000000, 0,
1001),
- 'YearAD' : (lambda v: 0<=v and v<2501, 0,2501),
- 'YearBC' : (lambda v: 0<=v and v<4001, 0,501),
# zh: has years as old as 前1700年
- 'DecadeAD' : (lambda v: 0<=v and v<2501, 0,2501),
# At some point need to re-add "and v%10==0" to the limitation
- 'DecadeBC' : (lambda v: 0<=v and v<4001, 0,501),
# zh: has decades as old as 前1700年代
- 'CenturyAD' : (lambda v: 1<=v and v<41, 1,23),
# Some centuries use Roman numerals or a given list - do not exceed them in
testing
- 'CenturyBC' : (lambda v: 1<=v and v<91, 1,23),
# Some centuries use Roman numerals or a given list - do not exceed them in
testing
- 'MillenniumAD' : (lambda v: 1<=v and v<6, 1,4),
# For milleniums, only test first 3 AD Milleniums,
- 'MillenniumBC' : (lambda v: 1<=v and v<20, 1,2),
# And only 1 BC Millenium
- 'CenturyAD_Cat' : (lambda v: 1<=v and v<41, 1,23),
# Some centuries use Roman numerals or a given list - do not exceed them in
testing
- 'CenturyBC_Cat' : (lambda v: 1<=v and v<41, 1,23),
# Some centuries use Roman numerals or a given list - do not exceed them in
testing
- 'Cat_Year_MusicAlbums' : (lambda v: 1950<=v and v<2021,
1950,2021),
- 'CurrEvents' : (lambda v: 0<=v and v<1, 0,1),
+ 'YearAD' : (lambda v: 0 <=v and v < 2501, 0,
2501),
+ 'YearBC' : (lambda v: 0 <=v and v < 4001, 0,
501), # zh: has years as old as 前1700年
+ 'DecadeAD' : (lambda v: 0 <=v and v < 2501, 0,
2501), # At some point need to re-add "and v%10==0" to the limitation
+ 'DecadeBC' : (lambda v: 0 <=v and v < 4001, 0,
501), # zh: has decades as old as 前1700年代
+ 'CenturyAD' : (lambda v: 1 <=v and v < 41, 1, 23),
# Some centuries use Roman numerals or a given list - do not exceed them in
testing
+ 'CenturyBC' : (lambda v: 1 <=v and v < 91, 1, 23),
# Some centuries use Roman numerals or a given list - do not exceed them in
testing
+ 'MillenniumAD' : (lambda v: 1 <=v and v < 6, 1, 4),
# For milleniums, only test first 3 AD Milleniums,
+ 'MillenniumBC' : (lambda v: 1 <=v and v < 20, 1, 2),
# And only 1 BC Millenium
+ 'CenturyAD_Cat' : (lambda v: 1 <=v and v < 41, 1, 23),
# Some centuries use Roman numerals or a given list - do not exceed them in
testing
+ 'CenturyBC_Cat' : (lambda v: 1 <=v and v < 41, 1, 23),
# Some centuries use Roman numerals or a given list - do not exceed them in
testing
+ 'Cat_Year_MusicAlbums' : (lambda v: 1950 <= v and v < 2021, 1950,
2021),
+ 'CurrEvents' : (lambda v: 0 <= v and v < 1, 0, 1),
}
# All month of year articles are in the same format
@@ -1517,7 +1515,7 @@
_formatLimit_DayOfMonth30 = (lambda v: 1 <= v and v < 31, 1, 31)
_formatLimit_DayOfMonth29 = (lambda v: 1 <= v and v < 30, 1, 30)
for monthId in range(12):
- if (monthId+1) in [1,3,5,7,8,10,12]:
+ if (monthId + 1) in [1, 3, 5, 7, 8, 10, 12]:
formatLimits[dayMnthFmts[monthId]] = _formatLimit_DayOfMonth31 #
31 days a month
elif (monthId+1) == 2: # February
formatLimits[dayMnthFmts[monthId]] = _formatLimit_DayOfMonth29 #
29 days a month
@@ -1567,8 +1565,6 @@
else:
return formats['YearAD'][lang](year)
-
-
#
#
# Map testing methods
@@ -1603,7 +1599,7 @@
for code, convFunc in formats[formatName].iteritems():
# import time
# startClock = time.clock()
- for value in range(start,stop,step):
+ for value in range(start, stop, step):
try:
if not predicate(value):
raise AssertionError(" Not a valid value for this
format.")
@@ -1618,11 +1614,14 @@
# wikipedia.output( u"%s\t%s\t%f" % (formatName, code, time.clock() -
startClock) )
def test(quick = False, showAll = False):
- """This is a test function, to be used interactivelly to test entire
format convesion map at once
+ """This is a test function, to be used interactively to test entire
+ format conversion map at once
+
Usage example:
run python interpreter
>>> import date
>>> date.test()
+
"""
for formatName in formats.keys():
Modified: trunk/pywikipedia/families/mac_wikia_family.py
===================================================================
--- trunk/pywikipedia/families/mac_wikia_family.py 2010-01-13 07:10:29 UTC
(rev 7873)
+++ trunk/pywikipedia/families/mac_wikia_family.py 2010-01-13 07:15:42 UTC
(rev 7874)
@@ -76,7 +76,7 @@
self.languages_by_size = ['en','de']
def version(self, code):
- return "1.10alpha"
+ return "1.14"
def scriptpath(self, code):
return ''
Modified: trunk/pywikipedia/families/meta_family.py
===================================================================
--- trunk/pywikipedia/families/meta_family.py 2010-01-13 07:10:29 UTC (rev
7873)
+++ trunk/pywikipedia/families/meta_family.py 2010-01-13 07:15:42 UTC (rev
7874)
@@ -133,7 +133,6 @@
'mediawiki', 'test', 'incubator', 'commons', 'species',
]
-
def version(self,code):
return '1.16alpha-wmf'
Modified: trunk/pywikipedia/families/strategy_family.py
===================================================================
--- trunk/pywikipedia/families/strategy_family.py 2010-01-13 07:10:29 UTC
(rev 7873)
+++ trunk/pywikipedia/families/strategy_family.py 2010-01-13 07:15:42 UTC
(rev 7874)
@@ -31,7 +31,6 @@
self.interwiki_forward = 'wikipedia'
-
def version(self, code):
return '1.16alpha-wmf'
Modified: trunk/pywikipedia/families/wikipedia_family.py
===================================================================
--- trunk/pywikipedia/families/wikipedia_family.py 2010-01-13 07:10:29 UTC
(rev 7873)
+++ trunk/pywikipedia/families/wikipedia_family.py 2010-01-13 07:15:42 UTC
(rev 7874)
@@ -1175,7 +1175,7 @@
def get_known_families(self, site):
# In Swedish Wikipedia 's:' is part of page title not a family
# prefix for 'wikisource'.
- if site.lang == 'sv':
+ if site.language() == 'sv':
d = self.known_families.copy()
d.pop('s') ; d['src'] = 'wikisource'
return d
Modified: trunk/pywikipedia/families/wowwiki_family.py
===================================================================
--- trunk/pywikipedia/families/wowwiki_family.py 2010-01-13 07:10:29 UTC
(rev 7873)
+++ trunk/pywikipedia/families/wowwiki_family.py 2010-01-13 07:15:42 UTC
(rev 7874)
@@ -28,8 +28,8 @@
'nl': 'nl.wow.wikia.com',
'no': 'no.wow.wikia.com',
'pl': 'pl.wow.wikia.com',
+ 'pt': 'pt.wow.wikia.com',
'pt-br': 'pt-br.wow.wikia.com',
- 'pt': 'pt.wow.wikia.com',
'ro': 'ro.wow.wikia.com',
'ru': 'ru.wow.wikia.com',
'sk': 'sk.wow.wikia.com',
Modified: trunk/pywikipedia/family.py
===================================================================
--- trunk/pywikipedia/family.py 2010-01-13 07:10:29 UTC (rev 7873)
+++ trunk/pywikipedia/family.py 2010-01-13 07:15:42 UTC (rev 7874)
@@ -2677,7 +2677,8 @@
},
}
- # letters that can follow a wikilink and are regarded as part of this
link
+ # letters that can follow a wikilink and are regarded as part
+ # of this link
# This depends on the linktrail setting in LanguageXx.php and on
# [[MediaWiki:Linktrail]].
# Note: this is a regular expression.
@@ -2710,6 +2711,8 @@
# for line in f.readlines():
# s = line[:line.index('\t')]
# print ((" '%s':" % s).ljust(20) + ("'%s'," % s))
+
+ # TODO: replace this with API interwikimap call
self.known_families = {
'abbenormal': 'abbenormal',
'aboutccc': 'aboutccc',
@@ -3157,7 +3160,7 @@
# a list of languages. If there are at least the number of interwiki
# links, all languages in the list should be placed at the front as
# well as in the normal list.
- self.interwiki_putfirst_doubled = {}
+ self.interwiki_putfirst_doubled = {} # THIS APPEARS TO BE UNUSED!
# Some families, e. g. commons and meta, are not multilingual and
# forward interlanguage links to another family (wikipedia).
@@ -3274,7 +3277,9 @@
elif fallback:
return self.linktrails[fallback]
else:
- raise KeyError('ERROR: linktrail in language %s unknown' % code)
+ raise KeyError(
+ "ERROR: linktrail in language %s unknown"
+ % code)
def namespace(self, code, ns_number, fallback = '_default', all = False):
if not self.isDefinedNS(ns_number):
@@ -3408,7 +3413,7 @@
return self.disambiguationTemplates[fallback]
else:
raise KeyError(
- 'ERROR: title for disambig template in language %s unknown'
+ "ERROR: title for disambig template in language %s unknown"
% code)
# Returns the title of the special namespace in language 'code', taken from
@@ -3912,6 +3917,16 @@
wiki"""
return self.code2encoding(code),
+ # aliases
+ def encoding(self, code):
+ """Return the encoding for a specific language wiki"""
+ return self.code2encoding(code)
+
+ def encodings(self, code):
+ """Return a list of historical encodings for a specific language
+ wiki"""
+ return self.code2encodings(code)
+
def __cmp__(self, otherfamily):
try:
return cmp(self.name, otherfamily.name)
@@ -3921,6 +3936,9 @@
def __hash__(self):
return hash(self.name)
+ def __repr__(self):
+ return 'Family("%s")' % self.name
+
def RversionTab(self, code):
"""Change this to some regular expression that shows the page we
found is an existing page, in case the normal regexp does not work."""
@@ -3940,7 +3958,7 @@
return datetime.utcnow() + self.servergmtoffset
def isPublic(self):
- """Does the wiki require logging in before viewing it ?"""
+ """Does the wiki require logging in before viewing it?"""
return True
def post_get_convert(self, site, getText):
Modified: trunk/pywikipedia/login.py
===================================================================
--- trunk/pywikipedia/login.py 2010-01-13 07:10:29 UTC (rev 7873)
+++ trunk/pywikipedia/login.py 2010-01-13 07:15:42 UTC (rev 7874)
@@ -1,11 +1,10 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-
"""
Script to log the robot in to a wiki account.
Suggestion is to make a special account to use for robot use only. Make
-sure this robot account is well known on your home wikipedia before using.
+sure this robot account is well known on your home wiki before using.
Parameters:
@@ -37,19 +36,20 @@
check the output. Using -log is recommended: this will output a
lot of data
-If not given as parameter, the script will ask for your username and password
-(password entry will be hidden), log in to your home wiki using this
-combination, and store the resulting cookies (containing your password hash,
+If not given as parameter, the script will ask for your username and
+password (password entry will be hidden), log in to your home wiki using
+this combination, and store the resulting cookies (containing your password
so keep it secured!) in a file in the login-data subdirectory.
-All scripts in this library will be looking for this cookie file and will use
-the login information if it is present.
+All scripts in this library will be looking for this cookie file and will
+use the login information if it is present.
To log out, throw away the XX-login.data file that is created in the login-data
subdirectory.
"""
#
# (C) Rob W.W. Hooft, 2003
+# (C) Pywikipedia bot team, 2003-2010
#
# Distributed under the terms of the MIT license.
#
@@ -80,11 +80,11 @@
wikipedia.output(u"You are not logged in on %s." % repr(mysite))
class LoginManager:
- def __init__(self, password = None, sysop = False, site = None,
username=None, verbose=False):
+ def __init__(self, password=None, sysop=False, site=None, username=None,
verbose=False):
self.site = site or wikipedia.getSite()
self.sysop = sysop
if username:
- self.username=username
+ self.username = username
# perform writeback.
if site.family.name not in config.usernames:
config.usernames[site.family.name]={}
@@ -92,7 +92,8 @@
else:
if sysop:
try:
- self.username =
config.sysopnames[self.site.family.name][self.site.lang]
+ self.username = config.sysopnames\
+ [self.site.family.name][self.site.lang]
except:
raise wikipedia.NoUsername(u'ERROR: Sysop username for
%s:%s is undefined.\nIf you have a sysop account for that site, please add such
a line to user-config.py:\n\nsysopnames[\'%s\'][\'%s\'] = \'myUsername\'' %
(self.site.family.name, self.site.lang, self.site.family.name, self.site.lang))
else:
@@ -110,7 +111,8 @@
Checks whether the bot is listed on a specific page to comply with
the policy on the respective wiki.
"""
- if self.site.family.name in botList and self.site.language() in
botList[self.site.family.name]:
+ if self.site.family.name in botList \
+ and self.site.language() in botList[self.site.family.name]:
botListPageTitle = wikipedia.translate(self.site.language(),
botList)
botListPage = wikipedia.Page(self.site, botListPageTitle)
for linkedPage in botListPage.linkedPages():
@@ -225,11 +227,12 @@
def storecookiedata(self, filename, data):
"""
- Stores cookie data.
+ Store cookie data.
The argument data is the raw data, as returned by getCookie().
- Returns nothing."""
+ Returns nothing.
+ """
s = u''
for v, k in data.iteritems():
s += "%s=%s\n" % (v, k)
@@ -239,8 +242,10 @@
def readPassword(self):
"""
- Reads passwords from a file. DO NOT FORGET TO REMOVE READ
- ACCESS FOR OTHER USERS!!! Use chmod 600 password-file.
+ Read passwords from a file.
+
+ DO NOT FORGET TO REMOVE READ ACCESS FOR OTHER USERS!!!
+ Use chmod 600 password-file.
All lines below should be valid Python tuples in the form
(code, family, username, password) or (username, password)
to set a default password for an username. Default usernames
@@ -252,8 +257,8 @@
("my_sysop_user", "my_sysop_password")
("en", "wikipedia", "my_en_user", "my_en_pass")
"""
- file = open(wikipedia.config.datafilepath(config.password_file), 'r')
- for line in file:
+ password_f = open(wikipedia.config.datafilepath(config.password_file),
'r')
+ for line in password_f:
if not line.strip(): continue
entry = eval(line)
if len(entry) == 2: #for default userinfo
@@ -263,13 +268,16 @@
entry[1] == self.site.family.name and \
entry[2] == self.username:
self.password = entry[3]
- file.close()
+ password_f.close()
def login(self, api = config.use_api_login, retry = False):
if not self.password:
# As we don't want the password to appear on the screen, we set
# password = True
- self.password = wikipedia.input(u'Password for user %s on %s:' %
(self.username, self.site), password = True)
+ self.password = wikipedia.input(
+ u'Password for user %s on %s:'
+ % (self.username, self.site),
+ password = True)
self.password = self.password.encode(self.site.encoding())
@@ -335,7 +343,8 @@
for arg in wikipedia.handleArgs():
if arg.startswith("-pass"):
if len(arg) == 5:
- password = wikipedia.input(u'Password for all accounts:',
password = True)
+ password = wikipedia.input(u'Password for all accounts:',
+ password = True)
else:
password = arg[6:]
elif arg == "-clean":
Modified: trunk/pywikipedia/pagegenerators.py
===================================================================
--- trunk/pywikipedia/pagegenerators.py 2010-01-13 07:10:29 UTC (rev 7873)
+++ trunk/pywikipedia/pagegenerators.py 2010-01-13 07:15:42 UTC (rev 7874)
@@ -15,26 +15,26 @@
"""
__version__='$Id$'
-parameterHelp = """\
+parameterHelp = u"""\
-cat Work on all pages which are in a specific category.
Argument can also be given as "-cat:categoryname" or
- as "-cat:categoryname#fromtitle" (using | instead of #
+ as "-cat:categoryname|fromtitle" (using # instead of |
is also allowed in this one and the following)
-catr Like -cat, but also recursively includes pages in
subcategories, sub-subcategories etc. of the
given category.
Argument can also be given as "-catr:categoryname" or
- as "-catr:categoryname#fromtitle".
+ as "-catr:categoryname|fromtitle".
-subcats Work on all subcategories of a specific category.
Argument can also be given as "-subcats:categoryname" or
- as "-subcats:categoryname#fromtitle".
+ as "-subcats:categoryname|fromtitle".
-subcatsr Like -subcats, but also includes sub-subcategories etc. of
the given category.
Argument can also be given as "-subcatsr:categoryname" or
- as "-subcatsr:categoryname#fromtitle".
+ as "-subcatsr:categoryname|fromtitle".
-uncat Work on all pages which are not categorised.
@@ -50,22 +50,12 @@
-filelinks Work on all pages that use a certain image/media file.
Argument can also be given as "-filelinks:filename".
--yahoo Work on all pages that are found in a Yahoo search.
- Depends on python module pYsearch. See yahoo_appid in
- config.py for instructions.
-
-search Work on all pages that are found in a MediaWiki search
across all namespaces.
--google Work on all pages that are found in a Google search.
- You need a Google Web API license key. Note that Google
- doesn't give out license keys anymore. See google_key in
- config.py for instructions.
- Argument can also be given as "-google:searchstring".
-
--namespace Filters the page generator to only yield pages in the
+-namespace Filter the page generator to only yield pages in the
specified namespaces. Separate multiple namespace
- numbers with commas.
+ numbers with commas. Example "-namespace:0,2,4"
-interwiki Work on the given page and all equivalent pages in other
languages. This can, for example, be used to fight
@@ -77,15 +67,20 @@
-links Work on all pages that are linked from a certain page.
Argument can also be given as "-links:linkingpagetitle".
--new Work on the 60 newest pages. If given as -new:x, will work
- on the x newest pages.
-
-imagelinks Work on all images that are linked from a certain page.
Argument can also be given as "-imagelinks:linkingpagetitle".
-newimages Work on the 100 newest images. If given as -newimages:x,
will work on the x newest images.
+-new Work on the 60 recent new pages. If given as -new:x,
+ will work on the x newest pages.
+
+-recentchanges Work on new and edited pages returned by
+ [[Special:Recentchanges]]. Can also be given as
+ "-recentchanges:n" where n is the number of pages to be
+ returned, else 100 pages are returned.
+
-ref Work on all pages that link to a certain page.
Argument can also be given as "-ref:referredpagetitle".
@@ -135,11 +130,6 @@
-gorandom Specifies that the robot should starting at the random pages
returned by [[Special:Random]].
--recentchanges Work on new and edited pages returned by
- [[Special:Recentchanges]]. Can also be given as
- "-recentchanges:n" where n is the number of pages to be
- returned, else 100 pages are returned.
-
-redirectonly Work on redirect pages only, not their target pages.
The robot goes alphabetically through all redirect pages
on the wiki, starting at the named page. The
@@ -148,15 +138,24 @@
You can also include a namespace. For example,
"-redirectonly:Template:!" will make the bot work on
all redirect pages in the template namespace.
+
+-google Work on all pages that are found in a Google search.
+ You need a Google Web API license key. Note that Google
+ doesn't give out license keys anymore. See google_key in
+ config.py for instructions.
+ Argument can also be given as "-google:searchstring".
+
+-yahoo Work on all pages that are found in a Yahoo search.
+ Depends on python module pYsearch. See yahoo_appid in
+ config.py for instructions.
"""
+docuReplacements = {'¶ms;': parameterHelp}
-docuReplacements = {
- '¶ms;': parameterHelp
-}
+
# Standard library imports
import re, codecs, sys
import threading, Queue, traceback
@@ -309,9 +308,10 @@
yield page
def InterwikiPageGenerator(page):
+ """Iterator over all interwiki (non-language) links on a page."""
yield page
- for iwPage in page.interwiki():
- yield iwPage
+ for link in page.interwiki():
+ yield link
def ReferringPageGenerator(referredPage, followRedirects=False,
withTemplateInclusion=True,
@@ -333,9 +333,10 @@
If start is a string value, only pages whose title comes after start
alphabetically are included.
'''
- for page in category.articles(recurse = recurse, startFrom = start):
- if page.title() >= start:
- yield page
+ # TODO: page generator could be modified to use cmstartsortkey ...
+ for a in category.articles(recurse = recurse, startFrom = start):
+ if start is None or a.title() >= start:
+ yield a
def SubCategoriesPageGenerator(category, recurse=False, start=None):
'''
@@ -345,9 +346,12 @@
recurse is an int, only subcategories to that depth will be included
(e.g., recurse=2 will get pages in subcats and sub-subcats, but will
not go any further).
+ If start is a string value, only categories whose sortkey comes after
+ start alphabetically are included.
'''
- for page in category.subcategories(recurse = recurse, startFrom = start):
- yield page
+ # TODO: page generator could be modified to use cmstartsortkey ...
+ for s in category.subcategories(recurse = recurse, startFrom = start):
+ yield s
def UnCategorizedCategoryGenerator(number = 100, repeat = False, site = None):
if site is None:
@@ -461,8 +465,8 @@
yield wikipedia.Page(site, title)
f.close()
-def PagesFromTitlesGenerator(iterable, site = None):
- """Generates pages from the titles (unicode strings) yielded by iterable"""
+def PagesFromTitlesGenerator(iterable, site=None):
+ """Generate pages from the titles (unicode strings) yielded by iterable."""
if site is None:
site = wikipedia.getSite()
for title in iterable:
Modified: trunk/pywikipedia/userlib.py
===================================================================
--- trunk/pywikipedia/userlib.py 2010-01-13 07:10:29 UTC (rev 7873)
+++ trunk/pywikipedia/userlib.py 2010-01-13 07:15:42 UTC (rev 7874)
@@ -2,6 +2,11 @@
"""
Library to work with users, their pages and talk pages.
"""
+#
+# (C) Pywikipedia bot team, 2008-2010
+#
+# Distributed under the terms of the MIT license.
+#
__version__ = '$Id$'
import re
_______________________________________________
Pywikipedia-svn mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikipedia-svn