Skip to content

Release v6.1.0 #58

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 45 commits into from
Jul 5, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
ed897f4
add test
SunRunAway Jun 30, 2013
865b63a
new put api & new multipart_form
SunRunAway Jul 1, 2013
9be4c2e
crc32
SunRunAway Jul 1, 2013
4bfb993
fix
SunRunAway Jul 1, 2013
bcb418f
README.md
SunRunAway Jul 1, 2013
440ee65
random FileName when key is None
SunRunAway Jul 1, 2013
8a3fc5c
randomize the test keys
SunRunAway Jul 1, 2013
b8688a7
workaround a bug with urllib.quote(unicode)
SunRunAway Jul 2, 2013
ef30b8e
test code
SunRunAway Jul 3, 2013
f5d1e0e
rpc.py/httplib can post chunked data
SunRunAway Jul 3, 2013
ac4d35f
changelog & py docstring
SunRunAway Jul 3, 2013
b3cafae
add unittest info in README.md
SunRunAway Jul 3, 2013
d6bb2fe
remove unused code
SunRunAway Jul 3, 2013
ef7b745
nosetests with coverage
SunRunAway Jul 3, 2013
0bf513f
Merge branch 'feature/multipart_reader' into feature/unittest_doc
SunRunAway Jul 3, 2013
6b45d10
fix
SunRunAway Jul 3, 2013
ebad5f7
fix
SunRunAway Jul 3, 2013
ace4a75
update demo & docs
SunRunAway Jul 3, 2013
b989d5d
fix a bug in io.put, when key is None and extra.params is not empty
SunRunAway Jul 3, 2013
ca68739
Merge branch 'feature/multipart_reader' into feature/unittest_doc
SunRunAway Jul 3, 2013
81c93b7
fix test
SunRunAway Jul 3, 2013
2c81a6f
fix test
SunRunAway Jul 3, 2013
ae87f05
Merge branch 'feature/multipart_reader' into feature/unittest_doc
SunRunAway Jul 3, 2013
cba796c
version=6.1.0
SunRunAway Jul 3, 2013
a73b91c
qiniu_escape
SunRunAway Jul 4, 2013
241b9e2
Merge branch 'feature/multipart_reader' into feature/unittest_doc
SunRunAway Jul 4, 2013
011c858
x
SunRunAway Jul 4, 2013
fa0b457
test-env.sh
SunRunAway Jul 5, 2013
94e9162
Merge branch 'feature/multipart_reader' of github.com:SunRunAway/pyth…
SunRunAway Jul 5, 2013
0ff4001
Merge branch 'feature/multipart_reader' into feature/workaround_urllib
SunRunAway Jul 5, 2013
f418045
Merge branch 'feature/multipart_reader' into feature/unittest_doc
SunRunAway Jul 5, 2013
9a4bd59
test-env.sh in README.md
SunRunAway Jul 5, 2013
187be56
travis
SunRunAway Jul 5, 2013
39d4eca
Merge branch 'feature/multipart_reader' into feature/workaround_urllib
SunRunAway Jul 5, 2013
aa26c17
Merge branch 'feature/multipart_reader' into feature/unittest_doc
SunRunAway Jul 5, 2013
bbed4fe
fix README.md
SunRunAway Jul 5, 2013
c5f8498
fix README.md
SunRunAway Jul 5, 2013
3eb366e
fix README.md
SunRunAway Jul 5, 2013
049e0cb
add test
SunRunAway Jul 5, 2013
daf2566
fix test-env.sh according to impl.md
SunRunAway Jul 5, 2013
b246a33
.travis.yml
SunRunAway Jul 5, 2013
2b34296
Merge pull request #53 from SunRunAway/feature/multipart_reader
xushiwei Jul 5, 2013
8786716
Merge pull request #55 from SunRunAway/feature/workaround_urllib
xushiwei Jul 5, 2013
fb5c1b0
Merge pull request #56 from SunRunAway/feature/unittest_doc
xushiwei Jul 5, 2013
e027dc9
Update CHANGELOG.md
xushiwei Jul 5, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

*.py[cod]

my-test-env.sh

##
## from https://github.com/github/gitignore/blob/master/Python.gitignore
Expand Down
16 changes: 9 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ language: python
python:
- "2.6"
- "2.7"
install:
- "pip install coverage --use-mirrors"
before_script:
- export QINIU_ACCESS_KEY="X0XpjFmLMTJpHB_ESHjeolCtipk-1U3Ok7LVTdoN"
- export QINIU_SECRET_KEY="wenlwkU1AYwNBf7Q9cCoG4VT_GYyrHE9AS_R2u81"
- export QINIU_PIC_KEY="hello_jpg"
- export QINIU_NOEXIST_PIC_KEY="no_exist"
- export QINIU_BUCKET_NAME="pysdk"
- export QINIU_DOMAIN="pysdk.qiniudn.com"
script:
- python setup.py nosetests
- export PYTHONPATH="$PYTHONPATH:." && python docs/demo.py
- export QINIU_TEST_BUCKET="pysdk"
- export QINIU_TEST_DOMAIN="pysdk.qiniudn.com"
- export PYTHONPATH="$PYTHONPATH:."
script:
- nosetests --with-coverage --cover-package=qiniu
- python docs/demo.py
- python docs/gist/conf.py
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
## CHANGE LOG

### v6.1.0

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

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


### v6.0.1

