

def sign(self, uri, http_method='GET', body=None, headers=None, realm=None):
    "Sign a request\n\n        Signs an HTTP request with the specified parts.\n\n        Returns a 3-tuple of the signed request's URI, headers, and body.\n        Note that http_method is not returned as it is unaffected by the OAuth\n        signing process. Also worth noting is that duplicate parameters\n        will be included in the signature, regardless of where they are\n        specified (query, body).\n\n        The body argument may be a dict, a list of 2-tuples, or a formencoded\n        string. The Content-Type header must be 'application/x-www-form-urlencoded'\n        if it is present.\n\n        If the body argument is not one of the above, it will be returned\n        verbatim as it is unaffected by the OAuth signing process. Attempting to\n        sign a request with non-formencoded data using the OAuth body signature\n        type is invalid and will raise an exception.\n\n        If the body does contain parameters, it will be returned as a properly-\n        formatted formencoded string.\n\n        Body may not be included if the http_method is either GET or HEAD as\n        this changes the semantic meaning of the request.\n\n        All string data MUST be unicode or be encoded with the same encoding\n        scheme supplied to the Client constructor, default utf-8. This includes\n        strings inside body dicts, for example.\n        "
    request = Request(uri, http_method, body, headers, encoding=self.encoding)
    content_type = request.headers.get('Content-Type', None)
    multipart = (content_type and content_type.startswith('multipart/'))
    should_have_params = (content_type == CONTENT_TYPE_FORM_URLENCODED)
    has_params = (request.decoded_body is not None)
    if (multipart and has_params):
        raise ValueError('Headers indicate a multipart body but body contains parameters.')
    elif (should_have_params and (not has_params)):
        raise ValueError('Headers indicate a formencoded body but body was not decodable.')
    elif ((not should_have_params) and has_params):
        raise ValueError('Body contains parameters but Content-Type header was {0} instead of {1}'.format((content_type or 'not set'), CONTENT_TYPE_FORM_URLENCODED))
    elif ((self.signature_type == SIGNATURE_TYPE_BODY) and (not (should_have_params and has_params and (not multipart)))):
        raise ValueError('Body signatures may only be used with form-urlencoded content')
    elif ((http_method.upper() in ('GET', 'HEAD')) and has_params):
        raise ValueError('GET/HEAD requests should not include body.')
    request.oauth_params = self.get_oauth_params(request)
    request.oauth_params.append(('oauth_signature', self.get_oauth_signature(request)))
    (uri, headers, body) = self._render(request, formencode=True, realm=(realm or self.realm))
    if self.decoding:
        log.debug('Encoding URI, headers and body to %s.', self.decoding)
        uri = uri.encode(self.decoding)
        body = (body.encode(self.decoding) if body else body)
        new_headers = {
            
        }
        for (k, v) in headers.items():
            new_headers[k.encode(self.decoding)] = v.encode(self.decoding)
        headers = new_headers
    return (uri, headers, body)

dataset/ETHPy150Open idan/oauthlib/oauthlib/oauth1/rfc5849/__init__.py Client.sign/original