Пример #1
0
 def make_connection(self, host):
     _host, _port = m2urllib.splitport(host)
     if sys.version[0] == '2':
         return httpslib.HTTPS(_host, int(_port), ssl_context=self.ssl_ctx)
     elif sys.version[:3] == '1.5':
         return httpslib.HTTPS(self.ssl_ctx, _host, int(_port))
     else:
         raise RuntimeError, 'unsupported Python version'
Пример #2
0
	def make_connection(self, host):
		_host, _port = m2urllib.splitport(host)
		if sys.version[0] == '2':
			return httpslib.HTTPS(_host, int(_port), ssl_context=self.ssl_ctx)
		elif sys.version[:3] == '1.5':
			return httpslib.HTTPS(self.ssl_ctx, _host, int(_port))
		else:
			raise RuntimeError, 'unsupported Python version'
Пример #3
0
    def request(self, host, handler, request_body, verbose=0):
        # Handle username and password.
        user_passwd, host_port = m2urllib.splituser(host)
        _host, _port = m2urllib.splitport(host_port)
        h = httpslib.HTTPS(_host, int(_port), ssl_context=self.ssl_ctx)

        if verbose:
            h.set_debuglevel(1)

        # Check cert ::Addition by RogerB
        self.check_cert(h)

        # What follows is as in xmlrpclib.Transport. (Except the authz bit.)
        h.putrequest("POST", handler)

        # required by HTTP/1.1
        h.putheader("Host", _host)

        # required by XML-RPC
        h.putheader("User-Agent", self.user_agent)
        h.putheader('Keep-Alive', '1')
        h.putheader("Content-Type", "text/xml")
        h.putheader("Content-Length", str(len(request_body)))

        # Authorisation.
        if user_passwd is not None:
            auth=string.strip(base64.encodestring(user_passwd))
            h.putheader('Authorization', 'Basic %s' % auth)

        h.endheaders()

        if request_body:
            h.send(request_body)

        errcode, errmsg, headers = h.getreply()

        if errcode != 200:
            print errcode, errmsg, headers
            raise xmlrpclib.ProtocolError(
                host + handler,
                errcode, errmsg,
                headers
                )

        self.verbose = verbose
        return self.parse_response(h.getfile())
Пример #4
0
    def request(self, host, handler, request_body, verbose=0):
        # Handle username and password.
        user_passwd, host_port = m2urllib.splituser(host)
        _host, _port = m2urllib.splitport(host_port)
        h = httpslib.HTTPS(_host, int(_port), ssl_context=self.ssl_ctx)

        if verbose:
            h.set_debuglevel(1)

        # Check cert ::Addition by RogerB
        self.check_cert(h)

        # What follows is as in xmlrpclib.Transport. (Except the authz bit.)
        h.putrequest("POST", handler)

        # required by HTTP/1.1
        h.putheader("Host", _host)

        # required by XML-RPC
        h.putheader("User-Agent", self.user_agent)
        h.putheader('Keep-Alive', '1')
        h.putheader("Content-Type", "text/xml")
        h.putheader("Content-Length", str(len(request_body)))

        # Authorisation.
        if user_passwd is not None:
            auth = string.strip(base64.encodestring(user_passwd))
            h.putheader('Authorization', 'Basic %s' % auth)

        h.endheaders()

        if request_body:
            h.send(request_body)

        errcode, errmsg, headers = h.getreply()

        if errcode != 200:
            print errcode, errmsg, headers
            raise xmlrpclib.ProtocolError(host + handler, errcode, errmsg,
                                          headers)

        self.verbose = verbose
        return self.parse_response(h.getfile())
Пример #5
0
    def request(self, host, handler, request_body, verbose=0):
        # type: (AnyStr, Callable, bytes, int) -> object
        # Handle username and password.
        user_passwd, host_port = m2urllib.splituser(host)
        _host, _port = m2urllib.splitport(host_port)
        h = httpslib.HTTPSConnection(_host,
                                     int(_port),
                                     ssl_context=self.ssl_ctx)
        if verbose:
            h.set_debuglevel(1)

        # What follows is as in xmlrpclib.Transport. (Except the authz bit.)
        h.putrequest("POST", handler)

        # required by HTTP/1.1
        h.putheader("Host", _host)

        # required by XML-RPC
        h.putheader("User-Agent", self.user_agent)
        h.putheader("Content-Type", "text/xml")
        h.putheader("Content-Length", str(len(request_body)))

        # Authorisation.
        if user_passwd is not None:
            auth = base64.encodestring(user_passwd).strip()
            h.putheader('Authorization', 'Basic %s' % auth)

        h.endheaders()

        if request_body:
            h.send(request_body)

        response = h.getresponse()

        if response.status != 200:
            raise ProtocolError(host + handler, response.status,
                                response.reason, response.getheaders())

        self.verbose = verbose
        return self.parse_response(response)
Пример #6
0
 def make_connection(self, host, port=None):
     if port is None:
         host, port = m2urllib.splitport(host)
     return httpslib.HTTPS(host, int(port), ssl_context=self.ssl_ctx)
Пример #7
0
 def make_connection(self, host):
     _host, _port = m2urllib.splitport(host)
     return httpslib.HTTPS(_host, int(_port), ssl_context=self.ssl_ctx)