jenkins-bot merged this change.

View Change

Approvals: Dvorapa: Looks good to me, approved jenkins-bot: Verified
[IMPR] Simplify http.user_agent_username

- simplify the code in user_agent_username() and return the
calculated username at the end

Change-Id: Ic21709a50cedbf5cf0451432d39903342a508751
---
M pywikibot/comms/http.py
1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py
index fd32330..a860996 100644
--- a/pywikibot/comms/http.py
+++ b/pywikibot/comms/http.py
@@ -162,21 +162,19 @@
"""
if not username:
return ''
+
username = username.replace(' ', '_') # Avoid spaces or %20.
try:
username.encode('ascii') # just test, but not actually use it
except UnicodeEncodeError:
- pass
+ username = quote(username.encode('utf-8'))
else:
# % is legal in the default $wgLegalTitleChars
# This is so that ops know the real pywikibot will not
# allow a useragent in the username to allow through a hand-coded
# percent-encoded value.
if '%' in username:
- return quote(username)
- else:
- return username
- username = quote(username.encode('utf-8'))
+ username = quote(username)
return username



To view, visit change 606410. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic21709a50cedbf5cf0451432d39903342a508751
Gerrit-Change-Number: 606410
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Dvorapa <dvorapa@seznam.cz>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot (75)