def putrequest(self, method, url, skip_host=False, skip_accept_encoding=False): """Send a request to the server. Args: method: str Specifies an HTTP request method. url: str Specifies the object being requested. [optional] skip_host: bool If True does not add automatically a 'Host:' header. skip_accept_encoding: bool If True does not add automatically an 'Accept-Encoding:' header. """ if HttpConnectionHandler.compress: skip_accept_encoding = True if self.__http_proxy != self.__host: scheme = Utils.GetSchemeFromUrl(url) or 'http' netloc = Utils.GetNetLocFromUrl(url) or self.__host path = Utils.GetPathFromUrl(url) uri = '%s://%s%s' % (scheme, netloc, path) else: uri = url httplib.HTTPConnection.putrequest( self, method=method, url=uri, skip_host=skip_host, skip_accept_encoding=skip_accept_encoding)
def sign(self, soap_writer): """Sign signature handler. Args: soap_writer: SoapWriter instance. """ keys = [] for key in self.__headers: keys.append((key, self.__headers[key])) keys = tuple(keys) header = soap_writer._header body = soap_writer.body # Set RequestHeader element, if appropriate. if 'ns_target' in self.__config: name_space, target = self.__config['ns_target'] header = header.createAppendElement('', target) header.setNamespaceAttribute('', name_space) # Explicitly set namespace at the request method's level. For services # with multiple namespaces, this has to be done prior to checking where # RequestHeader elements point. if body._getElements(): body._getElements()[0].setAttributeNS('', 'xmlns:ns1', name_space) # Make sure that the namespace for RequestHeader elements is pointing # at default namespace, if present. if (self.__group and self.__group not in Utils.GetPathFromUrl(name_space).split('/')): parts = name_space.split('/') parts[-2] = self.__group name_space = '/'.join(parts) else: name_space = '' for key, value in keys: if value: if isinstance(value, dict): if 'auth_type' not in self.__config: self.__config['auth_type'] = '' obj = header.createAppendElement(name_space, key) obj.node.setAttribute('xsi:type', self.__config['auth_type']) for sub_key in value: obj.createAppendElement(name_space, sub_key).createAppendTextNode( value[sub_key]) else: header.createAppendElement(name_space, key).createAppendTextNode(value)