jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/658044 )

Change subject: [cleanup] Remove unused threadedhttp.py
......................................................................

[cleanup] Remove unused threadedhttp.py

threadedhttp.HttpRequest was already replaced with requests.Response

Bug: T265206
Change-Id: If048c853727590b0e8bf0412643649e4b355687a
---
M docs/api_ref/pywikibot.comms.rst
M pywikibot/CONTENT.rst
D pywikibot/comms/threadedhttp.py
M tests/utils.py
4 files changed, 12 insertions(+), 319 deletions(-)

Approvals:
  JJMC89: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/docs/api_ref/pywikibot.comms.rst b/docs/api_ref/pywikibot.comms.rst
index 53f1598..abe9441 100644
--- a/docs/api_ref/pywikibot.comms.rst
+++ b/docs/api_ref/pywikibot.comms.rst
@@ -16,9 +16,4 @@

 .. automodule:: pywikibot.comms.http

-pywikibot.comms.threadedhttp module
------------------------------------
-
-.. automodule:: pywikibot.comms.threadedhttp
-

diff --git a/pywikibot/CONTENT.rst b/pywikibot/CONTENT.rst
index fc7b721..a0f8036 100644
--- a/pywikibot/CONTENT.rst
+++ b/pywikibot/CONTENT.rst
@@ -84,8 +84,6 @@
     
+----------------------------+------------------------------------------------------+
     | http.py                    | Basic HTTP access interface                 
         |
     
+----------------------------+------------------------------------------------------+
-    | threadedhttp.py            | HTTP requests wrapper                       
         |
-    
+----------------------------+------------------------------------------------------+


     
+----------------------------+------------------------------------------------------+
diff --git a/pywikibot/comms/threadedhttp.py b/pywikibot/comms/threadedhttp.py
deleted file mode 100644
index d5c26f5..0000000
--- a/pywikibot/comms/threadedhttp.py
+++ /dev/null
@@ -1,302 +0,0 @@
-"""Http backend layer providing a HTTP requests wrapper."""
-#
-# (C) Pywikibot team, 2007-2020
-#
-# Distributed under the terms of the MIT license.
-#
-import codecs
-import re
-
-from typing import Optional
-from urllib.parse import urlparse
-
-import pywikibot
-
-from pywikibot.backports import Dict
-from pywikibot.tools import (
-    deprecated,
-    deprecated_args,
-    issue_deprecation_warning,
-    ModuleDeprecationWrapper,
-)
-
-
-_logger = 'comms.threadedhttp'
-
-
-class HttpRequest:
-
-    """Object wrapper for HTTP requests.
-
-    self.data will be either:
-    * requests.Response object if the request was successful
-    * an exception
-    """
-
-    @deprecated_args(uri=True, method=True, params=True, body=True,
-                     headers=True, all_headers=True)
-    def __init__(self, url=None, method=None, params=None, body=None,
-                 all_headers=None, callbacks=None, charset=None, **kwargs):
-        """Initializer."""
-        if isinstance(charset, codecs.CodecInfo):
-            self.charset = charset.name
-        else:
-            self.charset = charset
-
-        self._kwargs = kwargs
-        self._parsed_uri = None
-        self._data = None
-
-        # deprecate positional parameters
-        if url:
-            issue_deprecation_warning("'url' parameter", depth=3,
-                                      warning_class=FutureWarning,
-                                      since='20201211')
-        if method:
-            issue_deprecation_warning("'method' parameter",
-                                      warning_class=FutureWarning,
-                                      since='20201211')
-        if params:
-            issue_deprecation_warning("'params' parameter",
-                                      warning_class=FutureWarning,
-                                      since='20201211')
-        if body:
-            issue_deprecation_warning("'body' parameter",
-                                      warning_class=FutureWarning,
-                                      since='20201211')
-        if all_headers:
-            issue_deprecation_warning("'all_headers' parameter",
-                                      warning_class=FutureWarning,
-                                      since='20201211')
-        if callbacks:
-            issue_deprecation_warning("'callbacks' parameter",
-                                      warning_class=FutureWarning,
-                                      since='20201211')
-        if kwargs:
-            for item in kwargs.items():
-                issue_deprecation_warning('{}={!r} parameter'.format(*item),
-                                          warning_class=FutureWarning,
-                                          since='20201211')
-
-    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(since='20201211', future_warning=True)
-    def args(self):  # pragma: no cover
-        """DEPRECATED: Return predefined argument list."""
-        return [
-            self.url,
-            self.request.method,
-            self.request.body,
-            self.all_headers,
-        ]
-
-    @property
-    @deprecated('the `request.body` attribute',
-                since='20201211', future_warning=True)
-    def body(self):  # pragma: no cover
-        """DEPRECATED: Return request body attribute."""
-        return self.request.body
-
-    @property
-    @deprecated(since='20201211', future_warning=True)
-    def kwargs(self):  # pragma: no cover
-        """DEPRECATED: Return request body attribute."""
-        return self._kwargs
-
-    @property
-    @deprecated('the `request.method` attribute',
-                since='20201211', future_warning=True)
-    def method(self):  # pragma: no cover
-        """DEPRECATED: Return request body attribute."""
-        return self.request.method
-
-    @property
-    @deprecated('the `url` attribute', since='20201011', future_warning=True)
-    def uri(self):  # pragma: no cover
-        """DEPRECATED. Return the response URL."""
-        return self.url
-
-    @property
-    @deprecated('the `request.headers` property', since='20201011',
-                future_warning=True)
-    def headers(self):  # pragma: no cover
-        """DEPRECATED. Return the response headers."""
-        return self.request.headers
-
-    @property
-    @deprecated('the `request.headers` property', since='20201211',
-                future_warning=True)
-    def all_headers(self):  # pragma: no cover
-        """DEPRECATED. Return the response headers."""
-        return self.request.headers
-
-    @property
-    def data(self):
-        """DEPRECATED. Return the requests response tuple.
-
-        @note: This property will removed.
-        """
-        assert(self._data is not None)
-        return self._data
-
-    @data.setter
-    def data(self, value):
-        """DEPRECATED. Set the requests response and invoke each callback.
-
-        @note: This property setter will removed.
-        """
-        self._data = value
-
-    @property
-    def exception(self) -> Optional[Exception]:
-        """DEPRECATED. Get the exception, if any.
-
-        @note: This property will removed.
-        """
-        return self.data if isinstance(self.data, Exception) else None
-
-    @property
-    def response_headers(self) -> Optional[Dict[str, str]]:
-        """DEPRECATED. Return the response headers.
-
-        @note: This property will renamed to headers.
-        """
-        return self.data.headers if not self.exception else None
-
-    @property
-    @deprecated('the `content` property', since='20201210',
-                future_warning=True)
-    def raw(self) -> Optional[bytes]:  # pragma: no cover
-        """DEPRECATED. Return the raw response body.
-
-        @note: The behaviour will be changed.
-        """
-        return self.content
-
-    @property
-    @deprecated('urlparse(HttpRequest.url)',
-                since='20201011', future_warning=True)
-    def parsed_uri(self):  # pragma: no cover
-        """DEPRECATED. Return the parsed requested uri."""
-        if not self._parsed_uri:
-            self._parsed_uri = urlparse(self.uri)
-        return self._parsed_uri
-
-    @property
-    @deprecated('urlparse(HttpRequest.url).netloc',
-                since='20201011', future_warning=True)
-    def hostname(self):  # pragma: no cover
-        """DEPRECATED. Return the host of the request."""
-        return self.parsed_uri.netloc
-
-    @property
-    @deprecated('the `status_code` property', since='20201011',
-                future_warning=True)
-    def status(self) -> Optional[int]:  # pragma: no cover
-        """DEPRECATED. Return the HTTP response status."""
-        return self.status_code
-
-    @property
-    def header_encoding(self):
-        """Return charset given by the response header."""
-        if hasattr(self, '_header_encoding'):
-            return self._header_encoding
-
-        content_type = self.response_headers.get('content-type', '')
-        m = re.search('charset=(?P<charset>.*?$)', content_type)
-        if m:
-            self._header_encoding = m.group('charset')
-        elif 'json' in content_type:
-            # application/json | application/sparql-results+json
-            self._header_encoding = 'utf-8'
-        elif 'xml' in content_type:
-            header = self.content[:100].splitlines()[0]  # bytes
-            m = re.search(
-                br'encoding=(["\'])(?P<encoding>.+?)\1', header)
-            if m:
-                self._header_encoding = m.group('encoding').decode('utf-8')
-            else:
-                self._header_encoding = 'utf-8'
-        else:
-            self._header_encoding = None
-
-        return self._header_encoding
-
-    @property
-    def encoding(self):
-        """Detect the response encoding."""
-        if hasattr(self, '_encoding'):
-            return self._encoding
-
-        if self.charset is None and self.request is not None:
-            self.charset = self.request.headers.get('accept-charset')
-
-        if self.charset is None and self.header_encoding is None:
-            pywikibot.log("Http response doesn't contain a charset.")
-            charset = 'latin1'
-        else:
-            charset = self.charset
-
-        _encoding = UnicodeError()
-        if self.header_encoding is not None \
-           and (charset is None
-                or codecs.lookup(self.header_encoding)
-                != codecs.lookup(charset)):
-            if charset:
-                pywikibot.warning(
-                    'Encoding "{}" requested but "{}" received in the '
-                    'header.'.format(charset, self.header_encoding))
-
-            # TODO: Buffer decoded content, weakref does remove it too
-            #       early (directly after this method)
-            _encoding = self._try_decode(self.header_encoding)
-
-        if charset and isinstance(_encoding, Exception):
-            _encoding = self._try_decode(charset)
-
-        if isinstance(_encoding, Exception):
-            raise _encoding
-        else:
-            self._encoding = _encoding
-        return self._encoding
-
-    def _try_decode(self, encoding):
-        """Helper function to try decoding."""
-        try:
-            self.content.decode(encoding)
-        except UnicodeError as e:
-            result = e
-        else:
-            result = encoding
-        return result
-
-    @deprecated('the `text` property', since='20201011', future_warning=True)
-    def decode(self, encoding, errors='strict') -> str:  # pragma: no cover
-        """Return the decoded response."""
-        return self.content.decode(
-            encoding, errors) 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)
-
-    @deprecated('the `text` property', since='20201011', future_warning=True)
-    def __str__(self) -> str:  # pragma: no cover
-        """Return the response decoded by the detected encoding."""
-        return self.text
-
-    @deprecated(since='20201011', future_warning=True)
-    def __bytes__(self) -> Optional[bytes]:  # pragma: no cover
-        """Return the undecoded response."""
-        return self.content
-
-
-wrapper = ModuleDeprecationWrapper(__name__)
-wrapper._add_deprecated_attr('HttpRequest', replacement_name='',
-                             since='20201226', future_warning=True)
diff --git a/tests/utils.py b/tests/utils.py
index 5f77cf1..291f11d 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -15,14 +15,10 @@
 from subprocess import PIPE, Popen, TimeoutExpired
 from types import ModuleType

