Hi,
Noticed one of my scripts failing because I tried to instantiate a category named "Wikipedia:Globalt perspektiv-samtliga" (it's in Swedish Wikipedia, here's the actual category: http://sv.wikipedia.org/wiki/Kategori:Wikipedia:Globalt_perspektiv-samtliga)
This fails: myCat = pywikibot.Category(mySite, "Wikipedia:Globalt perspektiv-samtliga");
The error is: ValueError: 'Wikipedia:Globalt perspektiv-samtliga' is not in the category namespace!
Creating it as a page with namespace set to 14 results in: >>> myPage = pywikibot.Page(mySite, 'Wikipedia:Globalt perspektiv-samtliga', ns=14); >>> print myPage.title(); Wikipedia:Globalt perspektiv-samtliga >>> print myPage.namespace(); 4
The title's namespace overrides the given option, which itsn't what I would expect. However, if I add the category namespace prefix to the title (localised to Swedish it's "Kategori:Wikipedia:Globalt perspektiv-samtliga"), I get the right namespace and such.
Not sure if this is a bug or a feature, so I figured I'd post a note here and see if anyone had any views on it, rather than just file the bug in SF.
Cheers, Morten
Morten Wang wrote:
Noticed one of my scripts failing because I tried to instantiate a category named "Wikipedia:Globalt perspektiv-samtliga" (it's in Swedish Wikipedia, here's the actual category: http://sv.wikipedia.org/wiki/Kategori:Wikipedia:Globalt_perspektiv-samtliga)
This fails: myCat = pywikibot.Category(mySite, "Wikipedia:Globalt perspektiv-samtliga");
The error is: ValueError: 'Wikipedia:Globalt perspektiv-samtliga' is not in the category namespace!
That should fail; it would equally fail if you tried myCat = pywikibot.Category(mySite, "Garbage") since "Garbage" is not in the Category namespace. In other words, the fact that the category title starts with "Wikipedia:" has nothing to do with it. However, this should work: myCat = pywikibot.Category(mySite, "Kategori:Wikipedia:Globalt perspektiv-samtliga");
Creating it as a page with namespace set to 14 results in:
myPage = pywikibot.Page(mySite, 'Wikipedia:Globalt
perspektiv-samtliga', ns=14);
print myPage.title();
Wikipedia:Globalt perspektiv-samtliga
print myPage.namespace();
4
The title's namespace overrides the given option, which itsn't what I would expect.
That one does seem like a bug. The namespace number ought to match the actual title. I'll investigate further.
Russ
On Tue, Jun 14, 2011 at 12:28 PM, Russell Blau russblau@imapmail.orgwrote:
That should fail; it would equally fail if you tried myCat = pywikibot.Category(mySite, "Garbage") since "Garbage" is not in the Category namespace. In other words, the fact that the category title starts with "Wikipedia:" has nothing to do with it.
Hm, I struggle to understand why your example is supposed to fail, it attempts to create a Page object with title "Garbage" and ns=14, that's a perfectly valid page, isn't it? (except that myCat.exists() returns False, of course, as expected)
However, this should work: myCat = pywikibot.Category(mySite, "Kategori:Wikipedia:Globalt perspektiv-samtliga");
Yes, that does work, so I've chosen to go with the straightforward workaround that I'll prefix any category name with site.category_namespace() and ":". That's partly why I chose to post to the list, in case that'll just be defined as expected behaviour, I have no problem with having to qualify the names that way :)
Creating it as a page with namespace set to 14 results in:
myPage = pywikibot.Page(mySite, 'Wikipedia:Globalt
perspektiv-samtliga', ns=14);
print myPage.title();
Wikipedia:Globalt perspektiv-samtliga
print myPage.namespace();
4
The title's namespace overrides the given option, which itsn't what I would expect.
That one does seem like a bug. The namespace number ought to match the actual title. I'll investigate further.
Thanks, let me know if there's anything I can do to help!
Cheers, Morten
Morten Wang wrote:
On Tue, Jun 14, 2011 at 12:28 PM, Russell Blau russblau@imapmail.org wrote:
...
Creating it as a page with namespace set to 14 results in:
myPage = pywikibot.Page(mySite, 'Wikipedia:Globalt
perspektiv-samtliga', ns=14);
print myPage.title();
Wikipedia:Globalt perspektiv-samtliga
print myPage.namespace();
4
The title's namespace overrides the given option, which itsn't what I would expect.
That one does seem like a bug. The namespace number ought to match the actual title. I'll investigate further.
Thanks, let me know if there's anything I can do to help!
Sorry for the delay in getting to this. On further study, this is exactly the same behavior as found in the original wikipedia.py.
import wikipedia mySite = wikipedia.getSite() myPage = wikipedia.Page(mySite, 'Wikipedia:Globalt perspektiv-samtliga', defaultNamespace=14) print myPage.title()
Wikipedia:Globalt perspektiv-samtliga
print myPage.namespace()
4
So, if there is a bug, it is not in the rewrite branch but in the original design. I don't think it is a bug, though, because "defaultNamespace" is supposed to be applied only when the string passed to the Page constructor does not contain any namespace prefix.
Russ
pywikipedia-l@lists.wikimedia.org