comparison lib/python3.8/site-packages/pip/_internal/network/xmlrpc.py @ 0:9e54283cc701 draft

"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
author guerler
date Mon, 27 Jul 2020 03:47:31 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:9e54283cc701
1 """xmlrpclib.Transport implementation
2 """
3
4 # The following comment should be removed at some point in the future.
5 # mypy: disallow-untyped-defs=False
6
7 import logging
8
9 from pip._vendor import requests
10 # NOTE: XMLRPC Client is not annotated in typeshed as on 2017-07-17, which is
11 # why we ignore the type on this import
12 from pip._vendor.six.moves import xmlrpc_client # type: ignore
13 from pip._vendor.six.moves.urllib import parse as urllib_parse
14
15 logger = logging.getLogger(__name__)
16
17
18 class PipXmlrpcTransport(xmlrpc_client.Transport):
19 """Provide a `xmlrpclib.Transport` implementation via a `PipSession`
20 object.
21 """
22
23 def __init__(self, index_url, session, use_datetime=False):
24 xmlrpc_client.Transport.__init__(self, use_datetime)
25 index_parts = urllib_parse.urlparse(index_url)
26 self._scheme = index_parts.scheme
27 self._session = session
28
29 def request(self, host, handler, request_body, verbose=False):
30 parts = (self._scheme, host, handler, None, None, None)
31 url = urllib_parse.urlunparse(parts)
32 try:
33 headers = {'Content-Type': 'text/xml'}
34 response = self._session.post(url, data=request_body,
35 headers=headers, stream=True)
36 response.raise_for_status()
37 self.verbose = verbose
38 return self.parse_response(response.raw)
39 except requests.HTTPError as exc:
40 logger.critical(
41 "HTTP error %s while getting %s",
42 exc.response.status_code, url,
43 )
44 raise