jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/623009 )
Change subject: [IMPR] Prevent huge traceback from underlying python libraries
......................................................................
[IMPR] Prevent huge traceback from underlying python libraries
Bug: T253236
Change-Id: I4f8fdb82d538e467ea0e32a83dfb4108f771cc20
---
M pywikibot/comms/http.py
1 file changed, 12 insertions(+), 24 deletions(-)
Approvals:
Matěj Suchánek: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py
index 848a0b1..165d4c8 100644
--- a/pywikibot/comms/http.py
+++ b/pywikibot/comms/http.py
@@ -23,6 +23,7 @@
from http import cookiejar
from string import Formatter
+from typing import Optional, Tuple, Union
from urllib.parse import quote, urlparse
from warnings import warn
@@ -132,7 +133,7 @@
return username
-def user_agent(site=None, format_string=None):
+def user_agent(site=None, format_string: str = None) -> str:
"""
Generate the user agent string for a given site and format.
@@ -140,9 +141,7 @@
@type site: BaseSite
@param format_string: The string to which the values will be added using
str.format. Is using config.user_agent_format when it is None.
- @type format_string: basestring
@return: The formatted user agent
- @rtype: str
"""
values = USER_AGENT_PRODUCTS.copy()
@@ -201,12 +200,8 @@
return fake_user_agent()
-def fake_user_agent():
- """
- Return a fake user agent.
-
- @rtype: str
- """
+def fake_user_agent() -> str:
+ """Return a fake user agent."""
try:
from fake_useragent import UserAgent
except ImportError:
@@ -216,8 +211,8 @@
@deprecate_arg('ssl', None)
-def request(site=None, uri=None, method='GET', params=None, body=None,
- headers=None, data=None, **kwargs):
+def request(site=None, uri: Optional[str] = None, method='GET', params=None,
+ body=None, headers=None, data=None, **kwargs) -> str:
"""
Request to Site with default error handling and response decoding.
@@ -231,13 +226,11 @@
@param site: The Site to connect to
@type site: L{pywikibot.site.BaseSite}
@param uri: the URI to retrieve
- @type uri: str
@keyword charset: Either a valid charset (usable for str.decode()) or None
to automatically chose the charset from the returned header (defaults
to latin-1)
@type charset: CodecInfo, str, None
@return: The received data
- @rtype: a unicode string
"""
# body and data parameters both map to the data parameter of
# requests.Session.request.
@@ -269,14 +262,12 @@
return r.text
-def get_authentication(uri):
+def get_authentication(uri: str) -> Optional[Tuple[str, str]]:
"""
Retrieve authentication token.
@param uri: the URI to access
- @type uri: str
@return: authentication token
- @rtype: None or tuple of two str
"""
parsed_uri = requests.utils.urlparse(uri)
netloc_parts = parsed_uri.netloc.split('.')
@@ -294,7 +285,7 @@
return None
-def _http_process(session, http_request):
+def _http_process(session, http_request) -> None:
"""
Process an `threadedhttp.HttpRequest` instance.
@@ -302,8 +293,6 @@
@type session: L{requests.Session}
@param http_request: Request that will be processed.
@type http_request: L{threadedhttp.HttpRequest}
- @return: None
- @rtype: None
"""
method = http_request.method
uri = http_request.uri
@@ -356,7 +345,7 @@
if isinstance(request.data, Exception):
error('An error occurred for uri ' + request.uri)
- raise request.data
+ raise request.data from None
# HTTP status 207 is also a success status for Webdav FINDPROP,
# used by the version module.
@@ -420,8 +409,9 @@
def fetch(uri, method='GET', params=None, body=None, headers=None,
- default_error_handling=True, use_fake_user_agent=False, data=None,
- **kwargs):
+ default_error_handling: bool = True,
+ use_fake_user_agent: Union[bool, str] = False,
+ data=None, **kwargs):
"""
Blocking HTTP request.
@@ -431,8 +421,6 @@
See L{requests.Session.request} for parameters.
@param default_error_handling: Use default error handling
- @type default_error_handling: bool
- @type use_fake_user_agent: bool, str
@param use_fake_user_agent: Set to True to use fake UA, False to use
pywikibot's UA, str to specify own UA. This behaviour might be
overridden by domain in config.
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/623009
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I4f8fdb82d538e467ea0e32a83dfb4108f771cc20
Gerrit-Change-Number: 623009
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged