`Contents of the library (objects and functions to be used outside, situation late August 2004)  Classes: Page: A MediaWiki page     __init__               Page(Site, Title) - the page with title Title on wikimedia site Site     title                  The name of the page, in a form suitable for an interwiki link     urlname                The name of the page, in a form suitable for a URL     titleWithoutNamespace  The name of the page, with the namespace part removed     section                The section of the page (the part of the name after '#')     sectionFreeTitle       The name without the section part     aslink                 The name of the page in the form Title or lang:Title     site                   The wiki this page is in     encoding               The encoding of the page     isAutoTitle            If the title is a well known, auto-translatable title     autoFormat             Returns (dictName, value), where value can be a year, date, etc.,                             and dictName is 'YearBC', 'December', etc.     isCategory             True if the page is a category, false otherwise     isImage                True if the page is an image, false otherwise      get (*)                The text of the page     exists (*)             True if the page actually exists, false otherwise     isRedirectPage (*)     True if the page is a redirect, false otherwise     isEmpty (*)            True if the page has 4 characters or less content, not                             counting interwiki and category links     botMayEdit (*)         True if bot is allowed to edit page     interwiki (*)          The interwiki links from the page (list of Pages)     categories (*)         The categories the page is in (list of Pages)     linkedPages (*)        The normal pages linked from the page (list of Pages)     imagelinks (*)         The pictures on the page (list of ImagePages)     templates (*)          All templates referenced on the page (list of strings)     getRedirectTarget (*)  The page the page redirects to     isDisambig (*)         True if the page is a disambiguation page     getReferences          List of pages linking to the page     namespace              The namespace in which the page is     permalink (*)          The url of the permalink of the current version     move                   Move the page to another title     put(newtext)           Saves the page     put_async(newtext)     Queues the page to be saved asynchronously     delete                 Deletes the page (requires being logged in)      (*)  This loads the page if it has not been loaded before; permalink might           even reload it if it has been loaded before  Site: a MediaWiki site     messages               There are new messages on the site     forceLogin()           Does not continue until the user has logged in to                             the site     getUrl()               Retrieve an URL from the site     mediawiki_message(key): Retrieve the text of the MediaWiki message with                             the key ``key``     has_mediawiki_message(key)  True if this site defines a MediaWiki message                                  with the key ``key``     Special pages:         Dynamic pages:             allpages(): Special:Allpages             newpages(): Special:Newpages             longpages(): Special:Longpages             shortpages(): Special:Shortpages             categories(): Special:Categories          Cached pages:             deadendpages(): Special:Deadendpages             ancientpages(): Special:Ancientpages             lonelypages(): Special:Lonelypages             uncategorizedcategories(): Special:Uncategorizedcategories             uncategorizedpages(): Special:Uncategorizedpages             unusedcategories(): Special:Unusuedcategories  Other functions: getall(): Load pages via Special:Export setAction(text): Use 'text' instead of ``Wikipedia python library`` in     editsummaries handleArgs(): Checks whether text is an argument defined on wikipedia.py     (these are -family, -lang, -log and others) translate(xx, dict): dict is a dictionary, giving text depending on language,     xx is a language. Returns the text in the most applicable language for     the xx: wiki setUserAgent(text): Sets the string being passed to the HTTP server as     the User-agent: header. Defaults to 'Pywikipediabot/1.0'.  output(text): Prints the text 'text' in the encoding of the user's console. input(text): Asks input from the user, printing the text 'text' first. showDiff(oldtext, newtext): Prints the differences between oldtext and newtext     on the screen  getLanguageLinks(text,xx): get all interlanguage links in wikicode text 'text'     in the form xx:pagename removeLanguageLinks(text): gives the wiki-code 'text' without any interlanguage     links. replaceLanguageLinks(oldtext, new): in the wiki-code 'oldtext' remove the     language links and replace them by the language links in new, a dictionary     with the languages as keys and either Pages or titles as values getCategoryLinks(text,xx): get all category links in text 'text' (links in the     form xx:pagename) removeCategoryLinks(text,xx): remove all category links in 'text' replaceCategoryLinks(oldtext,new): replace the category links in oldtext by     those in new (new a list of category Pages) stopme(): Put this on a bot when it is not or not communicating with the Wiki     any longer. It will remove the bot from the list of running processes,     and thus not slow down other bot threads anymore.  `````` from __future__ import generators # # (C) Pywikipedia bot team, 2003-2006 # # Distributed under the terms of the MIT license. # __version__ = '$Id: wikipedia.py 4028 2007-08-11 20:43:46Z btongminh $'  import os, sys import httplib, socket, urllib import traceback import time, threading, Queue import math import re, md5, codecs, difflib, locale import xml.sax, xml.sax.handler import htmlentitydefs import warnings import unicodedata  import config, login import xmlreader from BeautifulSoup import * import simplejson  # we'll set the locale to system default. This will ensure correct string # handling for non-latin characters on Python 2.3.x. For Python 2.4.x it's no # longer needed. locale.setlocale(locale.LC_ALL, '')  try:     set # introduced in Python2.4: faster and future except NameError:     from sets import Set as set   # Check Unicode support (is this a wide or narrow python build?) # See http://www.python.org/doc/peps/pep-0261/ try:     unichr(66365)  # a character in th: alphabet, uses 32 bit encoding     WIDEBUILD = True except ValueError:     WIDEBUILD = False   # Local exceptions  class Error(Exception):     ``````Wikipedia error``````  class NoUsername(Error):     ``````Username is not in user-config.py``````  class NoPage(Error):     ``````Page does not exist``````  class IsRedirectPage(Error):     ``````Page is a redirect page``````  class IsNotRedirectPage(Error):     ``````Page is not a redirect page``````  class LockedPage(Error):     ``````Page is locked``````  class LockedNoPage(NoPage, LockedPage):     ``````Page does not exist, and creating it is not possible because of a lock.``````  class NoSuchEntity(ValueError):     ``````No entity exist for this character``````  class SectionError(Error):     ``````The section specified by # does not exist``````  class PageNotSaved(Error):     ``````Saving the page has failed``````  class EditConflict(PageNotSaved):     ``````There has been an edit conflict while uploading the page``````  class SpamfilterError(PageNotSaved):     ``````Saving the page has failed because the MediaWiki spam filter detected a blacklisted URL.``````     def __init__(self, arg):         self.url = arg         self.args = arg,  class ServerError(Error):     ``````Got unexpected server response``````      class BadTitle(Error):     ``````Server responded with BadTitle.``````  # UserBlocked exceptions should in general not be catched. If the bot has been # blocked, the bot operator has possibly done a mistake and should take care of # the issue before continuing. class UserBlocked(Error):     ``````Your username or IP has been blocked``````  class PageNotFound(Exception):     ``````Page not found in list``````  SaxError = xml.sax._exceptions.SAXParseException  # Pre-compile re expressions reNamespace = re.compile(``^(.+?) *: *(.*)$``)  # The most important thing in this whole module: The Page class class Page(object):     ``````A page on the wiki.``````     def __init__(self, site, title, insite = None, defaultNamespace = 0):         ``````         Constructor. Normally called with two arguments:         Parameters:NEWLIN