# Path: symantec_package/HTTPHandler.py
# class HTTPSClientCertTransport(HttpTransport):
#     def __init__(self, key, cert, *args, **kwargs):
#         HttpTransport.__init__(self, *args, **kwargs)
#         self.key = key
#         self.cert = cert
# 
#     def u2open(self, u2request):
#         """
#         Open a connection.
#         @param u2request: A urllib2 request.
#         @type u2request: urllib2.Requet.
#         @return: The opened file-like urllib2 object.
#         @rtype: fp
#         """
#         tm = self.options.timeout
#         url = urllib.request.build_opener(HTTPSClientAuthHandler(self.key, self.cert))
#         if self.u2ver() < 2.6:
#             socket.setdefaulttimeout(tm)
#             return url.open(u2request)
#         else:
#             return url.open(u2request, timeout=tm)


from suds.plugin import MessagePlugin
from suds.client import Client
from symantec_package.HTTPHandler import HTTPSClientCertTransport

class SymantecLegacyServices:
    """This class acts as a layer of abstraction to handling Symantec VIP SOAP calls in Python.

    You call this class to handle to managing users and credentials using authentication API.

    Example:
        >>> client = Client("http://../vip_auth.wsdl", transport = HTTPSClientCertTransport('vip_certificate.crt','vip_certificate.crt'))
        >>> service = SymantecLegacyServices(client)
        >>> response = service.sendOtpSMS(<parameters here>)
        >>> print (response)

    .. NOTE::
        Reference HTTPHandler for further information on how to setup the client.

    """

    def __init__(self):
        """The class takes in only a SOAP client object.

            Arg:
                client (suds.client Client): The client to handle the SOAP calls

            .. NOTE::
                Any parameters that are of "None" type are optional fields.

        """
        self.legacyservices_url = 'http://webdev.cse.msu.edu/~huynhall/vip_auth.wsdl'
        self.client = Client(self.legacyservices_url, location="https://services-auth.vip.symantec.com/mgmt/soap",
                             plugins=[MyPlugin()],

# Path: symantec_package/HTTPHandler.py
# class HTTPSClientCertTransport(HttpTransport):
#     def __init__(self, key, cert, *args, **kwargs):
#         HttpTransport.__init__(self, *args, **kwargs)
#         self.key = key
#         self.cert = cert
# 
#     def u2open(self, u2request):
#         """
#         Open a connection.
#         @param u2request: A urllib2 request.
#         @type u2request: urllib2.Requet.
#         @return: The opened file-like urllib2 object.
#         @rtype: fp
#         """
#         tm = self.options.timeout
#         url = urllib.request.build_opener(HTTPSClientAuthHandler(self.key, self.cert))
#         if self.u2ver() < 2.6:
#             socket.setdefaulttimeout(tm)
#             return url.open(u2request)
#         else:
#             return url.open(u2request, timeout=tm)


# Path: symantec_package/lib/legacyService/SymantecLegacyServices.py
from suds.plugin import MessagePlugin
from suds.client import Client
from symantec_package.HTTPHandler import HTTPSClientCertTransport


class SymantecLegacyServices:
    """This class acts as a layer of abstraction to handling Symantec VIP SOAP calls in Python.

    You call this class to handle to managing users and credentials using authentication API.

    Example:
        >>> client = Client("http://../vip_auth.wsdl", transport = HTTPSClientCertTransport('vip_certificate.crt','vip_certificate.crt'))
        >>> service = SymantecLegacyServices(client)
        >>> response = service.sendOtpSMS(<parameters here>)
        >>> print (response)

    .. NOTE::
        Reference HTTPHandler for further information on how to setup the client.

    """

    def __init__(self):
        """The class takes in only a SOAP client object.

            Arg:
                client (suds.client Client): The client to handle the SOAP calls

            .. NOTE::
                Any parameters that are of "None" type are optional fields.

        """
        self.legacyservices_url = 'http://webdev.cse.msu.edu/~huynhall/vip_auth.wsdl'
        self.client = Client(self.legacyservices_url, location="https://services-auth.vip.symantec.com/mgmt/soap",
                             plugins=[MyPlugin()],

                               transport=HTTPSClientCertTransport('vip_certificate.crt', 'vip_certificate.crt'))