jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/647719 )
Change subject: [IMPR] Delegate undefined method calls to requests.Response object ......................................................................
[IMPR] Delegate undefined method calls to requests.Response object
Enable the following properties and methods: history, reason. cookies, elapsed, request, ok, is_redirect, is_permanent_redirect, apparent_encoding, links, raise_for_status
Bug: T265206 Change-Id: I28f36266615bb1da6be4ea7d5643595a6ebee364 --- M pywikibot/comms/threadedhttp.py 1 file changed, 6 insertions(+), 13 deletions(-)
Approvals: Mpaa: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/comms/threadedhttp.py b/pywikibot/comms/threadedhttp.py index c5c0e38..9e22711 100644 --- a/pywikibot/comms/threadedhttp.py +++ b/pywikibot/comms/threadedhttp.py @@ -57,6 +57,12 @@ self._parsed_uri = None self._data = None
+ def __getattr__(self, name): + """Delegate undefined method calls to request.Response object.""" + if self.exception and name in ('content', 'status_code'): + return None + return getattr(self.data, name) + @property @deprecated('the `url` attribute', since='20201011', future_warning=True) def uri(self): # pragma: no cover @@ -154,11 +160,6 @@ return self.status_code
@property - def status_code(self) -> Optional[int]: - """Return the HTTP response status.""" - return self.data.status_code if not self.exception else None - - @property def header_encoding(self): """Return charset given by the response header.""" if hasattr(self, '_header_encoding'): @@ -236,14 +237,6 @@ encoding, errors) if not self.exception else None
@property - def content(self) -> bytes: - """Return the response in bytes. - - @note: The behaviour has been changed. - """ - return self.data.content if not self.exception else None - - @property def text(self) -> str: """Return the response decoded by the detected encoding.""" return self.content.decode(self.encoding)
pywikibot-commits@lists.wikimedia.org