@@ -148,6 +148,23 @@ def test_nested(self):
148
148
num += 1
149
149
self .assertEqual (num , 3 )
150
150
151
+ def test_unicode_headers (self ):
152
+ # http://code.google.com/p/couchdb-python/issues/detail?id=179
153
+ dump = '''Content-Type: multipart/mixed; boundary="==123456789=="
154
+
155
+ --==123456789==
156
+ Content-ID: =?utf-8?b?5paH5qGj?=
157
+ Content-Length: 63
158
+ Content-MD5: Cpw3iC3xPua8YzKeWLzwvw==
159
+ Content-Type: application/json
160
+
161
+ {"_rev": "3-bc27b6930ca514527d8954c7c43e6a09", "_id": "文档"}
162
+ '''
163
+ parts = multipart .read_multipart (StringIO (dump ))
164
+ for headers , is_multipart , payload in parts :
165
+ self .assertEqual (headers ['content-id' ], u'文档' )
166
+ break
167
+
151
168
152
169
class WriteMultipartTestCase (unittest .TestCase ):
153
170
@@ -173,6 +190,25 @@ def test_unicode_content_ascii(self):
173
190
self .assertRaises (UnicodeEncodeError , envelope .add ,
174
191
'text/plain;charset=ascii' , u'Iñtërnâtiônàlizætiøn' )
175
192
193
+ def test_unicode_headers (self ):
194
+ # http://code.google.com/p/couchdb-python/issues/detail?id=179
195
+ buf = StringIO ()
196
+ envelope = multipart .write_multipart (buf , boundary = '==123456789==' )
197
+ envelope .add ('application/json' ,
198
+ '{"_rev": "3-bc27b6930ca514527d8954c7c43e6a09",'
199
+ ' "_id": "文档"}' ,
200
+ headers = {'Content-ID' : u"文档" })
201
+ self .assertEqual ('''Content-Type: multipart/mixed; boundary="==123456789=="
202
+
203
+ --==123456789==
204
+ Content-ID: =?utf-8?b?5paH5qGj?=
205
+ Content-Length: 63
206
+ Content-MD5: Cpw3iC3xPua8YzKeWLzwvw==
207
+ Content-Type: application/json
208
+
209
+ {"_rev": "3-bc27b6930ca514527d8954c7c43e6a09", "_id": "文档"}
210
+ ''' , buf .getvalue ().replace ('\r \n ' , '\n ' ))
211
+
176
212
177
213
def suite ():
178
214
suite = unittest .TestSuite ()
0 commit comments