Merge pull request #43 from Parkayun/master

Modify UnicodeDecodeError
diff --git a/googleapiclient/model.py b/googleapiclient/model.py
index 0f0172c..df3efbb 100644
--- a/googleapiclient/model.py
+++ b/googleapiclient/model.py
@@ -167,7 +167,7 @@
           x = x.encode('utf-8')
           astuples.append((key, x))
       else:
-        if getattr(value, 'encode', False) and callable(value.encode):
+        if isinstance(value, unicode) and callable(value.encode):
           value = value.encode('utf-8')
         astuples.append((key, value))
     return '?' + urllib.urlencode(astuples)
diff --git a/tests/test_model.py b/tests/test_model.py
index d24c367..6bc87be 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -1,4 +1,5 @@
 #!/usr/bin/python2.4
+# -*- coding:utf-8 -*-
 #
 # Copyright 2014 Google Inc. All Rights Reserved.
 #
@@ -21,9 +22,9 @@
 
 __author__ = 'jcgregorio@google.com (Joe Gregorio)'
 
-import httplib2
 import unittest
 
+from googleapiclient.model import BaseModel
 from googleapiclient.model import makepatch
 
 
@@ -67,5 +68,27 @@
       self.assertEqual(expected_patch, makepatch(orig, mod), msg=msg)
 
 
+class TestBaseModel(unittest.TestCase):
+    def test_build_query(self):
+        model = BaseModel()
+
+        test_cases = [
+            ('hello', 'world', '?hello=world'),
+            ('hello', u'world', '?hello=world'),
+            ('hello', '세계', '?hello=%EC%84%B8%EA%B3%84'),
+            ('hello', u'세계', '?hello=%EC%84%B8%EA%B3%84'),
+            ('hello', 'こんにちは', '?hello=%E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%81%AF'),
+            ('hello', u'こんにちは', '?hello=%E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%81%AF'),
+            ('hello', '你好', '?hello=%E4%BD%A0%E5%A5%BD'),
+            ('hello', u'你好', '?hello=%E4%BD%A0%E5%A5%BD'),
+            ('hello', 'مرحبا', '?hello=%D9%85%D8%B1%D8%AD%D8%A8%D8%A7'),
+            ('hello', u'مرحبا', '?hello=%D9%85%D8%B1%D8%AD%D8%A8%D8%A7')
+        ]
+
+        for case in test_cases:
+            key, value, expect = case
+            self.assertEqual(expect, model._build_query({key: value}))
+
+
 if __name__ == '__main__':
   unittest.main()