r2005 pywikipedia - Code Review archive

Repository:pywikipedia
Revision:r2004‎ | r2005 | r2006 >
Date:09:14, 22 July 2005
Author:wikipedian
Status:old
Tags:
Comment:
renamed Page.catname() to Page.titleWithoutNamespace()
Modified paths:
  • /trunk/pywikipedia/category.py (modified) (history)
  • /trunk/pywikipedia/catlib.py (modified) (history)
  • /trunk/pywikipedia/wikipedia.py (modified) (history)

Diff [purge]

Index: trunk/pywikipedia/category.py
@@ -408,7 +408,7 @@
409409 if current_cat == original_cat:
410410 print 'No changes necessary.'
411411 else:
412 - catlib.change_category(article, original_cat.catname(), current_cat.catname())
 412+ catlib.change_category(article, original_cat.titleWithoutNamespace(), current_cat.titleWithoutNamespace())
413413 flag = True
414414 elif choice == 'j':
415415 newCatTitle = wikipedia.input(u'Please enter the category the article should be moved to:')
@@ -418,7 +418,7 @@
419419 flag = True
420420 elif choice == 'r':
421421 # remove the category tag
422 - catlib.change_category(article, original_cat.catname(), None)
 422+ catlib.change_category(article, original_cat.titleWithoutNamespace(), None)
423423 flag = True
424424 elif choice == '?':
425425 print ''
Index: trunk/pywikipedia/catlib.py
@@ -265,7 +265,7 @@
266266 cats.remove(cat)
267267 removed = True
268268 elif cattext.startswith(old_cat_title + '|'):
269 - sort_key = cat.catname().split('|', 1)[1]
 269+ sort_key = cat.titleWithoutNamespace().split('|', 1)[1]
270270 cats.remove(cat)
271271 removed = True
272272 if not removed:
Index: trunk/pywikipedia/wikipedia.py
@@ -138,9 +138,6 @@
139139 class SectionError(ValueError):
140140 """The section specified by # does not exist"""
141141
142 -class NoNamespace(Error):
143 - """Page is not in a special namespace"""
144 -
145142 class PageNotSaved(Error):
146143 """ Saving the page has failed """
147144
@@ -240,16 +237,17 @@
241238 """The name of this Page, as a Unicode string"""
242239 return self._title
243240
244 - def catname(self):
 241+ def titleWithoutNamespace(self):
245242 """The name of the page without the namespace part. Gives an error
246243 if the page is from the main namespace. Note that this is a raw way
247244 of doing things - it simply looks for a : in the name."""
248245 t=self.sectionFreeTitle()
249 - p=t.split(':')
250 - p=p[1:]
251 - if p==[]:
252 - raise NoNamespace(self)
253 - return ':'.join(p)
 246+ p=t.split(':', 1)
 247+ if len(p) == 1:
 248+ # page is in the main namespace
 249+ return p[0]
 250+ else:
 251+ return p[1]
254252
255253 def section(self):
256254 """The name of the section this Page refers to. Sections are

Status & tagging log