Hi,
I would like to suggest a different implementation for copying Page
objects. Currently, it involves doing something like this:
original_page = mwclient.page.Page(site, 'Some page')
copied_page = mwclient.page.Page(site, original_page)
This is not very convenient, returns a shallow copy of the object, and
silently ignores the 'site' parameter. Hence I propose this change:
Index: page.py
===================================================================
--- page.py (revision 82)
+++ page.py (working copy)
@@ -6,8 +6,8 @@
class Page(object):
def __init__(self, site, name, info = None, extra_properties = {}):
- if type(name) is type(self):
- return self.__dict__.update(name.__dict__)
+ if not isinstance(name, basestring):
+ raise TypeError("'name' must be a string")
self.site = site
self.name = name
@@ -41,6 +41,8 @@
self.last_rev_time = None
self.edit_time = None
+ def copy(self):
+ return self.__class__(self.site, self.name, self._info)
def __repr__(self):
return "<Page object '%s' for %s>" % (self.name.encode('utf-8'), self.site)
With the above patch, copying a Page (or Image) object becomes:
original_page = mwclient.page.Page(site, 'Some page')
copied_page = original_page.copy()
This time, the new object is a deep copy (except for copied_page._info,
but no one is supposed to mess with that anyway), and the syntax is
greatly simplified.
What do you think?
Benoît Knecht
|