= Overview = Title:: write an interwiki map loader Duration:: 96 Difficulty:: Easy Type:: Code Tags:: python Mentors:: thomaswaldmann,rb_proj,ronny_pfannschmidt,xoraxax Count:: -1 = Description = == Abstract == Write an interwiki map file (intermap.txt) loader that reads the file and returns a python dict. == Details == In moin2 the wikiconfig value "interwiki" is now just a dict. Thus we need a loader returning a python dict for people who want to load the file (intermap.txt). Note: your code should also be able to process a unicode object (instead of a file) as input. You need to write the code implementing the functionality, a unit test testing it and some docs for admins showing how to use it from the wikiconfig. Deliverables: a patch or changeset. == Skill Requirements == python, py.test, rst == Links == = Discussion = Claimed by MicheleOrru == Implementation == The code is avaible at: http://bitbucket.org/maker/moin-2.0-dev/ Since the repo is private, for now only Thomas and Alexander have +r access. The module {{{datastruct.backends.wiki_map}}} implements the class {{{InterWikiMap}}}, which provides a set of utilities for parsing and checking a interwiki maps. Its main job is to load an interwiki file/string, and then store everything into a dictionary containing the name of the link as key, and its url as value. In order to parse a string/file object, you simply have to use (respectively) {{{InterWikiMap.from_file}}} and {{{InterWikiMap.from_string}}} methods. e.g. {{{#!highlight python from MoinMoin.datastruct.backends.wiki_map import InterWikiMap interwiki_map = InterWikiMap.from_file('intermap.txt').iwmap }}} Now, use {{{interwiki_map}}} to access urls, just like you would do with a simple dictionary: e.g. {{{#!highlight python 'FOO' in interwiki_map print interwiki_map for name, url in interwiki_map.iteritems(): print name, '-->', url [etc.] }}}