Revision: 5438 Author: btongminh Date: 2008-05-25 18:23:31 +0000 (Sun, 25 May 2008)
Log Message: ----------- Use BeautifulSoup to parse MediaWiki messages. No need to add more external dependencies. Also if you do add an external dependency, commit it as well or add it as svn:external. Also doing sys.exit() is not really a sane thing to do. If you really need to exit, you should raise an error when wikipedia is imported. TODO: Fix this for MediaWiki 1.11.
Modified Paths: -------------- trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py =================================================================== --- trunk/pywikipedia/wikipedia.py 2008-05-24 00:55:14 UTC (rev 5437) +++ trunk/pywikipedia/wikipedia.py 2008-05-25 18:23:31 UTC (rev 5438) @@ -4458,22 +4458,6 @@
def mediawiki_message(self, key): """Return the MediaWiki message text for key "key" """ - try: - from xml.etree.cElementTree import XML # 2.5 - except ImportError: - try: - from cElementTree import XML - except ImportError: - output('Module cElementTree not found, using instead the slower ElementTree') - try: - from xml.etree.ElementTree import XML # 2.5 - except ImportError: - try: - from elementtree.ElementTree import XML - except ImportError: - output('ERROR: One of the cElementTree, or the ElementTree module is now needed to be able to parse mediawiki messages. Please install (c)ElementTree. (Note that python 2.5 natively includes these librairies : upgrading to python 2.5 will solve this issue.)') - stopme() - sys.exit(1) # Allmessages is retrieved once for all in a session if not self._mediawiki_messages: if verbose: @@ -4484,15 +4468,15 @@ get_throttle() xml = self.getUrl(self.get_address("Special:Allmessages") + "&ot=xml") - decode = xml.encode(self.encoding()) - tree = XML(decode) + tree = BeautifulStoneSoup(xml) # xml structure is : # <messages lang="fr"> # <message name="about">À propos</message> # ... # </messages> - for msg in tree.getiterator('message'): - self._mediawiki_messages[msg.get('name').lower()] = msg.text + self._mediawiki_messages = dict([(tag.get('name').lower(), tag.string) + for tag in tree.findAll('message')]) + if not self._mediawiki_messages: # No messages could be added. # We assume that the server is down.