[Pywikipedia-l] [Pywikipedia-svn] SVN: [6978] trunk/pywikipedia/wikipedia.py

Maarten Dammers maarten at mdammers.nl
Thu Jun 25 10:22:02 UTC 2009


Nicdumz,

I'm getting this:

Traceback (most recent call last):
  File "/home/multichill/bot/loose_category_from_gallery.py", line 137, in <module>
    main()
  File "/home/multichill/bot/loose_category_from_gallery.py", line 106, in main
    imagerecat.initLists()
  File "/home/multichill/pywikipedia/imagerecat.py", line 53, in initLists
    for cat in blacklistPage.linkedPages():
  File "/home/multichill/pywikipedia/wikipedia.py", line 1815, in linkedPages
    thistxt = self.site().resolvemagicwords(thistxt)
  File "/home/multichill/pywikipedia/wikipedia.py", line 5916, in resolvemagicwords
    named = re.compile(u'{{ns:(' + '|'.join(defaults) + ')}}', re.I)
TypeError: sequence item 21: expected string or Unicode, list found

Could you please take a look at it?

Maarten

nicdumz at svn.wikimedia.org schreef:
> Revision: 6978
> Author:   nicdumz
> Date:     2009-06-21 13:58:28 +0000 (Sun, 21 Jun 2009)
>
> Log Message:
> -----------
> Adding a Site.resolvemagicwords member.
> For now, only resolves {{ns:xx}} words, but is meant to be expanded.
>
> This solves issue #2805572
>
> Modified Paths:
> --------------
>     trunk/pywikipedia/wikipedia.py
>
> Modified: trunk/pywikipedia/wikipedia.py
> ===================================================================
> --- trunk/pywikipedia/wikipedia.py	2009-06-21 10:46:10 UTC (rev 6977)
> +++ trunk/pywikipedia/wikipedia.py	2009-06-21 13:58:28 UTC (rev 6978)
> @@ -1811,6 +1811,9 @@
>          # from text before processing
>          thistxt = removeDisabledParts(thistxt)
>  
> +        # resolve {{ns:-1}} or {{ns:Help}}
> +        thistxt = self.site().resolvemagicwords(thistxt)
> +
>          for match in Rlink.finditer(thistxt):
>              title = match.group('title')
>              title = title.replace("_", " ").strip(" ")
> @@ -5898,6 +5901,32 @@
>                                   + '\s*:?\s*\[\[(.+?)(?:\|.*?)?\]\]',
>                            re.IGNORECASE | re.UNICODE | re.DOTALL)
>  
> +    def resolvemagicwords(self, wikitext):
> +        """Replace the {{ns:xx}} marks in a wikitext with the namespace names"""
> +
> +        defaults = []
> +        for namespace in self.family.namespaces.itervalues():
> +            value = namespace.get('_default', None)
> +            if value:    
> +                if isinstance(value, list):
> +                    defaults += value
> +                else:
> +                    defaults.append(value)
> +
> +        named = re.compile(u'{{ns:(' + '|'.join(defaults) + ')}}', re.I)
> +
> +        def replacenamed(match):
> +            return self.normalizeNamespace(match.group(1))
> +
> +        wikitext = named.sub(replacenamed, wikitext)
> +
> +        numbered = re.compile('{{ns:(-?\d{1,2})}}', re.I)
> +
> +        def replacenumbered(match):
> +            return self.namespace(int(match.group(1)))
> +        
> +        return named.sub(replacenumbered, wikitext)
> +
>      # The following methods are for convenience, so that you can access
>      # methods of the Family class easier.
>      def encoding(self):
>
>
>
> _______________________________________________
> Pywikipedia-svn mailing list
> Pywikipedia-svn at lists.wikimedia.org
> https://lists.wikimedia.org/mailman/listinfo/pywikipedia-svn
>   





More information about the Pywikipedia-l mailing list