Commits

Mikhail Korobov committed 419e816

restore unicode support for signature function

Comments (0)

Files changed (1)

     def __str__(self):
         return "Error(code = '%s', description = '%s', params = '%s')" % (self.code, self.description, self.params)
 
+def _to_request_encoding(s):
+    if isinstance(s, unicode):
+        return s.encode(REQUEST_ENCODING)
+    return s # this can be number, etc.
+
+
 def signature(api_secret, params):
     keys = sorted(params.keys())
-    param_str = "".join(["%s=%s" % (str(key), params[key]) for key in keys])
+    param_str = "".join(["%s=%s" % (str(key), _to_request_encoding(params[key])) for key in keys])
     return md5(param_str + str(api_secret)).hexdigest()
 
 # We have to support this:
         return signature(self.api_secret, params)
 
     def _request(self, method, timeout=DEFAULT_TIMEOUT, **kwargs):
-            
+
         for key, value in kwargs.iteritems():
-            if isinstance(value, unicode):
-                kwargs[key] = value.encode(REQUEST_ENCODING)
+            kwargs[key] = _to_request_encoding(value)
 
         if self.token:
             # http://vkontakte.ru/developers.php?oid=-1&p=Выполнение_запросов_к_API