Revision: 5121 Author: russblau Date: 2008-03-11 17:16:43 +0000 (Tue, 11 Mar 2008)
Log Message: ----------- More Site methods; add (incomplete) tests for Page and Link objects; merge families to trunk.
Modified Paths: -------------- branches/rewrite/pywikibot/config.py branches/rewrite/pywikibot/data/api.py branches/rewrite/pywikibot/families/commons_family.py branches/rewrite/pywikibot/families/incubator_family.py branches/rewrite/pywikibot/families/mediawiki_family.py branches/rewrite/pywikibot/families/meta_family.py branches/rewrite/pywikibot/families/species_family.py branches/rewrite/pywikibot/families/test_family.py branches/rewrite/pywikibot/families/uncyclopedia_family.py branches/rewrite/pywikibot/families/wikibooks_family.py branches/rewrite/pywikibot/families/wikinews_family.py branches/rewrite/pywikibot/families/wikipedia_family.py branches/rewrite/pywikibot/families/wikiquote_family.py branches/rewrite/pywikibot/families/wikisource_family.py branches/rewrite/pywikibot/families/wikiversity_family.py branches/rewrite/pywikibot/families/wiktionary_family.py branches/rewrite/pywikibot/page.py branches/rewrite/pywikibot/site.py
Added Paths: ----------- branches/rewrite/pywikibot/families/__init__.py branches/rewrite/pywikibot/tests/page_tests.py
Modified: branches/rewrite/pywikibot/config.py =================================================================== --- branches/rewrite/pywikibot/config.py 2008-03-10 13:53:14 UTC (rev 5120) +++ branches/rewrite/pywikibot/config.py 2008-03-11 17:16:43 UTC (rev 5121) @@ -103,7 +103,7 @@ base_dir = os.path.split( __sys.modules['wikipediatools'].__file__)[0] except KeyError: - print sys.modules + print __sys.modules base_dir = '.' if not os.path.isabs(base_dir): base_dir = os.path.normpath(os.path.join(os.getcwd(), base_dir))
Modified: branches/rewrite/pywikibot/data/api.py =================================================================== --- branches/rewrite/pywikibot/data/api.py 2008-03-10 13:53:14 UTC (rev 5120) +++ branches/rewrite/pywikibot/data/api.py 2008-03-11 17:16:43 UTC (rev 5121) @@ -87,8 +87,7 @@
""" def __init__(self, **kwargs): - self.site = kwargs.pop("site", None) - # else use defaultSite() ... when written + self.site = kwargs.pop("site", pywikibot.Site()) self.max_retries = kwargs.pop("max_retries", 25) self.retry_wait = kwargs.pop("retry_wait", 5) self.params = {} @@ -242,10 +241,10 @@ # method that converts the dict info to a Page object if isinstance(query["pages"], dict): for v in query["pages"].itervalues(): - yield pywikibot.Page(self.site, v['title']) + yield self.make_page(v) elif isinstance(query["pages"], list): for v in query["pages"]: - yield pywikibot.Page(self.site, v['title']) + yield self.make_page(v) else: raise APIError("Unknown", "Unknown format in ['query']['pages'] value.", @@ -259,7 +258,19 @@ self.request.update(self.data["query-continue"][self.generator]) del self.data
+ def make_page(self, pagedata): + """Convert page dict entry from api to Page object.""" + p = pywikibot.Page(self.site, pagedata['title'], pagedata['ns']) + if 'lastrevid' in pagedata: + p._revid = pagedata['lastrevid'] + if 'touched' in pagedata: + p._timestamp = pagedata['touched'] + if 'protection' in pagedata: + for item in pagedata['protection']: + p._protection[item['key']] = item['level'] + return p
+ class LoginManager(login.LoginManager): """Supplies getCookie() method to use API interface.""" def getCookie(self, remember=True, captchaId=None, captchaAnswer=None):
Added: branches/rewrite/pywikibot/families/__init__.py ===================================================================
Modified: branches/rewrite/pywikibot/families/commons_family.py =================================================================== --- branches/rewrite/pywikibot/families/commons_family.py 2008-03-10 13:53:14 UTC (rev 5120) +++ branches/rewrite/pywikibot/families/commons_family.py 2008-03-11 17:16:43 UTC (rev 5121) @@ -30,7 +30,7 @@ self.interwiki_forward = 'wikipedia'
def version(self, code): - return "1.12alpha" + return '1.13alpha'
def shared_image_repository(self, code): return ('commons', 'commons')
Modified: branches/rewrite/pywikibot/families/incubator_family.py =================================================================== --- branches/rewrite/pywikibot/families/incubator_family.py 2008-03-10 13:53:14 UTC (rev 5120) +++ branches/rewrite/pywikibot/families/incubator_family.py 2008-03-11 17:16:43 UTC (rev 5121) @@ -28,7 +28,7 @@ }
def version(self, code): - return "1.12alpha" + return '1.13alpha'
def shared_image_repository(self, code): return ('commons', 'commons')
Modified: branches/rewrite/pywikibot/families/mediawiki_family.py =================================================================== --- branches/rewrite/pywikibot/families/mediawiki_family.py 2008-03-10 13:53:14 UTC (rev 5120) +++ branches/rewrite/pywikibot/families/mediawiki_family.py 2008-03-11 17:16:43 UTC (rev 5121) @@ -36,7 +36,7 @@ }
def version(self, code): - return "1.12alpha" + return '1.13alpha'
def shared_image_repository(self, code): return ('commons', 'commons')
Modified: branches/rewrite/pywikibot/families/meta_family.py =================================================================== --- branches/rewrite/pywikibot/families/meta_family.py 2008-03-10 13:53:14 UTC (rev 5120) +++ branches/rewrite/pywikibot/families/meta_family.py 2008-03-11 17:16:43 UTC (rev 5121) @@ -126,7 +126,7 @@ self.interwiki_forward = 'wikipedia'
def version(self,code): - return "1.12alpha" + return '1.13alpha'
def shared_image_repository(self, code): return ('commons', 'commons')
Modified: branches/rewrite/pywikibot/families/species_family.py =================================================================== --- branches/rewrite/pywikibot/families/species_family.py 2008-03-10 13:53:14 UTC (rev 5120) +++ branches/rewrite/pywikibot/families/species_family.py 2008-03-11 17:16:43 UTC (rev 5121) @@ -24,7 +24,7 @@ self.interwiki_forward = 'wikipedia'
def version(self,code): - return "1.12alpha" + return '1.13alpha'
def shared_image_repository(self, code): return ('commons', 'commons')
Modified: branches/rewrite/pywikibot/families/test_family.py =================================================================== --- branches/rewrite/pywikibot/families/test_family.py 2008-03-10 13:53:14 UTC (rev 5120) +++ branches/rewrite/pywikibot/families/test_family.py 2008-03-11 17:16:43 UTC (rev 5121) @@ -122,7 +122,7 @@ }
def version(self, code): - return "1.12alpha" + return '1.13alpha'
def shared_image_repository(self, code): return ('commons', 'commons')
Modified: branches/rewrite/pywikibot/families/uncyclopedia_family.py =================================================================== --- branches/rewrite/pywikibot/families/uncyclopedia_family.py 2008-03-10 13:53:14 UTC (rev 5120) +++ branches/rewrite/pywikibot/families/uncyclopedia_family.py 2008-03-11 17:16:43 UTC (rev 5121) @@ -55,208 +55,476 @@ self.namespaces[1] = { '_default': u'Talk', 'ar': u'نقاش', + 'ast': u'Discusión', 'ca': u'Discussió', + 'cs': u'Diskuse', 'da': u'Diskussion', 'de': u'Diskussion', 'el': u'Συζήτηση', 'en': u'Talk', + 'eo': u'Diskuto', 'es': u'Discusión', + 'fa': u'بحث', 'fi': u'Keskustelu', 'fr': u'Discuter', 'he': u'שיחה', + 'hr': u'Razgovor', + 'hu': u'Vita', + 'id': u'Pembicaraan', 'it': u'Discussione', + 'ko': u'토론', 'la': u'Disputatio', + 'lt': u'Aptarimas', + 'lv': u'Diskusija', + 'nl': u'Overleg', + 'nn': u'Diskusjon', 'no': u'Diskusjon', 'pl': u'Dyskusja', 'pt': u'Discussão', 'ru': u'Обсуждение', + 'sk': u'Diskusia', + 'sl': u'Pogovor', + 'sr': u'Разговор', 'sv': u'Diskussion', + 'th': u'พูดคุย', + 'tr': u'Tartışma', + 'yi': u'רעדן', + 'zh-hk': u'討論', 'zh-tw': u'討論', }
self.namespaces[2] = { '_default': u'User', 'ar': u'مستخدم', + 'ast': u'Usuariu', 'ca': u'Usuari', + 'cs': u'Uživatel', 'da': u'Bruger', 'de': u'Benutzer', 'el': u'Χρήστης', 'en': u'User', + 'eo': u'Vikipediisto', 'es': u'Usuario', + 'fa': u'کاربر', 'fi': u'Käyttäjä', 'fr': u'Utilisateur', 'he': u'משתמש', + 'hr': u'Suradnik', + 'id': u'Pengguna', 'it': u'Utente', + 'ja': u'利用者', + 'ko': u'사용자', 'la': u'Usor', + 'lt': u'Naudotojas', + 'lv': u'Lietotājs', + 'nl': u'Gebruiker', + 'nn': u'Bruker', 'no': u'Bruker', 'pl': u'Użytkownik', 'pt': u'Usuário', 'ru': u'Участник', + 'sk': u'Redaktor', + 'sl': u'Uporabnik', + 'sr': u'Корисник', 'sv': u'Användare', + 'th': u'ผู้ใช้', + 'tr': u'Kullanıcı', + 'yi': u'באַניצער', + 'zh-hk': u'用戶', 'zh-tw': u'用戶', }
self.namespaces[3] = { '_default': u'User talk', 'ar': u'نقاش المستخدم', + 'ast': u'Usuariu discusión', 'ca': u'Usuari Discussió', - 'da': u'Bruger diskussion', + 'cs': u'Uživatel diskuse', + 'da': u'Brugerdiskussion', 'de': u'Benutzer Diskussion', 'el': u'Συζήτηση χρήστη', 'en': u'User talk', + 'eo': u'Vikipediista diskuto', 'es': u'Usuario Discusión', + 'fa': u'بحث کاربر', 'fi': u'Keskustelu käyttäjästä', 'fr': u'Discussion Utilisateur', 'he': u'שיחת משתמש', + 'hr': u'Razgovor sa suradnikom', + 'id': u'Pembicaraan Pengguna', 'it': u'Discussioni utente', + 'ja': u'利用者‐会話', + 'ko': u'사용자토론', 'la': u'Disputatio Usoris', + 'lt': u'Naudotojo aptarimas', + 'lv': u'Lietotāja diskusija', + 'nl': u'Overleg gebruiker', + 'nn': u'Brukerdiskusjon', 'no': u'Brukerdiskusjon', 'pl': u'Dyskusja użytkownika', 'pt': u'Usuário Discussão', 'ru': u'Обсуждение участника', + 'sk': u'Diskusia s redaktorom', + 'sl': u'Uporabniški pogovor', + 'sr': u'Разговор са корисником', 'sv': u'Användardiskussion', + 'th': u'คุยกับผู้ใช้', + 'tr': u'Kullanıcı mesaj', + 'yi': u'באַניצער רעדן', + 'zh-hk': u'用戶討論', 'zh-tw': u'用戶討論', }
self.namespaces[4] = { '_default': u'Uncyclopedia', - 'ar': u'ويكيبيديا', + 'ar': u'بيضيپيديا', + 'ast': u'Nunyepedia', 'ca': u'Valenciclopèdia', + 'cs': u'Necyklopedie', 'da': u'Spademanns Leksikon', 'de': u'Uncyclopedia', - 'el': u'Ανεγκυκλοπαίδεια', + 'el': u'Φρικηπαίδεια', 'en': u'Uncyclopedia', + 'eo': u'Neciklopedio', 'es': u'Inciclopedia', 'fi': u'Hikipedia', 'fr': u'Désencyclopédie', 'he': u'איןציקלופדיה', + 'hr': u'Neciklopedija', + 'hu': u'Unciklopédia', + 'id': u'Tolololpedia', 'it': u'Nonciclopedia', + 'ko': u'백괴사전', 'la': u'Uncapaedia', - 'no': u'Wikipedia', + 'lt': u'Nesamopedija Wiki', + 'lv': u'Neciklopēdija', + 'nl': u'Oncyclopedie', + 'nn': u'Ikkepedia', + 'no': u'Ikkepedia ', 'pl': u'Nonsensopedia', 'pt': u'Desciclopédia', 'ru': u'Абсурдопедия', - 'sv': u'Psykelopedia', + 'sk': u'Necyklopédia', + 'sl': u'Butalopedija', + 'sr': u'Нециклопедија', + 'sv': u'Psyklopedin', + 'th': u'ไร้สาระนุกรม', + 'tr': u'Yansiklopedi', + 'yi': u'קיינציקלאָפעדיע', 'zh': u'伪基百科', + 'zh-hk': u'偽基百科', 'zh-tw': u'偽基百科', } self.namespaces[5] = { '_default': u'Uncyclopedia talk', - 'ar': u'نقاش ويكيبيديا', + 'ar': u'نقاش بيضيپيديا', + 'ast': u'Nunyepedia discusión', 'ca': u'Valenciclopèdia Discussió', - 'da': u'Spademanns Leksikon diskussion', + 'cs': u'Necyklopedie diskuse', + 'da': u'Spademanns Leksikon-diskussion', 'de': u'Uncyclopedia Diskussion', - 'el': u'Ανεγκυκλοπαίδεια συζήτηση', + 'el': u'Φρικηπαίδεια συζήτηση', 'en': u'Uncyclopedia talk', + 'eo': u'Neciklopedio diskuto', 'es': u'Inciclopedia Discusión', + 'fa': u'بحث Uncyclopedia', 'fi': u'Keskustelu Hikipediasta', 'fr': u'Discussion Désencyclopédie', 'he': u'שיחת איןציקלופדיה', + 'hr': u'Razgovor Neciklopedija', + 'hu': u'Unciklopédia vita', + 'id': u'Pembicaraan Tolololpedia', 'it': u'Discussioni Nonciclopedia', + 'ko': u'백괴사전토론', 'la': u'Disputatio Uncapaediae', - 'no': u'Wikipedia-diskusjon', + 'lt': u'Nesamopedija Wiki aptarimas', + 'lv': u'Neciklopēdija diskusija', + 'nl': u'Overleg Oncyclopedie', + 'nn': u'Ikkepedia-diskusjon', + 'no': u'Ikkepedia -diskusjon', 'pl': u'Dyskusja Nonsensopedia', 'pt': u'Desciclopédia Discussão', 'ru': u'Обсуждение Абсурдопедии', - 'sv': u'Psykelopediadiskussion', + 'sk': u'Diskusia k Necyklopédia', + 'sl': u'Pogovor o Butalopedija', + 'sr': u'Разговор о Нециклопедија', + 'sv': u'Psyklopedindiskussion', + 'th': u'คุยเรื่องไร้สาระนุกรม', + 'tr': u'Yansiklopedi tartışma', + 'yi': u'קיינציקלאָפעדיע רעדן', 'zh': u'伪基百科 talk', + 'zh-hk': u'偽基百科討論', 'zh-tw': u'偽基百科討論', }
self.namespaces[6] = { '_default': u'Image', 'ar': u'صورة', + 'ast': u'Imaxen', 'ca': u'Imatge', + 'cs': u'Soubor', 'da': u'Billede', 'de': u'Bild', 'el': u'Εικόνα', + 'eo': u'Dosiero', 'es': u'Imagen', + 'fa': u'تصویر', 'fi': u'Kuva', 'he': u'תמונה', + 'hr': u'Slika', + 'hu': u'Kép', + 'id': u'Berkas', 'it': u'Immagine', + 'ko': u'그림', 'la': u'Imago', + 'lt': u'Vaizdas', + 'lv': u'Attēls', + 'nl': u'Afbeelding', + 'nn': u'Bilde', 'no': u'Bilde', 'pl': u'Grafika', 'pt': u'Imagem', 'ru': u'Изображение', + 'sk': u'Obrázok', + 'sl': u'Slika', + 'sr': u'Слика', 'sv': u'Bild', + 'th': u'ภาพ', + 'tr': u'Resim', + 'yi': u'בילד', + 'zh-hk': u'圖像', 'zh-tw': u'圖像', }
self.namespaces[7] = { '_default': u'Image talk', 'ar': u'نقاش الصورة', + 'ast': u'Imaxen discusión', 'ca': u'Imatge Discussió', - 'da': u'Billede diskussion', + 'cs': u'Soubor diskuse', + 'da': u'Billeddiskussion', 'de': u'Bild Diskussion', 'el': u'Συζήτηση εικόνας', + 'eo': u'Dosiera diskuto', 'es': u'Imagen Discusión', + 'fa': u'بحث تصویر', 'fi': u'Keskustelu kuvasta', 'fr': u'Discussion Image', 'he': u'שיחת תמונה', + 'hr': u'Razgovor o slici', + 'hu': u'Kep vita', + 'id': u'Pembicaraan Berkas', 'it': u'Discussioni immagine', + 'ja': u'画像‐ノート', + 'ko': u'그림토론', 'la': u'Disputatio Imaginis', + 'lt': u'Vaizdo aptarimas', + 'lv': u'Attēla diskusija', + 'nl': u'Overleg afbeelding', + 'nn': u'Bildediskusjon', 'no': u'Bildediskusjon', 'pl': u'Dyskusja grafiki', 'pt': u'Imagem Discussão', 'ru': u'Обсуждение изображения', + 'sk': u'Diskusia k obrázku', + 'sl': u'Pogovor o sliki', + 'sr': u'Разговор о слици', 'sv': u'Bilddiskussion', + 'th': u'คุยเรื่องภาพ', + 'tr': u'Resim tartışma', + 'yi': u'בילד רעדן', + 'zh-hk': u'圖像討論', 'zh-tw': u'圖像討論', }
self.namespaces[8] = { '_default': u'MediaWiki', 'ar': u'ميدياويكي', + 'fa': u'مدیاویکی', 'he': u'מדיה ויקי', - 'zh-tw': u'媒體維基', + 'sr': u'МедијаВики', + 'th': u'มีเดียวิกิ', + 'tr': u'MedyaViki', + 'yi': u'מעדיעװיקי', + 'zh-hk': u'媒體偽基', + 'zh-tw': u'媒體偽基', }
self.namespaces[9] = { '_default': u'MediaWiki talk', 'ar': u'نقاش ميدياويكي', + 'ast': u'MediaWiki discusión', 'ca': u'MediaWiki Discussió', - 'da': u'MediaWiki diskussion', + 'cs': u'MediaWiki diskuse', + 'da': u'MediaWiki-diskussion', 'de': u'MediaWiki Diskussion', + 'eo': u'MediaWiki diskuto', 'es': u'MediaWiki Discusión', + 'fa': u'بحث مدیاویکی', + 'fi': u'Keskustelu MediaWiki', 'fr': u'Discussion MediaWiki', 'he': u'שיחת מדיה ויקי', + 'hr': u'MediaWiki razgovor', + 'id': u'Pembicaraan MediaWiki', 'it': u'Discussioni MediaWiki', + 'ja': u'MediaWiki‐ノート', + 'ko': u'MediaWiki토론', 'la': u'Disputatio MediaWiki', + 'lt': u'MediaWiki aptarimas', + 'lv': u'MediaWiki diskusija', + 'nl': u'Overleg MediaWiki', + 'nn': u'MediaWiki-diskusjon', 'no': u'MediaWiki-diskusjon', 'pl': u'Dyskusja MediaWiki', 'pt': u'MediaWiki Discussão', 'ru': u'Обсуждение MediaWiki', + 'sk': u'Diskusia k MediaWiki', + 'sl': u'Pogovor o MediaWiki', + 'sr': u'Разговор о МедијаВикију', 'sv': u'MediaWiki diskussion', - 'zh-tw': u'媒體維基討論', + 'th': u'คุยเรื่องมีเดียวิกิ', + 'tr': u'MedyaViki tartışma', + 'yi': u'מעדיעװיקי רעדן', + 'zh-hk': u'媒體偽基討論', + 'zh-tw': u'媒體偽基討論', }
# # Custom namespace list for en: (and fi:) # self.namespaces[100] = { - '_default':u'Wilde', - 'en':u'Wilde', - 'fi':u'Hikiquote', + '_default': u'Wilde', + 'de': u'UnNews', + 'en': u'Wilde', + 'fi': u'Hikiquote', + 'nn': u'Ikkenytt', + 'pl': u'Cytaty', + 'sv': u'PsykNyheter', + 'tr': u'YanSözlük', } self.namespaces[101] = { - '_default':u'Wilde talk', - 'en':u'Wilde talk', - 'fi':u'Hiktionary' + '_default': u'Wilde talk', + 'de': u'UnNews Diskussion', + 'en': u'Wilde talk', + 'nn': u'Ikkenytt-diskusjon', + 'pl': u'Dyskusja cytatów', + 'sv': u'PsykNyheter diskussion', + 'tr': u'YanSözlük tartışma', } self.namespaces[102] = { - '_default':u'UnNews', - 'en':u'UnNews', - 'fi':u'Hikikirjasto' + '_default': u'UnNews', + 'de': u'Undictionary', + 'en': u'UnNews', + 'nn': u'Ikktionary', + 'pl': u'NonNews', + 'sv': u'Forum', + 'tr': u'YanHaber', } - self.namespaces[103] = {'_default':u'UnNews talk'} - self.namespaces[104] = {'_default':u'Undictionary'} - self.namespaces[105] = {'_default':u'Undictionary talk'} - self.namespaces[106] = {'_default':u'Game'} - self.namespaces[107] = {'_default':u'Game talk'} - self.namespaces[108] = {'_default':u'Babel'} - self.namespaces[109] = {'_default':u'Babel talk'} - self.namespaces[110] = {'_default':u'Forum'} - self.namespaces[111] = {'_default':u'Forum talk'} + self.namespaces[103] = { + 'de': u'Undictionary Diskussion', + 'en': u'UnNews talk', + 'ja': u'UnNews talk', + 'nn': u'Ikktionary-diskusjon', + 'pl': u'Dyskusja NonNews', + 'sv': u'Forumdiskussion', + 'tr': u'YanHaber tartışma', + } + self.namespaces[104] = { + 'de': u'UnBooks', + 'en': u'Undictionary', + 'pl': u'Nonźródła', + 'sv': u'Psyktionary', + } + self.namespaces[105] = { + 'de': u'UnBooks Diskussion', + 'en': u'Undictionary talk', + 'pl': u'Dyskusja nonźródeł', + 'sv': u'Psyktionary diskussion', + } + self.namespaces[106] = { + 'en': u'Game', + 'ja': u'Game', + 'pl': u'Słownik', + 'pt': u'Desnotícias', + 'sv': u'PsykCitat', + } + self.namespaces[107] = { + 'en': u'Game talk', + 'ja': u'Game talk', + 'pl': u'Dyskusja słownika', + 'pt': u'Desnotícias Discussão', + 'sv': u'PsykCitat diskussion', + } + self.namespaces[108] = { + 'en': u'Babel', + 'pl': u'Gra', + 'pt': u'Jogo', + 'sv': u'Spel', + } + self.namespaces[109] = { + 'en': u'Babel talk', + 'pl': u'Dyskusja gry', + 'pt': u'Jogo Discussão', + 'sv': u'Speldiskussion', + } + self.namespaces[110] = { + 'ar': u'Forum', + 'ast': u'Forum', + 'ca': u'Forum', + 'cs': u'Forum', + 'da': u'Forum', + 'de': u'Forum', + 'el': u'Forum', + 'en': u'Forum', + 'eo': u'Forum', + 'es': u'Forum', + 'fr': u'Forum', + 'he': u'Forum', + 'id': u'Forum', + 'it': u'Forum', + 'ja': u'Forum', + 'la': u'Forum', + 'lt': u'Forum', + 'nn': u'Forum', + 'no': u'Forum', + 'pl': u'Forum', + 'pt': u'Descionário', + 'ru': u'Форум', + 'sk': u'Forum', + 'sv': u'PsykBöcker', + 'tr': u'Astroloji', + 'yi': u'Forum', + 'zh': u'Forum', + } + self.namespaces[111] = { + 'ar': u'Forum talk', + 'ast': u'Forum talk', + 'ca': u'Forum talk', + 'cs': u'Forum talk', + 'da': u'Forumdiskussion', + 'de': u'Forum talk', + 'el': u'Forum talk', + 'en': u'Forum talk', + 'eo': u'Forum talk', + 'es': u'Forum talk', + 'fr': u'Discussion Forum', + 'he': u'Forum talk', + 'id': u'Forum talk', + 'it': u'Forum talk', + 'ja': u'Forum talk', + 'la': u'Forum talk', + 'lt': u'Forum talk', + 'nn': u'Forum-diskusjon', + 'no': u'Forum talk', + 'pl': u'Dyskusja forum', + 'pt': u'Descionário Discussão', + 'ru': u'Обсуждение форума', + 'sk': u'Forum talk', + 'sv': u'PsykBöckerdiskussion', + 'tr': u'Astroloji tartışma', + 'yi': u'Forum talk', + 'zh': u'Forum talk', + }
# A few selected big languages for things that we do not want to loop over # all languages. This is only needed by the titletranslate.py module, so
Modified: branches/rewrite/pywikibot/families/wikibooks_family.py =================================================================== --- branches/rewrite/pywikibot/families/wikibooks_family.py 2008-03-10 13:53:14 UTC (rev 5120) +++ branches/rewrite/pywikibot/families/wikibooks_family.py 2008-03-11 17:16:43 UTC (rev 5121) @@ -56,6 +56,7 @@ 'he': u'ויקיספר', 'hr': u'Wikiknjige', 'hu': u'Wikikönyvek', + 'hy': u'Վիքիգրքեր', 'is': u'Wikibækur', 'ka': u'ვიკიწიგნები', 'kk': u'Уикикітап', @@ -105,12 +106,12 @@ 'fy': u'Wikibooks oerlis', 'ga': u'Plé Vicíleabhar', 'gl': u'Conversa Wikibooks', - 'gn': u'Wikibooks Discusión', + 'gn': u'Wikibooks myangekõi', 'he': u'שיחת ויקיספר', 'hi': u'Wikibooks वार्ता', 'hr': u'Razgovor Wikiknjige', 'hu': u'Wikikönyvek vita', - 'hy': u'Wikibooks քննարկում', + 'hy': u'Վիքիգրքերի քննարկում', 'ia': u'Discussion Wikibooks', 'id': u'Pembicaraan Wikibooks', 'is': u'Wikibækurspjall', @@ -118,6 +119,7 @@ 'ja': u'Wikibooks‐ノート', 'ka': u'ვიკიწიგნები განხილვა', 'kk': u'Уикикітап талқылауы', + 'km': u'Wikibooks ពិភាក្សា', 'kn': u'Wikibooks ಚರ್ಚೆ', 'ko': u'위키책토론', 'ku': u'Wikibooks nîqaş', @@ -138,6 +140,7 @@ 'oc': u'Discussion Wikilibres', 'pa': u'Wikibooks ਚਰਚਾ', 'pl': u'Dyskusja Wikibooks', + 'ps': u'د Wikibooks خبرې اترې', 'pt': u'Wikibooks Discussão', 'qu': u'Wikibooks rimanakuy', 'ro': u'Discuţie Wikimanuale', @@ -164,22 +167,24 @@ }
self.namespaces[100] = { - 'id': u'Resep', 'fr': u'Transwiki', 'he': u'שער', + 'id': u'Resep', 'it': u'Progetto', 'ms': u'Resipi', 'ro': u'Raft', + 'ru': u'Полка', 'tr': u'Yemek', }
self.namespaces[101] = { - 'id': u'Pembicaraan Resep', 'fr': u'Discussion Transwiki', 'he': u'שיחת שער', + 'id': u'Pembicaraan Resep', 'it': u'Discussioni progetto', 'ms': u'Perbualan Resipi', 'ro': u'Discuţie Raft', + 'ru': u'Обсуждение полки', 'tr': u'Yemek tartışma', }
@@ -191,6 +196,8 @@ 'id': u'Wisata', 'it': u'Ripiano', 'nl': u'Transwiki', + 'ro': u'Wikijunior', + 'ru': u'Импортировано', 'sr': u'Кувар', }
@@ -202,6 +209,8 @@ 'id': u'Pembicaraan Wisata', 'it': u'Discussioni ripiano', 'nl': u'Overleg transwiki', + 'ro': u'Discuţie Wikijunior', + 'ru': u'Обсуждение импортированного', 'sr': u'Разговор о кувару', }
@@ -209,14 +218,26 @@ 'he': u'מדף', 'ka': u'თარო', 'nl': u'Wikijunior', + 'ro': u'Carte de bucate', + 'ru': u'Рецепт', }
self.namespaces[105] = { 'he': u'שיחת מדף', 'ka': u'თარო განხილვა', 'nl': u'Overleg Wikijunior', + 'ro': u'Discuţie Carte de bucate', + 'ru': u'Обсуждение рецепта', }
+ self.namespaces[106] = { + 'ru': u'Задача', + } + + self.namespaces[107] = { + 'ru': u'Обсуждение задачи', + } + self.namespaces[108] = { 'en': u'Transwiki', } @@ -281,7 +302,7 @@ }
def version(self, code): - return "1.12alpha" + return '1.13alpha'
def shared_image_repository(self, code): return ('commons', 'commons')
Modified: branches/rewrite/pywikibot/families/wikinews_family.py =================================================================== --- branches/rewrite/pywikibot/families/wikinews_family.py 2008-03-10 13:53:14 UTC (rev 5120) +++ branches/rewrite/pywikibot/families/wikinews_family.py 2008-03-11 17:16:43 UTC (rev 5121) @@ -170,7 +170,7 @@ return 'utf-8'
def version(self, code): - return "1.12alpha" + return '1.13alpha'
def shared_image_repository(self, code): return ('commons', 'commons')
Modified: branches/rewrite/pywikibot/families/wikipedia_family.py =================================================================== --- branches/rewrite/pywikibot/families/wikipedia_family.py 2008-03-10 13:53:14 UTC (rev 5120) +++ branches/rewrite/pywikibot/families/wikipedia_family.py 2008-03-11 17:16:43 UTC (rev 5121) @@ -201,6 +201,7 @@ 'ka': u'ვიკიპედია განხილვა', 'kab': u'Amyannan n Wikipedia', 'kk': u'Уикипедия талқылауы', + 'km': u'Wikipedia ពិភាក្សា', 'kn': u'ವಿಕಿಪೀಡಿಯ ಚರ್ಚೆ', 'ko': u'위키백과토론', 'ksh': u'Wikipedia Klaaf', @@ -238,6 +239,7 @@ 'pdc': u'Wikipedia Diskussion', 'pl': u'Dyskusja Wikipedii', 'pms': u'Discussion ant sla Wikipedia', + 'ps': u'د Wikipedia خبرې اترې', 'pt': u'Wikipedia Discussão', 'qu': u'Wikipedia rimanakuy', 'rmy': u'Vikipidiyake vakyarimata', @@ -733,6 +735,7 @@ 'he': ['en'], 'hu': ['en'], 'lb': self.alphabetic_lb, + 'ms': self.alphabetic_revised, 'nds': ['nds-nl','pdt'] + self.alphabetic, # Note: as of 2008-02-24, pdt: (Plautdietsch) is still in the Incubator. 'nn': ['no','nb','sv','da'] + self.alphabetic, 'no': self.alphabetic, @@ -781,7 +784,7 @@ return self.known_families
def version(self, code): - return "1.12alpha" + return '1.13alpha'
def dbName(self, code): # returns the name of the MySQL database
Modified: branches/rewrite/pywikibot/families/wikiquote_family.py =================================================================== --- branches/rewrite/pywikibot/families/wikiquote_family.py 2008-03-10 13:53:14 UTC (rev 5120) +++ branches/rewrite/pywikibot/families/wikiquote_family.py 2008-03-11 17:16:43 UTC (rev 5121) @@ -47,6 +47,7 @@ 'he': u'ויקיציטוט', 'hr': u'Wikicitat', 'hu': u'Wikidézet', + 'hy': u'Վիքիքաղվածք', 'is': u'Wikivitnun', 'ka': [u'ვიკიციტატა', u'Wikiquote'], 'kk': u'Уикидәйек', @@ -93,7 +94,7 @@ 'hi': u'Wikiquote वार्ता', 'hr': u'Razgovor Wikicitat', 'hu': u'Wikidézet vita', - 'hy': u'Wikiquote քննարկում', + 'hy': u'Վիքիքաղվածքի քննարկում', 'id': u'Pembicaraan Wikiquote', 'is': u'Wikivitnunspjall', 'it': u'Discussioni Wikiquote', @@ -236,7 +237,7 @@ }
def version(self, code): - return "1.12alpha" + return '1.13alpha'
def code2encodings(self, code): """
Modified: branches/rewrite/pywikibot/families/wikisource_family.py =================================================================== --- branches/rewrite/pywikibot/families/wikisource_family.py 2008-03-10 13:53:14 UTC (rev 5120) +++ branches/rewrite/pywikibot/families/wikisource_family.py 2008-03-11 17:16:43 UTC (rev 5121) @@ -54,6 +54,7 @@ 'hr': u'Wikizvor', 'ht': u'Wikisòrs', 'hu': u'Wikiforrás', + 'hy': u'Վիքիդարան', 'is': u'Wikiheimild', 'la': u'Vicifons', 'lt': u'Vikišaltiniai', @@ -93,7 +94,7 @@ 'hr': u'Razgovor o Wikizvoru', 'ht': u'Diskisyon Wikisòrs', 'hu': u'Wikiforrás vita', - 'hy': u'Wikisource քննարկում', + 'hy': u'Վիքիդարանի քննարկում', 'id': u'Pembicaraan Wikisource', 'is': u'Wikiheimildspjall', 'it': u'Discussioni Wikisource', @@ -225,33 +226,39 @@ }
self.namespaces[108] = { + 'he': u'מחבר', 'it': u'Pagina', 'pt': u'Em Tradução', 'sv': u'Index', }
self.namespaces[109] = { + 'he': u'שיחת מחבר', 'it': u'Discussioni pagina', 'pt': u'Discussão Em Tradução', 'sv': u'Indexdiskussion', }
self.namespaces[110] = { + 'he': u'תרגום', 'it': u'Indice', 'pt': u'Anexo', }
self.namespaces[111] = { + 'he': u'שיחת תרגום', 'it': u'Discussioni indice', 'pt': u'Anexo Discussão', }
self.namespaces[112] = { 'fr': u'Livre', + 'he': u'מפתח', }
self.namespaces[113] = { 'fr': u'Discussion Livre', + 'he': u'שיחת מפתח', }
self.alphabetic = ['ang','ar','az','bg','bs','ca','cs','cy', @@ -282,7 +289,7 @@ }
def version(self, code): - return "1.12alpha" + return '1.13alpha'
def shared_image_repository(self, code): return ('commons', 'commons')
Modified: branches/rewrite/pywikibot/families/wikiversity_family.py =================================================================== --- branches/rewrite/pywikibot/families/wikiversity_family.py 2008-03-10 13:53:14 UTC (rev 5120) +++ branches/rewrite/pywikibot/families/wikiversity_family.py 2008-03-11 17:16:43 UTC (rev 5121) @@ -98,7 +98,7 @@ }
def version(self,code): - return "1.12alpha" + return '1.13alpha'
def shared_image_repository(self, code): return ('commons', 'commons')
Modified: branches/rewrite/pywikibot/families/wiktionary_family.py =================================================================== --- branches/rewrite/pywikibot/families/wiktionary_family.py 2008-03-10 13:53:14 UTC (rev 5120) +++ branches/rewrite/pywikibot/families/wiktionary_family.py 2008-03-11 17:16:43 UTC (rev 5121) @@ -30,6 +30,7 @@ 'kw', 'ln', 'sm', 'si', 'za', 'roa-rup', 'mh', 'ba', 'or', 'sn', 'ak', 'bh', 'lo', 'bm', 'yo', 'bi', 'to', 'aa', 'av', 'rn', 'dz', 'tw', 'om', 'ab', 'my', 'wa', 'sc', 'cr', 'bo', 'rm', + 'hsb', ]
for lang in self.languages_by_size: @@ -65,6 +66,7 @@ 'hi': u'विक्षनरी', 'hr': u'Wječnik', 'hu': u'Wikiszótár', + 'hy': u'Վիքիբառարան', 'io': u'Wikivortaro', 'is': u'Wikiorðabók', 'it': u'Wikizionario', @@ -128,14 +130,14 @@ 'fy': u'Wiktionary oerlis', 'ga': u'Plé Vicífhoclóra', 'gl': u'Conversa Wiktionary', - 'gn': u'Wiktionary Discusión', + 'gn': u'Wiktionary myangekõi', 'gu': u'વિક્ષનરી talk', 'he': u'שיחת ויקימילון', 'hi': u'विक्षनरी वार्ता', 'hr': u'Razgovor Wječnik', 'hsb': u'Wiktionary diskusija', 'hu': u'Wikiszótár vita', - 'hy': u'Wiktionary քննարկում', + 'hy': u'Վիքիբառարանի քննարկում', 'ia': u'Discussion Wiktionary', 'id': u'Pembicaraan Wiktionary', 'io': u'Wikivortaro Debato', @@ -145,6 +147,7 @@ 'jv': u'Dhiskusi Wiktionary', 'ka': u'ვიქსიკონი განხილვა', 'kk': u'Уикисөздік талқылауы', + 'km': u'Wiktionary ពិភាក្សា', 'kn': u'Wiktionary ಚರ್ಚೆ', 'ko': u'위키낱말사전토론', 'ku': u'Wiktionary nîqaş', @@ -152,6 +155,7 @@ 'lb': u'Wiktionary Diskussioun', 'li': u'Euverlèk Wiktionary', 'ln': u'Discussion Wiktionary', + 'lo': u'ສົນທະນາກ່ຽວກັບWiktionary', 'lt': u'Vikižodyno aptarimas', 'lv': u'Wiktionary diskusija', 'mg': u'Discussion Wiktionary', @@ -167,6 +171,7 @@ 'oc': u'Discussion Wikiccionari', 'pa': u'Wiktionary ਚਰਚਾ', 'pl': u'Wikidyskusja', + 'ps': u'د Wiktionary خبرې اترې', 'pt': u'Wikcionário Discussão', 'qu': u'Wiktionary rimanakuy', 'ro': u'Discuţie Wikţionar', @@ -370,7 +375,7 @@ self.interwiki_attop = ['pl']
def version(self, code): - return "1.12alpha" + return '1.13alpha'
def shared_image_repository(self, code): return ('commons', 'commons')
Modified: branches/rewrite/pywikibot/page.py =================================================================== --- branches/rewrite/pywikibot/page.py 2008-03-10 13:53:14 UTC (rev 5120) +++ branches/rewrite/pywikibot/page.py 2008-03-11 17:16:43 UTC (rev 5121) @@ -15,6 +15,7 @@ import htmlentitydefs import logging import re +import sys import unicodedata import urllib
@@ -185,6 +186,9 @@
def __str__(self): """Return a console representation of the pagelink.""" + return self.title(asLink=True, forceInterwiki=True).encode(sys.stderr.encoding) + + def __unicode__(self): return self.title(asLink=True, forceInterwiki=True)
def __repr__(self): @@ -211,7 +215,7 @@ # Pseudo method that makes it possible to store Page objects as keys # in hash-tables. This relies on the fact that the string # representation of an instance can not change after the construction. - return hash(str(self)) + return hash(unicode(self))
def autoFormat(self): """Return L{date.autoFormat} dictName and value, if any. @@ -828,8 +832,8 @@ u'Please enter a reason for the undeletion:') return self.site().undelete(self, comment)
- def protect(self, edit='sysop', move='sysop', create='sysop', - unprotect=False, reason=None, prompt=True, throttle=None): + def protect(self, edit='sysop', move='sysop', unprotect=False, + reason=None, prompt=True, throttle=None): """(Un)protect a wiki page. Requires administrator status.
Valid protection levels (in MediaWiki 1.12) are '' (equivalent to @@ -837,7 +841,6 @@
@param edit: Level of edit protection @param move: Level of move protection - @param create: Level of create protection @param unprotect: If true, unprotect the page (equivalent to setting all protection levels to '') @param reason: Edit summary. @@ -857,7 +860,7 @@ % (un, self.title(asLink=True))) reason = pywikibot.input(u'Please enter a reason for the action:') if unprotect: - edit = move = create = "" + edit = move = "" answer = 'y' if prompt and not hasattr(self.site(), '_noProtectPrompt'): answer = pywikibot.inputChoice( @@ -868,7 +871,7 @@ answer = 'y' self.site()._noProtectPrompt = True if answer in ['y', 'Y']: - return self.site().protect(self, edit, move, create, reason) + return self.site().protect(self, edit, move, reason)
######## DEPRECATED METHODS ########
@@ -1279,7 +1282,7 @@ """ illegal_titles_pattern = re.compile( # Matching titles will be held as illegal. - u'''[^ %!"$&'()*,\-.\/0-9:;=?@A-Z\\^_`a-z~\x80-\xFF+]''' + u'''[^ %!"$&'()*,\-.\/0-9:;=?@A-Z\\^_`a-z~\u0080-\uFFFF+]''' # URL percent encoding sequences interfere with the ability # to round-trip titles -- you can't link to them consistently. u'|%[0-9A-Fa-f]{2}' @@ -1288,7 +1291,6 @@ u'|&#[0-9]+;' u'|&#x[0-9A-Fa-f]+;' ) - namespace_pattern = re.compile("^(.+?)_*:_*(.*)$")
def __init__(self, text, source=None, defaultNamespace=0): """Parse text into a Link object. @@ -1366,7 +1368,6 @@ # looks like an interwiki link if not firstPass: # Can't make a local interwiki link to an interwiki link. - # That's just crazy! raise pywikibot.Error( "Improperly formatted interwiki link '%s'" % text) @@ -1395,6 +1396,8 @@ firstPass = False continue self.site = newsite + else: + break # text before : doesn't match any known prefix
if u"#" in t: t, sec = t.split(u'#', 1) @@ -1406,7 +1409,7 @@ m = Link.illegal_titles_pattern.search(t) if m: raise pywikibot.Error( - "Invalid title: contains illegal char(s) '%s'" % m.group(0)) + u"Invalid title: contains illegal char(s) '%s'" % m.group(0))
# Pages with "/./" or "/../" appearing in the URLs will # often be unreachable due to the way web browsers deal
Modified: branches/rewrite/pywikibot/site.py =================================================================== --- branches/rewrite/pywikibot/site.py 2008-03-10 13:53:14 UTC (rev 5120) +++ branches/rewrite/pywikibot/site.py 2008-03-11 17:16:43 UTC (rev 5121) @@ -11,11 +11,16 @@ __version__ = '$Id: $'
import pywikibot -from pywikibot.exceptions import * from pywikibot.data import api
import os +import threading
+ +class PageInUse(pywikibot.Error): + """Page cannot be reserved for writing due to existing lock.""" + + def Family(fam=None, fatal=True): """Import the named family.
@@ -90,6 +95,10 @@ ## % (self._lang, self._family.name)) self._username = user
+ # following are for use with lock_page and unlock_page methods + self._mutex = threading.Lock() + self._locked_pages = [] + def family(self): """Return the associated Family object.""" return self._family @@ -134,10 +143,9 @@
def getNamespaceIndex(self, namespace): """Given a namespace name, return its int index, or None if invalid.""" - if self.case() == "first-letter": - namespace = namespace[:1].upper() + namespace[1:] for ns in self._namespaces: - if namespace in self._namespaces[ns]: + if namespace.lower() in [name.lower() + for name in self._namespaces[ns]]: return ns return None
@@ -145,7 +153,42 @@ """Return dict of valid namespaces on this wiki.""" return self._namespaces
+ def lock_page(self, page, block=True): + """Lock page for writing. Must be called before writing any page.
+ We don't want different threads trying to write to the same page + at the same time, even to different sections. + + @param page: the page to be locked + @type page: pywikibot.Page + @param block: if true, wait until the page is available to be locked; + otherwise, raise an exception if page can't be locked + + """ + self._mutex.acquire() + try: + while page in self._locked_pages: + if not block: + raise PageInUse + time.sleep(.25) + self._locked_pages.append(page.title(withSection=False)) + finally: + self._mutex.release() + + def unlock_page(self, page): + """Unlock page. Call as soon as a write operation has completed. + + @param page: the page to be locked + @type page: pywikibot.Page + + """ + self._mutex.acquire() + try: + self._locked_pages.remove(page.title(withSection=False)) + finally: + self._mutex.release() + + class APISite(BaseSite): """API interface to MediaWiki site.
@@ -296,6 +339,8 @@ self._namespaces = { # these are the MediaWiki built-in names, which always work # localized names are loaded later upon accessing the wiki + # namespace prefixes are always case-insensitive, but the + # canonical forms are capitalized -2: [u"Media"], -1: [u"Special"], 0: [u""], @@ -315,7 +360,7 @@ 14: [u"Category"], 15: [u"Category talk"], } - self.getsiteinfo() +# self.getsiteinfo() return # ANYTHING BELOW THIS POINT IS NOT YET IMPLEMENTED IN __init__() self._mediawiki_messages = {} @@ -450,15 +495,53 @@ def case(self): return self.getsiteinfo()['case']
+ def namespaces(self): + """Return dict of valid namespaces on this wiki.""" + self.getsiteinfo() + return self._namespaces + def namespace(self, num, all = False): """Return string containing local name of namespace 'num'.
- If optional argument 'all' is true, return a tuple of all recognized + If optional argument 'all' is true, return a list of all recognized values for this namespace.
""" + self.getsiteinfo() + if all: + return self._namespaces[num] return self._namespaces[num][0]
+ # following group of methods map more-or-less directly to API queries + + def getbacklinks(self, page, followRedirects, filterRedirects, + namespaces=None): + """Retrieve all pages that link to the given page. + + @param page: The Page to get links to. + @param followRedirects: Also return links to redirects pointing to + the given page. [Not yet implemented on API] + @param filterRedirects: If True, only return redirects to the given + page. If False, only return non-redirect links. If None, return + both (no filtering). + @param namespaces: If present, only return links from the namespaces + in this list. + + """ + bltitle = page.title(withSection=False) + blgen = api.PageGenerator("backlinks", gbltitle=bltitle, + gbllimit="5000") + if namespaces is not None: + blgen.request["gblnamespace"] = u"|".join(unicode(ns) + for ns in namespaces) + if filterRedirects is not None: + blgen.request["gblfilterredir"] = filterRedirects and "redirects"\ + or "nonredirects" + if followRedirects: + blgen.request["gblredirect"] = "" + return blgen + + #### METHODS NOT IMPLEMENTED YET (but may be delegated to Family object) #### class NotImplementedYet:
Added: branches/rewrite/pywikibot/tests/page_tests.py =================================================================== --- branches/rewrite/pywikibot/tests/page_tests.py (rev 0) +++ branches/rewrite/pywikibot/tests/page_tests.py 2008-03-11 17:16:43 UTC (rev 5121) @@ -0,0 +1,158 @@ +# -*- coding: utf-8 -*- +""" +Tests for the page module. +""" +# +# (C) Pywikipedia bot team, 2008 +# +# Distributed under the terms of the MIT license. +# +__version__ = '$Id: $' + + +import unittest +import pywikibot +import pywikibot.page + +site = pywikibot.Site("en", "wikipedia") + + +class TestLinkObject(unittest.TestCase): + """Test cases for Link objects""" + namespaces = {0: [u""], # en.wikipedia.org namespaces for testing + 1: [u"Talk:"], # canonical form first, then others + 2: [u"User:"], # must end with : + 3: [u"User talk:", u"User_talk:"], + 4: [u"Wikipedia:", u"Project:", u"WP:"], + 5: [u"Wikipedia talk:", u"Project talk:", u"Wikipedia_talk:", + u"Project_talk:", u"WT:"], + 6: [u"Image:"], + 7: [u"Image talk:", u"Image_talk:"], + 8: [u"MediaWiki:"], + 9: [u"MediaWiki talk:", u"MediaWiki_talk:"], + 10: [u"Template:"], + 11: [u"Template talk:", u"Template_talk:"], + 12: [u"Help:"], + 13: [u"Help talk:", u"Help_talk:"], + 14: [u"Category:"], + 15: [u"Category talk:", u"Category_talk:"], + 100: [u"Portal:"], + 101: [u"Portal talk:", u"Portal_talk:"], + } + titles = { + # just a bunch of randomly selected titles + # input format : expected output format + u"Cities in Burkina Faso" : u"Cities in Burkina Faso", + u"eastern Sayan" : u"Eastern Sayan", + u"The_Addams_Family_(pinball)" : u"The Addams Family (pinball)", + u"Hispanic (U.S. Census)" : u"Hispanic (U.S. Census)", + u"Stołpce" : u"Stołpce", + u"Nowy_Sącz" : u"Nowy Sącz", + u"battle of Węgierska Górka" : u"Battle of Węgierska Górka", + } + # random bunch of possible section titles + sections = [u"", + u"#Phase_2", + u"#History", + u"#later life", + ] + + def testNamespaces(self): + """Test that Link() normalizes namespace names""" + for num in self.namespaces: + for prefix in self.namespaces[num]: + l = pywikibot.page.Link(prefix+self.titles.keys()[0], + site) + self.assertEqual(l.namespace, num) + # namespace prefixes are case-insensitive + m = pywikibot.page.Link(prefix.lower()+self.titles.keys()[1], + site) + self.assertEqual(m.namespace, num) + + +class TestPageObject(unittest.TestCase): + def testSite(self): + """Test site() method""" + p1 = pywikibot.Page(site, u"Help:Test page#Testing") + self.assertEqual(p1.site(), site) + + def testNamespace(self): + """Test namespace() method""" + # TODO + + def testTitle(self): + """Test title() method options.""" + p1 = pywikibot.Page(site, u"Help:Test page#Testing") + self.assertEqual(p1.title(), + u"Help:Test page#Testing") + self.assertEqual(p1.title(underscore=True), + u"Help:Test_page#Testing") + self.assertEqual(p1.title(withNamespace=False), + u"Test page#Testing") + self.assertEqual(p1.title(withSection=False), + u"Help:Test page") + self.assertEqual(p1.title(withNamespace=False, withSection=False), + u"Test page") + self.assertEqual(p1.title(asUrl=True), + "Help%3ATest_page%23Testing") + self.assertEqual(p1.title(asLink=True), + u"[[Help:Test page#Testing]]") + self.assertEqual(p1.title(asLink=True, forceInterwiki=True), + u"[[en:Help:Test page#Testing]]") + self.assertEqual(p1.title(asLink=True, textlink=True), + p1.title(asLink=True)) + # also test a page with non-ASCII chars and a different namespace + p2 = pywikibot.Page(site, u"Image:Jean-Léon Gérôme 003.jpg") + self.assertEqual(p2.title(), + u"Image:Jean-Léon Gérôme 003.jpg") + self.assertEqual(p2.title(underscore=True), + u"Image:Jean-Léon_Gérôme_003.jpg") + self.assertEqual(p2.title(withNamespace=False), + u"Jean-Léon Gérôme 003.jpg") + self.assertEqual(p2.title(withSection=False), + u"Image:Jean-Léon Gérôme 003.jpg") + self.assertEqual(p2.title(withNamespace=False, withSection=False), + u"Jean-Léon Gérôme 003.jpg") + self.assertEqual(p2.title(asUrl=True), + u"Image%3AJean-L%C3%A9on_G%C3%A9r%C3%B4me_003.jpg") + self.assertEqual(p2.title(asLink=True), + u"[[Image:Jean-Léon Gérôme 003.jpg]]") + self.assertEqual(p2.title(asLink=True, forceInterwiki=True), + u"[[en:Image:Jean-Léon Gérôme 003.jpg]]") + self.assertEqual(p2.title(asLink=True, textlink=True), + u"[[:Image:Jean-Léon Gérôme 003.jpg]]") + + def testSection(self): + """Test section() method.""" + # use same pages as in previous test + p1 = pywikibot.Page(site, u"Help:Test page#Testing") + p2 = pywikibot.Page(site, u"Image:Jean-Léon Gérôme 003.jpg") + self.assertEqual(p1.section(), u"Testing") + self.assertEqual(p2.section(), None) + + def testIsTalkPage(self): + """Test isTalkPage() method.""" + p1 = pywikibot.Page(site, u"First page") + p2 = pywikibot.Page(site, u"Talk:First page") + p3 = pywikibot.Page(site, u"User:Second page") + p4 = pywikibot.Page(site, u"User talk:Second page") + self.assertEqual(p1.isTalkPage(), False) + self.assertEqual(p2.isTalkPage(), True) + self.assertEqual(p3.isTalkPage(), False) + self.assertEqual(p4.isTalkPage(), True) + + def testIsCategory(self): + """Test isCategory method.""" + p1 = pywikibot.Page(site, u"First page") + p2 = pywikibot.Page(site, u"Category:Second page") + p3 = pywikibot.Page(site, u"Category talk:Second page") + self.assertEqual(p1.isCategory(), False) + self.assertEqual(p2.isCategory(), True) + self.assertEqual(p3.isCategory(), False) + + +if __name__ == '__main__': + try: + unittest.main() + except SystemExit: + pass
pywikipedia-l@lists.wikimedia.org