コード例 #1
0
    def putrequest(self,
                   method,
                   url,
                   skip_host=False,
                   skip_accept_encoding=False):
        """Send a line to the server consisting of the request string, the selector
    string, and the HTTP version.

    Args:
      method: str HTTP request method.
      url: str selector URL.
      [optional]
      skip_host: bool if True, disable automatic sending of Host header.
      skip_accept_encoding: bool if True, disable automatic sending of
                            Accept-Encoding header.
    """
        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)
コード例 #2
0
    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 cm/.
            if 'cm' not in Utils.GetPathFromUrl(name_space).split('/'):
                parts = name_space.split('/')
                parts[-2] = 'cm'
                name_space = '/'.join(parts)
        else:
            name_space = ''
        for key, value in keys:
            if value:
                header.createAppendElement(name_space,
                                           key).createAppendTextNode(value)