예제 #1
0
 def _get_auth_header(self, oauth_params, realm=None):
     """Constructs and returns an authentication header."""
     auth_header = 'OAuth realm="{realm}"'.format(realm=realm or "")
     params = ""
     for k, v in oauth_params.items():
         params += ',{key}="{value}"'.format(key=k, value=quote(str(v)))
     auth_header += params
     return auth_header
예제 #2
0
    def _escape(self, s):
        '''
        Escapes a string, ensuring it is encoded as a UTF-8 octet.

        :param s: A string to be encoded.
        :type s: str
        '''
        return quote(self._ensure_unicode(s), safe='~').encode('utf-8')