Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bbad4f0

Browse files
committed
Merge pull request googleapis#43 from Parkayun/master
Modify UnicodeDecodeError
2 parents c1dba5f + 5bd38f3 commit bbad4f0

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

googleapiclient/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def _build_query(self, params):
167167
x = x.encode('utf-8')
168168
astuples.append((key, x))
169169
else:
170-
if getattr(value, 'encode', False) and callable(value.encode):
170+
if isinstance(value, unicode) and callable(value.encode):
171171
value = value.encode('utf-8')
172172
astuples.append((key, value))
173173
return '?' + urllib.urlencode(astuples)

tests/test_model.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/python2.4
2+
# -*- coding:utf-8 -*-
23
#
34
# Copyright 2014 Google Inc. All Rights Reserved.
45
#
@@ -21,9 +22,9 @@
2122

2223
__author__ = '[email protected] (Joe Gregorio)'
2324

24-
import httplib2
2525
import unittest
2626

27+
from googleapiclient.model import BaseModel
2728
from googleapiclient.model import makepatch
2829

2930

@@ -67,5 +68,27 @@ def test_patch(self):
6768
self.assertEqual(expected_patch, makepatch(orig, mod), msg=msg)
6869

6970

71+
class TestBaseModel(unittest.TestCase):
72+
def test_build_query(self):
73+
model = BaseModel()
74+
75+
test_cases = [
76+
('hello', 'world', '?hello=world'),
77+
('hello', u'world', '?hello=world'),
78+
('hello', '세계', '?hello=%EC%84%B8%EA%B3%84'),
79+
('hello', u'세계', '?hello=%EC%84%B8%EA%B3%84'),
80+
('hello', 'こんにちは', '?hello=%E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%81%AF'),
81+
('hello', u'こんにちは', '?hello=%E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%81%AF'),
82+
('hello', '你好', '?hello=%E4%BD%A0%E5%A5%BD'),
83+
('hello', u'你好', '?hello=%E4%BD%A0%E5%A5%BD'),
84+
('hello', 'مرحبا', '?hello=%D9%85%D8%B1%D8%AD%D8%A8%D8%A7'),
85+
('hello', u'مرحبا', '?hello=%D9%85%D8%B1%D8%AD%D8%A8%D8%A7')
86+
]
87+
88+
for case in test_cases:
89+
key, value, expect = case
90+
self.assertEqual(expect, model._build_query({key: value}))
91+
92+
7093
if __name__ == '__main__':
7194
unittest.main()

0 commit comments

Comments
 (0)