Skip to content

Commit e7f9310

Browse files
committed
Merge branch 'feature/multipart_reader' into feature/add_docs
2 parents f664e3a + b246a33 commit e7f9310

File tree

15 files changed

+62
-29
lines changed

15 files changed

+62
-29
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
*.py[cod]
66

7+
my-test-env.sh
78

89
##
910
## from https://github.com/github/gitignore/blob/master/Python.gitignore

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ python:
33
- "2.6"
44
- "2.7"
55
before_script:
6-
- source env.sh
6+
- export QINIU_ACCESS_KEY="X0XpjFmLMTJpHB_ESHjeolCtipk-1U3Ok7LVTdoN"
7+
- export QINIU_SECRET_KEY="wenlwkU1AYwNBf7Q9cCoG4VT_GYyrHE9AS_R2u81"
8+
- export QINIU_TEST_BUCKET="pysdk"
9+
- export QINIU_TEST_DOMAIN="pysdk.qiniudn.com"
710
- export PYTHONPATH="$PYTHONPATH:."
811
script:
912
- python setup.py nosetests

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
## CHANGE LOG
22

3-
### v6.0.2
3+
### v6.1.0
44

55
2013-07-03 issue [#53](https://github.com/qiniu/python-sdk/pull/53)
66

77
- 实现最新版的上传API,<http://docs.qiniu.com/api/put.html>
8+
- io.PutExtra更新,废弃callback_params,bucket,和custom_meta,新增params
89
- 修复[#16](https://github.com/qiniu/python-sdk/issues/16)
910
- put接口可以传入类文件对象(file-like object)
1011
- 修复[#52](https://github.com/qiniu/python-sdk/issues/52)

docs/demo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ def _setup():
5151
if access_key is None:
5252
exit("请配置环境变量 QINIU_ACCESS_KEY")
5353
secret_key = getenv("QINIU_SECRET_KEY")
54-
bucket_name = getenv("QINIU_BUCKET_NAME")
55-
domain = getenv("QINIU_DOMAIN")
56-
pickey = getenv("QINIU_PIC_KEY")
54+
bucket_name = getenv("QINIU_TEST_BUCKET")
55+
domain = getenv("QINIU_TEST_DOMAIN")
56+
pickey = 'QINIU_UNIT_TEST_PIC'
5757
setup(access_key, secret_key, bucket_name, domain, pickey)
5858

5959
def getenv(name):

env.sh

Lines changed: 0 additions & 6 deletions
This file was deleted.

qiniu/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
'''
88

99
# -*- coding: utf-8 -*-
10-
__version__ = '6.0.1'
10+
__version__ = '6.1.0'

qiniu/io.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ def put(uptoken, key, data, extra=None):
3232
extra = PutExtra()
3333

3434
if extra.params:
35-
for key in extra.params:
36-
fields[key] = str(extra.params[key])
35+
for k in extra.params:
36+
fields[k] = str(extra.params[k])
3737

3838
if extra.check_crc:
3939
fields["crc32"] = str(extra.crc32)

qiniu/rpc.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ def encode_multipart_formdata(self, fields, files):
110110
L.append('')
111111
L.append('--' + BOUNDARY)
112112
disposition = "Content-Disposition: form-data;"
113-
L.append('%s name="file"; filename="%s"' % (disposition, file_info.get('filename')))
113+
filename = _qiniu_escape(file_info.get('filename'))
114+
L.append('%s name="file"; filename="%s"' % (disposition, filename))
114115
L.append('Content-Type: %s' % file_info.get('content_type', 'application/octet-stream'))
115116
L.append('')
116117
L.append('')
@@ -127,6 +128,12 @@ def encode_multipart_formdata(self, fields, files):
127128
content_type = 'multipart/form-data; boundary=%s' % BOUNDARY
128129
return content_type, MultiReader(readers)
129130

131+
def _qiniu_escape(s):
132+
edits = [('\\', '\\\\'), ('\"', '\\\"')]
133+
for (search, replace) in edits:
134+
s = s.replace(search, replace)
135+
return s
136+
130137

131138
class MultiReader(object):
132139
""" class MultiReader([readers...])

qiniu/rs/test/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
import qiniu.conf
88

99
pic = "http://cheneya.qiniudn.com/hello_jpg"
10+
key = 'QINIU_UNIT_TEST_PIC'
1011

1112
def setUp():
1213
qiniu.conf.ACCESS_KEY = os.getenv("QINIU_ACCESS_KEY")
1314
qiniu.conf.SECRET_KEY = os.getenv("QINIU_SECRET_KEY")
14-
key = os.getenv("QINIU_PIC_KEY")
15-
bucket_name = os.getenv("QINIU_BUCKET_NAME")
15+
bucket_name = os.getenv("QINIU_TEST_BUCKET")
1616

1717
policy = qiniu.rs.PutPolicy(bucket_name)
1818
uptoken = policy.token()

qiniu/rs/test/rs_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ def r(length):
1313

1414
conf.ACCESS_KEY = os.getenv("QINIU_ACCESS_KEY")
1515
conf.SECRET_KEY = os.getenv("QINIU_SECRET_KEY")
16-
key = os.getenv("QINIU_PIC_KEY")
17-
bucket_name = os.getenv("QINIU_BUCKET_NAME")
18-
noexist_key = os.getenv("QINIU_NOEXIST_PIC_KEY")
16+
key = 'QINIU_UNIT_TEST_PIC'
17+
bucket_name = os.getenv("QINIU_TEST_BUCKET")
18+
noexist_key = 'QINIU_UNIT_TEST_NOEXIST' + r(30)
1919
key2 = "rs_demo_test_key_1_" + r(5)
2020
key3 = "rs_demo_test_key_2_" + r(5)
2121
key4 = "rs_demo_test_key_3_" + r(5)

qiniu/rs/test/rs_token_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
conf.ACCESS_KEY = os.getenv("QINIU_ACCESS_KEY")
1616
conf.SECRET_KEY = os.getenv("QINIU_SECRET_KEY")
17-
bucket_name = os.getenv("QINIU_BUCKET_NAME")
18-
domain = os.getenv("QINIU_DOMAIN")
19-
key = os.getenv("QINIU_PIC_KEY")
17+
bucket_name = os.getenv("QINIU_TEST_BUCKET")
18+
domain = os.getenv("QINIU_TEST_DOMAIN")
19+
key = 'QINIU_UNIT_TEST_PIC'
2020

2121
class TestToken(unittest.TestCase):
2222
def test_put_policy(self):

qiniu/test/io_test.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616

1717
conf.ACCESS_KEY = os.getenv("QINIU_ACCESS_KEY")
1818
conf.SECRET_KEY = os.getenv("QINIU_SECRET_KEY")
19-
bucket_name = os.getenv("QINIU_BUCKET_NAME")
19+
bucket_name = os.getenv("QINIU_TEST_BUCKET")
2020

2121
policy = rs.PutPolicy(bucket_name)
2222
extra = io.PutExtra()
2323
extra.mime_type = "text/plain"
24+
extra.params = {'x:a':'a'}
2425

2526
def r(length):
2627
lib = string.ascii_uppercase
@@ -36,23 +37,41 @@ def test_put():
3637
extra.crc32 = binascii.crc32(data) & 0xFFFFFFFF
3738
ret, err = io.put(policy.token(), key, data, extra)
3839
assert err is None
40+
assert ret['key'] == key
3941

4042
def test_put_same_crc():
4143
key = "test_%s" % r(9)
4244
data = "hello bubby!"
4345
extra.check_crc = 2
4446
ret, err = io.put(policy.token(), key, data, extra)
4547
assert err is None
48+
assert ret['key'] == key
4649

4750
def test_put_no_key():
4851
data = r(100)
49-
ret, err = io.put(policy.token(), key=None, data=data)
52+
extra.check_crc = 0
53+
ret, err = io.put(policy.token(), key=None, data=data, extra=extra)
5054
assert err is None
55+
assert ret['hash'] == ret['key']
56+
57+
def test_put_quote_key():
58+
data = r(100)
59+
key = 'a\\b\\c"你好' + r(9)
60+
ret, err = io.put(policy.token(), key, data)
61+
print err
62+
assert err is None
63+
assert ret['key'].encode('utf8') == key
64+
65+
data = r(100)
66+
key = u'a\\b\\c"你好' + r(9)
67+
ret, err = io.put(policy.token(), key, data)
68+
assert err is None
69+
assert ret['key'] == key
5170

5271
def test_put_unicode1():
5372
key = "test_%s" % r(9) + '你好'
5473
data = key
55-
ret, err = io.put(policy.token(), key, data)
74+
ret, err = io.put(policy.token(), key, data, extra)
5675
assert err is None
5776
assert ret[u'key'].endswith(u'你好')
5877

@@ -86,12 +105,14 @@ def test_put_StringIO():
86105
data = cStringIO.StringIO('hello buddy!')
87106
ret, err = io.put(policy.token(), key, data)
88107
assert err is None
108+
assert ret['key'] == key
89109

90110
def test_put_urlopen():
91111
key = "test_%s" % r(9)
92112
data = urllib.urlopen('http://cheneya.qiniudn.com/hello_jpg')
93113
ret, err = io.put(policy.token(), key, data)
94114
assert err is None
115+
assert ret['key'] == key
95116

96117
def test_put_no_length():
97118
class test_reader(object):
@@ -113,10 +134,12 @@ def read(self, n=None):
113134
extra.crc32 = binascii.crc32('abc') & 0xFFFFFFFF
114135
ret, err = io.put(policy.token(), key, data, extra)
115136
assert err is None
137+
assert ret['key'] == key
116138

117139
test_put()
118140
test_put_same_crc()
119141
test_put_no_key()
142+
test_put_quote_key()
120143
test_put_unicode1()
121144
test_put_unicode2()
122145
test_put_unicode3()
@@ -132,7 +155,7 @@ def test_put_file(self):
132155
extra.check_crc = 1
133156
ret, err = io.put_file(policy.token(), key, localfile, extra)
134157
assert err is None
135-
assert ret is not None
158+
assert ret['key'] == key
136159

137160
def test_put_crc_fail(self):
138161
key = "test_%s" % r(9)

qiniu/test/resumable_io_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from qiniu import resumable_io
1717
from qiniu import rs
1818

19-
bucket = os.getenv("QINIU_BUCKET_NAME")
19+
bucket = os.getenv("QINIU_TEST_BUCKET")
2020
conf.ACCESS_KEY = os.getenv("QINIU_ACCESS_KEY")
2121
conf.SECRET_KEY = os.getenv("QINIU_SECRET_KEY")
2222

qiniu/test/rsf_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import os
77
conf.ACCESS_KEY = os.getenv("QINIU_ACCESS_KEY")
88
conf.SECRET_KEY = os.getenv("QINIU_SECRET_KEY")
9-
bucket_name = os.getenv("QINIU_BUCKET_NAME")
9+
bucket_name = os.getenv("QINIU_TEST_BUCKET")
1010

1111
class TestRsf(unittest.TestCase):
1212
def test_list_prefix(self):

test-env.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export QINIU_ACCESS_KEY="<access_key>"
2+
export QINIU_SECRET_KEY="<secret_key>"
3+
export QINIU_TEST_BUCKET="<bucket_name>"
4+
export QINIU_TEST_DOMAIN="<bucket_domain>"

0 commit comments

Comments
 (0)