I propose this change:
- set `page.text` to `None` to discard changes - delete `page.text` to reload content -- equivalent to get(force=True) - in Page.save(), if `page.text` is equal to unchanged text, no API call - to touch a page, use page.touch(), which will call action="edit" & appendtext="", instead. The advantage is that there is no need to preload text.
Sorawee Porncharoenwase
Not a good idea, how do you save a blank page?
On Tuesday, September 2, 2014, Sorawee Porncharoenwase < nullzero.free@gmail.com> wrote:
I propose this change:
- set `page.text` to `None` to discard changes
- delete `page.text` to reload content -- equivalent to get(force=True)
- in Page.save(), if `page.text` is equal to unchanged text, no API call
- to touch a page, use page.touch(), which will call action="edit" &
appendtext="", instead. The advantage is that there is no need to preload text.
Sorawee Porncharoenwase
text method would be like this:
def text(self): """Return the current (edited) wikitext, loading it if necessary.
@return: unicode """ kwargs = {} if not hasattr(self, '_text'): kwargs['force'] = True if not hasattr(self, '_text') or self._text is None: try: self._text = self.get(get_redirect=True, **kwargs) except pywikibot.NoPage: # TODO: what other exceptions might be returned? self._text = u"" return self._text
On Tue, Sep 2, 2014 at 12:38 PM, John phoenixoverride@gmail.com wrote:
Not a good idea, how do you save a blank page?
On Tuesday, September 2, 2014, Sorawee Porncharoenwase < nullzero.free@gmail.com> wrote:
I propose this change:
- set `page.text` to `None` to discard changes
- delete `page.text` to reload content -- equivalent to get(force=True)
- in Page.save(), if `page.text` is equal to unchanged text, no API call
- to touch a page, use page.touch(), which will call action="edit" &
appendtext="", instead. The advantage is that there is no need to preload text.
Sorawee Porncharoenwase
Pywikipedia-l mailing list Pywikipedia-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikipedia-l
On Wed, Sep 3, 2014 at 2:29 AM, Sorawee Porncharoenwase nullzero.free@gmail.com wrote:
I propose this change:
- set `page.text` to `None` to discard changes
Doesn't the page.text setter already do this?
- delete `page.text` to reload content -- equivalent to get(force=True)
del page.text already removes the cached / modified page text.
so a forced reload of text is currently two lines:
del page.text new = page.text
I dont see why 'del page.text' should initiate network activity to reload the page text.
- in Page.save(), if `page.text` is equal to unchanged text, no API call
- to touch a page, use page.touch(), which will call action="edit" &
appendtext="", instead. The advantage is that there is no need to preload text.
We have a touch() changeset pending.
https://gerrit.wikimedia.org/r/#/c/144717/
On Fri, Sep 5, 2014 at 5:00 AM, John Mark Vandenberg jayvdb@gmail.com wrote:
On Wed, Sep 3, 2014 at 2:29 AM, Sorawee Porncharoenwase nullzero.free@gmail.com wrote:
I propose this change:
- set `page.text` to `None` to discard changes
Doesn't the page.text setter already do this?
Yes, it already does this. Currently, `del page.text` and `page.text = None` do the same thing. Since I want to change the functionality of `del page.text`, I wrote "set `page.text` to `None` to discard changes" to say that `page.text = None` will not be changed.
- delete `page.text` to reload content -- equivalent to get(force=True)
del page.text already removes the cached / modified page text.
so a forced reload of text is currently two lines:
del page.text new = page.text
I dont see why 'del page.text' should initiate network activity to reload the page text.
It seems to me that we want to switch get() to text property instead. To make text can do what get() can do, we want an ability to force reloading page--maybe to get the latest edit of a page which is edited frequently.
- in Page.save(), if `page.text` is equal to unchanged text, no API call
Currently, when I want to do find & replace, I have to write
text = page.text.replace(find, replace) if text != page.text: # avoid API call page.text = text page.save()
In the past, we have put(), so I can just write
text = page.get().replace(find, replace) if text != page.text: page.put(text)
I therefore think that the current functionality of save() is not useful much. I think that the right code for this is
page.text = page.text.replace(find, replace) page.save()
In order to make this possible, if the text is unchanged, there should be no API call.
- to touch a page, use page.touch(), which will call action="edit" &
appendtext="", instead. The advantage is that there is no need to preload text.
We have a touch() changeset pending.
Can I submit another patchset for 144717? action="edit" & appendtext="" is a better way to go because we don't have to retrieve text at all.
-- John Vandenberg
Pywikipedia-l mailing list Pywikipedia-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikipedia-l
2014-09-02 18:29 GMT+02:00 Sorawee Porncharoenwase nullzero.free@gmail.com :
- set `page.text` to `None` to discard changes
Not sure I like this, it seems to be a semantic mess and a little too much Page object implementation related. Of course internally if the text attribute value is None this usually mean the page have not been loaded yet and practically it discard changes.
But imagine a user for whom the Page object is the representation of a Wikipage on server. He may have no idea of how the Page object is implemented. He may believe if he does this and saves the page he actually will blank the page on server when saving (actually if I read the code well it will raise an error in the site.editpage function)
Why not use something more explicit as a "discard_changes" function ? I don't really like the raw access to the attribute as it exposes some implementation details
Of course python has setter methods, but when I read
@text.setter def text(self, value): """Update the current (edited) wikitext. @param value: New value or None @param value: basestring """ self._text = None if value is None else unicode(value) and
@text.deleter def text(self): """Delete the current (edited) wikitext.""" if hasattr(self, "_text"): del self._text I find there is a lot of implicit for a pythonic program :) at least the meaning and the effects should be more explicitely documented.