[Pywikipedia-l] SVN: [5468] trunk/pywikipedia
nicdumz at svn.wikimedia.org
nicdumz at svn.wikimedia.org
Fri May 30 05:37:13 UTC 2008
Revision: 5468
Author: nicdumz
Date: 2008-05-30 05:37:12 +0000 (Fri, 30 May 2008)
Log Message:
-----------
* Raising KeyError when some stupid users try to work with key '' (I did it :p )
* Doing only one disk access per mediawiki_message call; Catching diskusage KeyError on key access to raise a nice KeyError("MediaWiki key '%s' does not exist[...]) instead
Modified Paths:
--------------
trunk/pywikipedia/diskcache.py
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/diskcache.py
===================================================================
--- trunk/pywikipedia/diskcache.py 2008-05-29 23:20:27 UTC (rev 5467)
+++ trunk/pywikipedia/diskcache.py 2008-05-30 05:37:12 UTC (rev 5468)
@@ -62,7 +62,10 @@
if type(key) is unicode:
key = key.encode('utf-8')
- index = key[0]
+ try:
+ index = key[0]
+ except IndexError:
+ raise KeyError(key)
if not ((index >= 'a' and index <= 'z') or (index >= '0' and index <= '9')):
raise KeyError(key)
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2008-05-29 23:20:27 UTC (rev 5467)
+++ trunk/pywikipedia/wikipedia.py 2008-05-30 05:37:12 UTC (rev 5468)
@@ -4517,10 +4517,12 @@
break
key = key.lower()
- if self._mediawiki_messages[key] is None:
+ try:
+ value = self._mediawiki_messages[key]
+ return value
+ except KeyError:
raise KeyError("MediaWiki key '%s' does not exist on %s"
% (key, self))
- return self._mediawiki_messages[key]
def has_mediawiki_message(self, key):
"""Return True iff this site defines a MediaWiki message for 'key'."""
More information about the Pywikipedia-l
mailing list