Xqt submitted this change.

View Change

Approvals: Xqt: Verified; Looks good to me, approved
[IMPR] Simplify _decide_encoding

Change-Id: I67bebe73180bf01d44e282a737aab42e722b528e
---
M pywikibot/comms/http.py
1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py
index c5c4b11..4948f15 100644
--- a/pywikibot/comms/http.py
+++ b/pywikibot/comms/http.py
@@ -480,25 +480,19 @@

# No charset requested, or in request headers or response headers.
# Defaults to latin1.
- if charset is None and header_encoding is None:
- return _try_decode(response.content, 'latin1')
+ if charset is None:
+ return _try_decode(response.content, header_encoding or 'latin1')

- if charset is None and header_encoding is not None:
- return _try_decode(response.content, header_encoding)
-
- if charset is not None and header_encoding is None:
+ if header_encoding is None:
return _try_decode(response.content, charset)

# Both charset and header_encoding are available.
- try:
+ header_codecs = charset_codecs = None
+ with suppress(LookupError):
header_codecs = codecs.lookup(header_encoding)
- except LookupError:
- header_codecs = None

- try:
+ with suppress(LookupError):
charset_codecs = codecs.lookup(charset)
- except LookupError:
- charset_codecs = None

if header_codecs and charset_codecs and header_codecs != charset_codecs:
pywikibot.warning(

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I67bebe73180bf01d44e282a737aab42e722b528e
Gerrit-Change-Number: 831178
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged