[prev in list] [next in list] [prev in thread] [next in thread]
List: pywikipediabot-users
Subject: Re: [Pywikipedia-l] Propose to create another function to login
From: Merlijn van Deen <valhallasw () arctus ! nl>
Date: 2014-01-24 9:27:04
Message-ID: CADJO0eKuXkMLG-js6PiNnxK8qAgEYsPcSXRAkYyJS97YPP4Meg () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
Hi Sorawee,
On 24 January 2014 02:09, 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"
>
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.html;
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
[Attachment #5 (text/html)]
<div dir="ltr">Hi Sorawee,<div class="gmail_extra"><br><div class="gmail_quote">On 24 \
January 2014 02:09, Sorawee Porncharoenwase <span dir="ltr"><<a \
href="mailto:nullzero.free@gmail.com" \
target="_blank">nullzero.free@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div \
dir="ltr"><div>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"</div>
</div></blockquote><div><br></div><div>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,</div>
<div><br></div><div><div> def deletepage(self, page, summary):</div><div> \
"""Delete page from the wiki. Requires appropriate privilege \
level.</div><div><br></div><div> @param page: Page to be deleted.</div>
<div> @param summary: Edit summary (required!).</div><div><br></div><div> \
"""</div><div> try:</div><div> \
self.login(sysop=True)</div><div> except pywikibot.NoUsername as e:</div>
<div> raise NoUsername("delete: Unable to login as sysop \
(%s)"</div><div> % e.__class__.__name__)</div><div> \
if not self.logged_in(sysop=True):</div><div> raise \
NoUsername("delete: Unable to login as sysop")</div>
<div> token = self.token(page, \
"delete")</div></div><div><br></div><div>should really \
be</div><div><br></div><div> @must_be('sysop')</div><div><div> def \
deletepage(self, page, summary):</div>
<div> """Delete page from the wiki. Requires appropriate \
privilege level.</div><div><br></div><div> @param page: Page to be \
deleted.</div><div> @param summary: Edit summary (required!).</div>
<div><br></div><div> """</div><div><br></div><div> \
token = self.token(page, \
"delete")</div></div><div><br></div><div><br></div><div>As for <a \
href="http://lists.wikimedia.org/pipermail/pywikipedia-bugs/2014-January/007200.html" \
target="_blank">http://lists.wikimedia.org/pipermail/pywikipedia-bugs/2014-January/007200.html</a>; \
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</div>
<div><br></div><div>if site.username(sysop=True):<br></div><div> # a sysop \
username has been configured</div><div>else:</div><div> # \
otherwise</div><div><br></div><div><br></div><div>The actual account switching is \
then done in the site object using the must_be wrapper.</div>
<div><br></div><div>Merlijn</div></div></div></div>
[Attachment #6 (text/plain)]
_______________________________________________
Pywikipedia-l mailing list
Pywikipedia-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/pywikipedia-l
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic