2019-09-27 19:11:19 +02:00
|
|
|
"""xmlrpclib.Transport implementation
|
|
|
|
"""
|
2019-09-29 23:37:46 +02:00
|
|
|
|
2019-09-27 16:54:11 +02:00
|
|
|
import logging
|
2020-12-27 15:01:06 +01:00
|
|
|
import urllib.parse
|
2020-12-28 04:34:32 +01:00
|
|
|
import xmlrpc.client
|
|
|
|
from typing import TYPE_CHECKING, Tuple
|
2019-09-27 16:54:11 +02:00
|
|
|
|
2020-05-03 18:48:24 +02:00
|
|
|
from pip._internal.exceptions import NetworkConnectionError
|
2021-02-19 13:56:59 +01:00
|
|
|
from pip._internal.network.session import PipSession
|
2020-05-03 18:48:24 +02:00
|
|
|
from pip._internal.network.utils import raise_for_status
|
2020-05-17 23:41:44 +02:00
|
|
|
|
2020-12-28 04:34:32 +01:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from xmlrpc.client import _HostType, _Marshallable
|
|
|
|
|
2019-09-27 16:54:11 +02:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2020-12-28 04:34:32 +01:00
|
|
|
class PipXmlrpcTransport(xmlrpc.client.Transport):
|
2019-09-27 16:54:11 +02:00
|
|
|
"""Provide a `xmlrpclib.Transport` implementation via a `PipSession`
|
|
|
|
object.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, index_url, session, use_datetime=False):
|
2020-05-20 09:10:05 +02:00
|
|
|
# type: (str, PipSession, bool) -> None
|
2020-12-25 00:00:05 +01:00
|
|
|
super().__init__(use_datetime)
|
2020-12-27 15:01:06 +01:00
|
|
|
index_parts = urllib.parse.urlparse(index_url)
|
2019-09-27 16:54:11 +02:00
|
|
|
self._scheme = index_parts.scheme
|
|
|
|
self._session = session
|
|
|
|
|
|
|
|
def request(self, host, handler, request_body, verbose=False):
|
2020-12-28 04:34:32 +01:00
|
|
|
# type: (_HostType, str, bytes, bool) -> Tuple[_Marshallable, ...]
|
|
|
|
assert isinstance(host, str)
|
2019-09-27 16:54:11 +02:00
|
|
|
parts = (self._scheme, host, handler, None, None, None)
|
2020-12-27 15:01:06 +01:00
|
|
|
url = urllib.parse.urlunparse(parts)
|
2019-09-27 16:54:11 +02:00
|
|
|
try:
|
|
|
|
headers = {'Content-Type': 'text/xml'}
|
|
|
|
response = self._session.post(url, data=request_body,
|
|
|
|
headers=headers, stream=True)
|
2020-05-03 18:48:24 +02:00
|
|
|
raise_for_status(response)
|
2019-09-27 16:54:11 +02:00
|
|
|
self.verbose = verbose
|
|
|
|
return self.parse_response(response.raw)
|
2020-05-03 18:48:24 +02:00
|
|
|
except NetworkConnectionError as exc:
|
2020-07-09 09:14:21 +02:00
|
|
|
assert exc.response
|
2019-09-27 16:54:11 +02:00
|
|
|
logger.critical(
|
|
|
|
"HTTP error %s while getting %s",
|
|
|
|
exc.response.status_code, url,
|
|
|
|
)
|
|
|
|
raise
|