Skip to content

release v6.1.2 #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Aug 13, 2013
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
## CHANGE LOG

### v6.1.2

2013-08-01 issue [#66](https://github.com/qiniu/python-sdk/pull/66)

- 修复在Windows环境下put_file无法读取文件的bug
- 修复在Windows环境下创建临时文件的权限问题
- 修复在Windows环境下对二进制文件计算crc32的bug

### v6.1.1

2013-07-05 issue [#60](https://github.com/qiniu/python-sdk/pull/60)

- 整理文档


### v6.1.0

2013-07-03 issue [#58](https://github.com/qiniu/python-sdk/pull/58)
Expand Down
2 changes: 1 addition & 1 deletion qiniu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
'''

# -*- coding: utf-8 -*-
__version__ = '6.1.1'
__version__ = '6.1.2'
4 changes: 2 additions & 2 deletions qiniu/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ def put_file(uptoken, key, localfile, extra=None):
"""
if extra is not None and extra.check_crc == 1:
extra.crc32 = _get_file_crc32(localfile)
with open(localfile) as f:
with open(localfile, 'rb') as f:
return put(uptoken, key, f, extra)


_BLOCK_SIZE = 1024 * 1024 * 4

def _get_file_crc32(filepath):
with open(filepath) as f:
with open(filepath, 'rb') as f:
block = f.read(_BLOCK_SIZE)
crc = 0
while len(block) != 0:
Expand Down
2 changes: 1 addition & 1 deletion qiniu/test/io_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def test_get_file_crc32(self):
file_path = '%s' % __file__

data = None
with open(file_path) as f:
with open(file_path, 'rb') as f:
data = f.read()
io._BLOCK_SIZE = 4
assert binascii.crc32(data) & 0xFFFFFFFF == io._get_file_crc32(file_path)
Expand Down
15 changes: 11 additions & 4 deletions qiniu/test/resumable_io_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import unittest
import string
import random
import platform
try:
import zlib as binascii
except ImportError:
Expand Down Expand Up @@ -34,7 +35,7 @@ def test_block(self):
rets = [0, 0]
data_slice_2 = "\nbye!"
ret, err = resumable_io.mkblock(client, len(data_slice_2), data_slice_2)
assert err is None, err
assert err is None, err
self.assertEqual(ret["crc32"], binascii.crc32(data_slice_2))

extra = resumable_io.PutExtra(bucket)
Expand All @@ -49,10 +50,15 @@ def test_block(self):
assert err is None, err
self.assertEqual(ret["hash"], "FtCFo0mQugW98uaPYgr54Vb1QsO0", "hash not match")
rs.Client().delete(bucket, key)

def test_put(self):
src = urllib.urlopen("http://cheneya.qiniudn.com/hello_jpg")
dst = tempfile.NamedTemporaryFile()
ostype = platform.system()
if ostype.lower().find("windows") != -1:
tmpf = "".join([os.getcwd(), os.tmpnam()])
else:
tmpf = os.tmpnam()
dst = open(tmpf, 'wb')
shutil.copyfileobj(src, dst)
src.close()

Expand All @@ -63,11 +69,12 @@ def test_put(self):
localfile = dst.name
ret, err = resumable_io.put_file(policy.token(), key, localfile, extra)
dst.close()
os.remove(tmpf)

assert err is None, err
self.assertEqual(ret["hash"], "FnyTMUqPNRTdk1Wou7oLqDHkBm_p", "hash not match")
rs.Client().delete(bucket, key)


if __name__ == "__main__":
unittest.main()