I think that we should have a function which tries to login and return the status whether that logging in is successful. What we currently do (for example in APISite.deletepage()) is that we "try: site.login(sysop=True) except pywikibot.NoUsername: blah blah" Isn't it better to have something like "if site.loginABC(sysop=True): blah blah else: blah blah"
So, I write this email to ask two things. First, should we have site.loginABC()? Second, if we should have that function, what should be the name of that function?
(see also http://lists.wikimedia.org/pipermail/pywikipedia-bugs/2014-January/007200.ht...; I think we need site.loginABC() there instead of site.logged_in())
See site.loggedInAs()
On Thu, Jan 23, 2014 at 8:09 PM, Sorawee Porncharoenwase < nullzero.free@gmail.com> wrote:
I think that we should have a function which tries to login and return the status whether that logging in is successful. What we currently do (for example in APISite.deletepage()) is that we "try: site.login(sysop=True) except pywikibot.NoUsername: blah blah" Isn't it better to have something like "if site.loginABC(sysop=True): blah blah else: blah blah"
So, I write this email to ask two things. First, should we have site.loginABC()? Second, if we should have that function, what should be the name of that function?
(see also http://lists.wikimedia.org/pipermail/pywikipedia-bugs/2014-January/007200.ht...; I think we need site.loginABC() there instead of site.logged_in())
-- Sorawee Porncharoenwase
Pywikipedia-l mailing list Pywikipedia-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikipedia-l
I don't think loggedInAs() has the same functionality as I proposed. First of all, it is deprecated. In addition, it just return self.logged_in(sysop) and self.user(), and neither self.logged_in(sysop) nor self.user() does login.
On Thu, Jan 23, 2014 at 8:13 PM, John phoenixoverride@gmail.com wrote:
See site.loggedInAs()
On Thu, Jan 23, 2014 at 8:09 PM, Sorawee Porncharoenwase < nullzero.free@gmail.com> wrote:
I think that we should have a function which tries to login and return the status whether that logging in is successful. What we currently do (for example in APISite.deletepage()) is that we "try: site.login(sysop=True) except pywikibot.NoUsername: blah blah" Isn't it better to have something like "if site.loginABC(sysop=True): blah blah else: blah blah"
So, I write this email to ask two things. First, should we have site.loginABC()? Second, if we should have that function, what should be the name of that function?
(see also http://lists.wikimedia.org/pipermail/pywikipedia-bugs/2014-January/007200.ht...; I think we need site.loginABC() there instead of site.logged_in())
-- Sorawee Porncharoenwase
Pywikipedia-l mailing list Pywikipedia-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikipedia-l
Pywikipedia-l mailing list Pywikipedia-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikipedia-l
If you look in compat you have the functions you want and loggedinas isnt depreciated
On Thu, Jan 23, 2014 at 8:23 PM, Sorawee Porncharoenwase < nullzero.free@gmail.com> wrote:
I don't think loggedInAs() has the same functionality as I proposed. First of all, it is deprecated. In addition, it just return self.logged_in(sysop) and self.user(), and neither self.logged_in(sysop) nor self.user() does login.
On Thu, Jan 23, 2014 at 8:13 PM, John phoenixoverride@gmail.com wrote:
See site.loggedInAs()
On Thu, Jan 23, 2014 at 8:09 PM, Sorawee Porncharoenwase < nullzero.free@gmail.com> wrote:
I think that we should have a function which tries to login and return the status whether that logging in is successful. What we currently do (for example in APISite.deletepage()) is that we "try: site.login(sysop=True) except pywikibot.NoUsername: blah blah" Isn't it better to have something like "if site.loginABC(sysop=True): blah blah else: blah blah"
So, I write this email to ask two things. First, should we have site.loginABC()? Second, if we should have that function, what should be the name of that function?
(see also http://lists.wikimedia.org/pipermail/pywikipedia-bugs/2014-January/007200.ht...; I think we need site.loginABC() there instead of site.logged_in())
-- Sorawee Porncharoenwase
Pywikipedia-l mailing list Pywikipedia-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikipedia-l
Pywikipedia-l mailing list Pywikipedia-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikipedia-l
-- Sorawee Porncharoenwase
Pywikipedia-l mailing list Pywikipedia-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikipedia-l
Hi Sorawee,
On 24 January 2014 02:09, Sorawee Porncharoenwase nullzero.free@gmail.comwrote:
I think that we should have a function which tries to login and return the status whether that logging in is successful. What we currently do (for example in APISite.deletepage()) is that we "try: site.login(sysop=True) except pywikibot.NoUsername: blah blah" Isn't it better to have something like "if site.loginABC(sysop=True): blah blah else: blah blah"
In the case of deletepage(), the 'must_be' decorator should have been used. That function takes care of calling self.login(sysop=True/False) to make sure the user is logged in as the correct user. So, basically,
def deletepage(self, page, summary): """Delete page from the wiki. Requires appropriate privilege level.
@param page: Page to be deleted. @param summary: Edit summary (required!).
""" try: self.login(sysop=True) except pywikibot.NoUsername as e: raise NoUsername("delete: Unable to login as sysop (%s)" % e.__class__.__name__) if not self.logged_in(sysop=True): raise NoUsername("delete: Unable to login as sysop") token = self.token(page, "delete")
should really be
@must_be('sysop') def deletepage(self, page, summary): """Delete page from the wiki. Requires appropriate privilege level.
@param page: Page to be deleted. @param summary: Edit summary (required!).
"""
token = self.token(page, "delete")
As for http://lists.wikimedia.org/pipermail/pywikipedia-bugs/2014-January/007200.ht...; it should check whether a sysop user is *configured*, not whether the current user is the sysop - you're completely right. The way to do that is to call
if site.username(sysop=True): # a sysop username has been configured else: # otherwise
The actual account switching is then done in the site object using the must_be wrapper.
Merlijn
pywikipedia-l@lists.wikimedia.org