2013-06-27 issue [#43](https://github.com/qiniu/python-sdk/pull/43)

- 遵循 [sdkspec v6.0.2](https://github.com/qiniu/sdkspec/tree/v6.0.2)
- 现在,rsf.list_prefix在没有更多数据时,err 会返回 rsf.EOF


### v6.0.0

2013-06-26 issue [#42](https://github.com/qiniu/python-sdk/pull/42)
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ Qiniu Resource Storage SDK for Python

参考文档:[七牛云存储 Python SDK 使用指南](https://github.com/qiniu/python-sdk/blob/develop/docs/README.md)

## 单元测试

1. 测试环境

1. [开通七牛开发者帐号](https://portal.qiniu.com/signup)
2. [登录七牛开发者自助平台,查看 Access Key 和 Secret Key](https://portal.qiniu.com/setting/key) 。
3. 在开发者后台新建一个空间

然后将在`test-env.sh`中填入相关信息。

2. 需安装[nosetests](https://nose.readthedocs.org/en/latest/)测试工具。

运行测试:

source test-env.sh
nosetests

## 贡献代码

1. Fork
Expand Down
9 changes: 5 additions & 4 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,12 @@ qiniu.conf.SECRET_KEY = "<YOUR_APP_SECRET_KEY>"

import qiniu.io

extra = qiniu.io.PutExtra(bucket_name)
extra = qiniu.io.PutExtra()
extra.mime_type = "text/plain"

ret, err = qiniu.io.put(uptoken, key, "hello!", extra)
# data 可以是str或read()able对象
data = StringIO.StringIO("hello!")
ret, err = qiniu.io.put(uptoken, key, data, extra)
if err is not None:
error(err)
return
Expand All @@ -279,9 +281,8 @@ qiniu.conf.SECRET_KEY = "<YOUR_APP_SECRET_KEY>"
import qiniu.io

localfile = "%s" % __file__
extra = qiniu.io.PutExtra(bucket_name)

ret, err = qiniu.io.put_file(uptoken, key, localfile, extra)
ret, err = qiniu.io.put_file(uptoken, key, localfile)
if err is not None:
error(err)
return
Expand Down
18 changes: 10 additions & 8 deletions docs/demo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import os
import sys
import StringIO

# @gist import_io
import qiniu.io
Expand Down Expand Up @@ -49,9 +50,9 @@ def _setup():
if access_key is None:
exit("请配置环境变量 QINIU_ACCESS_KEY")
secret_key = getenv("QINIU_SECRET_KEY")
bucket_name = getenv("QINIU_BUCKET_NAME")
domain = getenv("QINIU_DOMAIN")
pickey = getenv("QINIU_PIC_KEY")
bucket_name = getenv("QINIU_TEST_BUCKET")
domain = getenv("QINIU_TEST_DOMAIN")
pickey = 'QINIU_UNIT_TEST_PIC'
setup(access_key, secret_key, bucket_name, domain, pickey)

def getenv(name):
Expand Down Expand Up @@ -95,9 +96,8 @@ def put_file():

# @gist put_file
localfile = "%s" % __file__
extra = qiniu.io.PutExtra(bucket_name)

ret, err = qiniu.io.put_file(uptoken, key, localfile, extra)

ret, err = qiniu.io.put_file(uptoken, key, localfile)
if err is not None:
error(err)
return
Expand All @@ -110,10 +110,12 @@ def put_binary():
qiniu.rs.Client().delete(bucket_name, key)

# @gist put
extra = qiniu.io.PutExtra(bucket_name)
extra = qiniu.io.PutExtra()
extra.mime_type = "text/plain"

ret, err = qiniu.io.put(uptoken, key, "hello!", extra)
# data 可以是str或read()able对象
data = StringIO.StringIO("hello!")
ret, err = qiniu.io.put(uptoken, key, data, extra)
if err is not None:
error(err)
return
Expand Down
4 changes: 2 additions & 2 deletions qiniu/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
'''
Qiniu Resource Storage SDK for Python
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -7,4 +6,5 @@
<https://github.com/qiniu/python-sdk/blob/develop/docs/README.md>
'''

__version__ = '6.0.1'
# -*- coding: utf-8 -*-
__version__ = '6.1.0'
123 changes: 123 additions & 0 deletions qiniu/httplib_chunk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
"""
Modified from standard httplib

1. HTTPConnection can send trunked data.
2. Remove httplib's automatic Content-Length insertion when data is a file-like object.
"""

# -*- coding: utf-8 -*-

import httplib
from httplib import _CS_REQ_STARTED, _CS_REQ_SENT
import string
import os
from array import array

class HTTPConnection(httplib.HTTPConnection):

def send(self, data, is_chunked=False):
"""Send `data' to the server."""
if self.sock is None:
if self.auto_open:
self.connect()
else:
raise NotConnected()

if self.debuglevel > 0:
print "send:", repr(data)
blocksize = 8192
if hasattr(data,'read') and not isinstance(data, array):
if self.debuglevel > 0: print "sendIng a read()able"
datablock = data.read(blocksize)
while datablock:
if self.debuglevel > 0:
print 'chunked:', is_chunked
if is_chunked:
if self.debuglevel > 0: print 'send: with trunked data'
lenstr = string.upper(hex(len(datablock))[2:])
self.sock.sendall('%s\r\n%s\r\n' % (lenstr, datablock))
else:
self.sock.sendall(datablock)
datablock = data.read(blocksize)
if is_chunked:
self.sock.sendall('0\r\n\r\n')
else:
self.sock.sendall(data)


def _set_content_length(self, body):
# Set the content-length based on the body.
thelen = None
try:
thelen = str(len(body))
except (TypeError, AttributeError), te:
# Don't send a length if this failed
if self.debuglevel > 0: print "Cannot stat!!"

if thelen is not None:
self.putheader('Content-Length', thelen)
return True
return False


def _send_request(self, method, url, body, headers):
# Honor explicitly requested Host: and Accept-Encoding: headers.
header_names = dict.fromkeys([k.lower() for k in headers])
skips = {}
if 'host' in header_names:
skips['skip_host'] = 1
if 'accept-encoding' in header_names:
skips['skip_accept_encoding'] = 1

self.putrequest(method, url, **skips)

is_chunked = False
if body and header_names.get('Transfer-Encoding') == 'chunked':
is_chunked = True
elif body and ('content-length' not in header_names):
is_chunked = not self._set_content_length(body)
if is_chunked:
self.putheader('Transfer-Encoding', 'chunked')
for hdr, value in headers.iteritems():
self.putheader(hdr, value)

self.endheaders(body, is_chunked=is_chunked)


def endheaders(self, message_body=None, is_chunked=False):
"""Indicate that the last header line has been sent to the server.

This method sends the request to the server. The optional
message_body argument can be used to pass a message body
associated with the request. The message body will be sent in
the same packet as the message headers if it is string, otherwise it is
sent as a separate packet.
"""
if self.__state == _CS_REQ_STARTED:
self.__state = _CS_REQ_SENT
else:
raise CannotSendHeader()
self._send_output(message_body, is_chunked=is_chunked)


def _send_output(self, message_body=None, is_chunked=False):
"""Send the currently buffered request and clear the buffer.

Appends an extra \\r\\n to the buffer.
A message_body may be specified, to be appended to the request.
"""
self._buffer.extend(("", ""))
msg = "\r\n".join(self._buffer)
del self._buffer[:]
# If msg and message_body are sent in a single send() call,
# it will avoid performance problems caused by the interaction
# between delayed ack and the Nagle algorithm.
if isinstance(message_body, str):
msg += message_body
message_body = None
self.send(msg)
if message_body is not None:
#message_body was not a string (i.e. it is a file) and
#we must run the risk of Nagle
self.send(message_body, is_chunked=is_chunked)

Loading