-try:
-    from cryptography import __version__ as cryptography_version
-    cryptography_version = list(map(int, cryptography_version.split('.')))
-except ImportError:
-    cryptography_version = None
+from requests import Response

 import pywikibot
-from pywikibot.comms import threadedhttp
+
 from pywikibot import config
 from pywikibot.data.api import CachedRequest, APIError
 from pywikibot.data.api import Request as _original_Request
@@ -30,6 +26,12 @@
 from pywikibot.site import Namespace
 from tests import _pwb_py, unittest

+try:
+    from cryptography import __version__ as cryptography_version
+    cryptography_version = list(map(int, cryptography_version.split('.')))
+except ImportError:
+    cryptography_version = None
+

 OSWIN32 = (sys.platform == 'win32')

@@ -475,9 +477,9 @@
         result = self.__wrapper.before_fetch(*args, **kwargs)
         if result is False:
             result = self.__wrapper._old_http.fetch(*args, **kwargs)
-        elif not isinstance(result, threadedhttp.HttpRequest):
-            raise ValueError('The result is not a valid type '
-                             '"{0}"'.format(type(result)))
+        elif not isinstance(result, Response):
+            raise ValueError('The result is not a valid type "{}"'
+                             .format(type(result)))
         response = self.__wrapper.after_fetch(result, *args, **kwargs)
         if response is None:
             response = result
@@ -503,7 +505,7 @@

     The data returned for C{request} may either be C{False}, a C{str} or a
     C{Mapping} which is converted into a json string. The data returned for
-    C{fetch} can only be C{False} or a L{threadedhttp.HttpRequest}. For both
+    C{fetch} can only be C{False} or a L{requests.Response}. For both
     variants any other types are not allowed and if it is False it'll use the
     original method and do an actual request.


--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/658044
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: If048c853727590b0e8bf0412643649e4b355687a
Gerrit-Change-Number: 658044
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: JJMC89 <[email protected]>
Gerrit-Reviewer: Mpaa <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to