Skip to content

Commit

Permalink
Merge branch 'feature/multipart_reader' of github.com:SunRunAway/pyth…
Browse files Browse the repository at this point in the history
…on-sdk into feature/multipart_reader
  • Loading branch information
SunRunAway committed Jul 5, 2013
2 parents fa0b457 + a73b91c commit 94e9162
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
9 changes: 8 additions & 1 deletion qiniu/rpc.py
Expand Up @@ -110,7 +110,8 @@ def encode_multipart_formdata(self, fields, files):
L.append('')
L.append('--' + BOUNDARY)
disposition = "Content-Disposition: form-data;"
L.append('%s name="file"; filename="%s"' % (disposition, file_info.get('filename')))
filename = _qiniu_escape(file_info.get('filename'))
L.append('%s name="file"; filename="%s"' % (disposition, filename))
L.append('Content-Type: %s' % file_info.get('content_type', 'application/octet-stream'))
L.append('')
L.append('')
Expand All @@ -127,6 +128,12 @@ def encode_multipart_formdata(self, fields, files):
content_type = 'multipart/form-data; boundary=%s' % BOUNDARY
return content_type, MultiReader(readers)

def _qiniu_escape(s):
edits = [('\\', '\\\\'), ('\"', '\\\"')]
for (search, replace) in edits:
s = s.replace(search, replace)
return s


class MultiReader(object):
""" class MultiReader([readers...])
Expand Down
15 changes: 15 additions & 0 deletions qiniu/test/io_test.py
Expand Up @@ -54,6 +54,20 @@ def test_put_no_key():
assert err is None
assert ret['hash'] == ret['key']

def test_put_quote_key():
data = r(100)
key = 'a\\b\\c"你好' + r(9)
ret, err = io.put(policy.token(), key, data)
print err
assert err is None
assert ret['key'].encode('utf8') == key

data = r(100)
key = u'a\\b\\c"你好' + r(9)
ret, err = io.put(policy.token(), key, data)
assert err is None
assert ret['key'] == key

def test_put_unicode1():
key = "test_%s" % r(9) + '你好'
data = key
Expand Down Expand Up @@ -125,6 +139,7 @@ def read(self, n=None):
test_put()
test_put_same_crc()
test_put_no_key()
test_put_quote_key()
test_put_unicode1()
test_put_unicode2()
test_put_unicode3()
Expand Down

0 comments on commit 94e9162

Please sign in to comment.