src/pyams_utils/protocol/xmlrpc.py
branchdev-tf
changeset 419 05ff71a02b2d
parent 393 225e6576d28d
--- a/src/pyams_utils/protocol/xmlrpc.py	Sat Nov 23 01:17:56 2019 +0100
+++ b/src/pyams_utils/protocol/xmlrpc.py	Sat Nov 23 14:51:46 2019 +0100
@@ -10,6 +10,13 @@
 # FOR A PARTICULAR PURPOSE.
 #
 
+"""PyAMS_utils.protocol.xmlrpc module
+
+This module provides a few set of classes and functions usable to improve XML-RPC client usage.
+
+It provides custom transports and allows storage of response cookies
+"""
+
 import base64
 import http.client
 import http.cookiejar
@@ -17,7 +24,6 @@
 import urllib.request
 import xmlrpc.client
 
-
 try:
     import gzip
 except ImportError:
@@ -27,6 +33,7 @@
 
 
 class XMLRPCCookieAuthTransport(xmlrpc.client.Transport):
+    # pylint: disable=too-many-instance-attributes
     """An XML-RPC transport handling authentication via cookies"""
 
     _http_connection = http.client.HTTPConnection
@@ -34,6 +41,7 @@
 
     def __init__(self, user_agent, credentials=(), cookies=None,
                  timeout=socket._GLOBAL_DEFAULT_TIMEOUT, headers=None):
+        # pylint: disable=protected-access,too-many-arguments
         xmlrpc.client.Transport.__init__(self)
         self.user_agent = user_agent
         self.credentials = credentials
@@ -75,8 +83,8 @@
         self.send_content(connection, request_body)
         return connection
 
-    # override the send_host hook to also send authentication info
     def send_auth(self, connection):
+        """Override the send_host hook to also send authentication info"""
         if (self.cookies is not None) and (len(self.cookies) > 0):
             for cookie in self.cookies:
                 connection.putheader('Cookie', '%s=%s' % (cookie.name, cookie.value))
@@ -85,41 +93,46 @@
             auth = 'Basic %s' % creds
             connection.putheader('Authorization', auth)
 
-    # send content type
-    def send_content_type(self, connection):
+    @staticmethod
+    def send_content_type(connection):
+        """Send content type"""
         connection.putheader('Content-Type', 'text/xml')
 
-    # send user agent
     def send_user_agent(self, connection):
+        """Send user agent"""
         connection.putheader('User-Agent', self.user_agent)
 
-    # send custom headers
     def send_headers(self, connection, headers):
+        """Send custom headers"""
         xmlrpc.client.Transport.send_headers(self, connection, headers)
-        for k, v in (self.headers or {}).items():
-            connection.putheader(k, v)
+        for key, value in (self.headers or {}).items():
+            connection.putheader(key, value)
 
-    # dummy request class for extracting cookies
     class CookieRequest(urllib.request.Request):
-        pass
+        """Dummy request class used for extracting cookies"""
 
-    # dummy response info headers helper
     class CookieResponseHelper:
+        """Dummy response headers helper"""
+
         def __init__(self, response):
             self.response = response
 
         def getheaders(self, header):
+            """Get response headers"""
             return self.response.msg.getallmatchingheaders(header)
 
-    # dummy response class for extracting cookies
     class CookieResponse:
+        """Dummy response class used to extract cookies"""
+
         def __init__(self, response):
             self.response = response
 
         def info(self):
+            """Get response info from cookies"""
             return XMLRPCCookieAuthTransport.CookieResponseHelper(self.response)
 
     def get_response(self, connection, host, handler):
+        """Get server response"""
         response = connection.getresponse()
         # extract cookies from response headers
         if self.cookies is not None:
@@ -143,6 +156,7 @@
 
 def get_client(uri, credentials=(), verbose=False, allow_none=0,
                timeout=socket._GLOBAL_DEFAULT_TIMEOUT, headers=None):
+    # pylint: disable=protected-access,too-many-arguments
     """Get an XML-RPC client which supports basic authentication"""
     if uri.startswith('https:'):
         transport = SecureXMLRPCCookieAuthTransport(
@@ -156,6 +170,7 @@
 
 def get_client_with_cookies(uri, credentials=(), verbose=False, allow_none=0,
                             timeout=socket._GLOBAL_DEFAULT_TIMEOUT, headers=None, cookies=None):
+    # pylint: disable=protected-access,too-many-arguments
     """Get an XML-RPC client which supports authentication through cookies"""
     if cookies is None:
         cookies = http.cookiejar.CookieJar()