[Pywikipedia-l] SVN: [6274] trunk/pywikipedia
russblau at svn.wikimedia.org
russblau at svn.wikimedia.org
Wed Jan 21 19:19:12 UTC 2009
Revision: 6274
Author: russblau
Date: 2009-01-21 19:19:12 +0000 (Wed, 21 Jan 2009)
Log Message:
-----------
Recognize enwiki namespace aliases
Modified Paths:
--------------
trunk/pywikipedia/families/wikipedia_family.py
trunk/pywikipedia/family.py
Modified: trunk/pywikipedia/families/wikipedia_family.py
===================================================================
--- trunk/pywikipedia/families/wikipedia_family.py 2009-01-20 13:55:52 UTC (rev 6273)
+++ trunk/pywikipedia/families/wikipedia_family.py 2009-01-21 19:19:12 UTC (rev 6274)
@@ -75,6 +75,7 @@
'cy': u'Wicipedia',
'dsb': u'Wikipedija',
'el': u'Βικιπαίδεια',
+ 'en': [u"Wikipedia", u"WP"],
'eo': u'Vikipedio',
'et': u'Vikipeedia',
'ext': u'Güiquipeya',
@@ -180,6 +181,7 @@
'dsb': u'Wikipedija diskusija',
'el': u'Βικιπαίδεια συζήτηση',
'eml': u'Discussioni Wikipedia',
+ 'en': [u"Wikipedia talk", u"WT"],
'eo': u'Vikipedia diskuto',
'es': u'Wikipedia Discusión',
'et': u'Vikipeedia arutelu',
Modified: trunk/pywikipedia/family.py
===================================================================
--- trunk/pywikipedia/family.py 2009-01-20 13:55:52 UTC (rev 6273)
+++ trunk/pywikipedia/family.py 2009-01-21 19:19:12 UTC (rev 6274)
@@ -3085,22 +3085,25 @@
way to write the same namespace - choose the first one in the list.
If nothing can be normalized, return the original value.
"""
- for ns, items in self.namespaces.iteritems():
- if items.has_key(code):
- v = items[code]
- elif items.has_key('_default'):
- v = items['_default']
+ for ns, localized_ns in self.namespaces.iteritems():
+ if code in localized_ns:
+ valid = localized_ns[code]
+ if isinstance(valid, basestring):
+ valid = [valid]
+ else:
+ valid = valid[:]
else:
+ valid = []
+ if '_default' in localized_ns:
+ default = localized_ns['_default']
+ if isinstance(default, basestring):
+ default = [default]
+ if default:
+ valid.extend(default)
+ if not valid:
continue
- if type(v) is list:
- if value in v: return v[0]
- else:
- if value == v: return v
- try:
- if value == self.namespace('_default', ns):
- return self.namespace(code, ns)
- except KeyError:
- pass
+ if value in valid:
+ return self.namespace(code, ns)
return value
def getNamespaceIndex(self, lang, namespace):
@@ -3113,7 +3116,7 @@
for n in self.namespaces.keys():
try:
nslist = self.namespaces[n][lang]
- if type(nslist) != type([]):
+ if type(nslist) is not list:
nslist = [nslist]
for ns in nslist:
if ns.lower() == namespace:
More information about the Pywikipedia-l
mailing list