--- a/src/pyams_utils/protocol/xmlrpc.py Tue Sep 17 11:34:31 2019 +0200
+++ b/src/pyams_utils/protocol/xmlrpc.py Tue Sep 17 11:47:20 2019 +0200
@@ -10,10 +10,6 @@
# FOR A PARTICULAR PURPOSE.
#
-__docformat__ = 'restructuredtext'
-
-
-# import standard library
import base64
import http.client
import http.cookiejar
@@ -21,14 +17,13 @@
import urllib.request
import xmlrpc.client
+
try:
import gzip
except ImportError:
- gzip = None #python can be built without zlib/gzip support
+ gzip = None # python can be built without zlib/gzip support
-# import interfaces
-
-# import packages
+__docformat__ = 'restructuredtext'
class XMLRPCCookieAuthTransport(xmlrpc.client.Transport):
@@ -37,7 +32,8 @@
_http_connection = http.client.HTTPConnection
verbose = False
- def __init__(self, user_agent, credentials=(), cookies=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, headers=None):
+ def __init__(self, user_agent, credentials=(), cookies=None,
+ timeout=socket._GLOBAL_DEFAULT_TIMEOUT, headers=None):
xmlrpc.client.Transport.__init__(self)
self.user_agent = user_agent
self.credentials = credentials
@@ -111,6 +107,7 @@
class CookieResponseHelper:
def __init__(self, response):
self.response = response
+
def getheaders(self, header):
return self.response.msg.getallmatchingheaders(header)
@@ -118,6 +115,7 @@
class CookieResponse:
def __init__(self, response):
self.response = response
+
def info(self):
return XMLRPCCookieAuthTransport.CookieResponseHelper(self.response)
@@ -132,7 +130,8 @@
cookie.name = cookie.name.split(': ', 1)[1]
self.cookies.set_cookie(cookie)
if response.status != 200:
- raise xmlrpc.client.ProtocolError(host + handler, response.status, response.reason, response.getheaders())
+ raise xmlrpc.client.ProtocolError(host + handler, response.status, response.reason,
+ response.getheaders())
return self.parse_response(response)
@@ -142,26 +141,30 @@
_http_connection = http.client.HTTPSConnection
-def get_client(uri, credentials=(), verbose=False, allow_none=0, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, headers=None):
+def get_client(uri, credentials=(), verbose=False, allow_none=0,
+ timeout=socket._GLOBAL_DEFAULT_TIMEOUT, headers=None):
"""Get an XML-RPC client which supports basic authentication"""
if uri.startswith('https:'):
- transport = SecureXMLRPCCookieAuthTransport('Python XML-RPC Client/0.1 (PyAMS secure transport)', credentials,
- timeout=timeout, headers=headers)
+ transport = SecureXMLRPCCookieAuthTransport(
+ 'Python XML-RPC Client/0.1 (PyAMS secure transport)', credentials,
+ timeout=timeout, headers=headers)
else:
- transport = XMLRPCCookieAuthTransport('Python XML-RPC Client/0.1 (PyAMS basic transport)', credentials,
- timeout=timeout, headers=headers)
+ transport = XMLRPCCookieAuthTransport('Python XML-RPC Client/0.1 (PyAMS basic transport)',
+ credentials, timeout=timeout, headers=headers)
return xmlrpc.client.Server(uri, transport=transport, verbose=verbose, allow_none=allow_none)
-def get_client_with_cookies(uri, credentials=(), verbose=False, allow_none=0, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
- headers=None, cookies=None):
+def get_client_with_cookies(uri, credentials=(), verbose=False, allow_none=0,
+ timeout=socket._GLOBAL_DEFAULT_TIMEOUT, headers=None, cookies=None):
"""Get an XML-RPC client which supports authentication through cookies"""
if cookies is None:
cookies = http.cookiejar.CookieJar()
if uri.startswith('https:'):
- transport = SecureXMLRPCCookieAuthTransport('Python XML-RPC Client/0.1 (PyAMS secure cookie transport)',
- credentials, cookies, timeout, headers)
+ transport = SecureXMLRPCCookieAuthTransport(
+ 'Python XML-RPC Client/0.1 (PyAMS secure cookie transport)',
+ credentials, cookies, timeout, headers)
else:
- transport = XMLRPCCookieAuthTransport('Python XML-RPC Client/0.1 (PyAMS basic cookie transport)',
- credentials, cookies, timeout, headers)
+ transport = XMLRPCCookieAuthTransport(
+ 'Python XML-RPC Client/0.1 (PyAMS basic cookie transport)',
+ credentials, cookies, timeout, headers)
return xmlrpc.client.Server(uri, transport=transport, verbose=verbose, allow_none=allow_none)