def test_get_utf8_value(self):
     self.assertEqual(get_utf8_value('utf-8'), 'utf-8')
     self.assertEqual(get_utf8_value(u'unicode'), 'unicode')
     self.assertEqual(get_utf8_value([1, 2]), '[1, 2]')
     if sys.version < "3":
         self.assertEqual(get_utf8_value(u'你好'), '\xe4\xbd\xa0\xe5\xa5\xbd')
     else:
         self.assertEqual(get_utf8_value(u'你好'), u'你好')
 def _calc_signature(self, params, verb, path):
     """ calc signature for request
     """
     string_to_sign = '%s\n%s\n' % (verb, path)
     params['signature_method'] = self.algorithm()
     keys = sorted(params.keys())
     pairs = []
     for key in keys:
         val = get_utf8_value(params[key])
         if is_python3:
             key = key.encode()
         pairs.append(urllib.quote(key, safe='') + '=' +
                      urllib.quote(val, safe='-_~'))
     qs = '&'.join(pairs)
     string_to_sign += qs
     # print "string to sign:[%s]" % string_to_sign
     b64 = self.sign_string(string_to_sign)
     return (qs, b64)
Exemple #3
0
 def _calc_signature(self, params, verb, path):
     """ calc signature for request
     """
     string_to_sign = '%s\n%s\n' % (verb, path)
     params['signature_method'] = self.algorithm()
     keys = sorted(params.keys())
     pairs = []
     for key in keys:
         val = get_utf8_value(params[key])
         if is_python3:
             key = key.encode()
         pairs.append(
             urllib.quote(key, safe='') + '=' +
             urllib.quote(val, safe='-_~'))
     qs = '&'.join(pairs)
     string_to_sign += qs
     # print "string to sign:[%s]" % string_to_sign
     b64 = self.sign_string(string_to_sign)
     return (qs, b64)
 def test_get_utf8_value(self):
     self.assertEqual(get_utf8_value('utf-8'), 'utf-8')
     self.assertEqual(get_utf8_value(u'unicode'), 'unicode')
     self.assertEqual(get_utf8_value([1, 2]), '[1, 2]')
Exemple #5
0
 def test_get_utf8_value(self):
     self.assertEqual(get_utf8_value('utf-8'), 'utf-8')
     self.assertEqual(get_utf8_value(u'unicode'), 'unicode')
     self.assertEqual(get_utf8_value([1, 2]), '[1, 2]')
 def test_get_utf8_value(self):
     self.assertEqual(get_utf8_value('utf-8'), 'utf-8')
     self.assertEqual(get_utf8_value(u'unicode'), 'unicode')
     self.assertEqual(get_utf8_value([1, 2]), '[1, 2]')
     self.assertEqual(get_utf8_value(u'\u4f60\u597d'), '\xe4\xbd\xa0\xe5\xa5\xbd')
 def test_get_utf8_value(self):
     self.assertEqual(get_utf8_value('utf-8'), 'utf-8')
     self.assertEqual(get_utf8_value(u'unicode'), 'unicode')
     self.assertEqual(get_utf8_value([1, 2]), '[1, 2]')
     self.assertEqual(get_utf8_value(u'\u4f60\u597d'),
                      '\xe4\xbd\xa0\xe5\xa5\xbd')