Skip to content

Feature/rsf eof #47

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 4 commits into from
Jun 27, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
## CHANGE LOG

### 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
2 changes: 1 addition & 1 deletion docs/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def batch():
# @endgist

def list_prefix():
''' 列出文件操作 '''
''' 前缀查询操作 '''
rets, err = qiniu.rsf.Client().list_prefix(bucket_name, prefix="test", limit=3)
if err is not None:
error(err)
Expand Down
8 changes: 8 additions & 0 deletions qiniu/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
# -*- coding: utf-8 -*-
'''
Qiniu Resource Storage SDK for Python
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

For detailed document, please see:
<https://github.com/qiniu/python-sdk/blob/develop/docs/README.md>
'''

__version__ = '6.0.1'
15 changes: 13 additions & 2 deletions qiniu/rsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import conf
import urllib

EOF = 'EOF'


class Client(object):
conn = None
def __init__(self, mac=None):
Expand All @@ -11,11 +14,16 @@ def __init__(self, mac=None):
self.conn = auth.digest.Client(host=conf.RSF_HOST, mac=mac)

def list_prefix(self, bucket, prefix=None, marker=None, limit=None):
'''
'''前缀查询:
* bucket => str
* prefix => str
* marker => str
* limit => int
* return ret => {'items': items, 'marker': markerOut}, err => str

1. 首次请求 marker = None
2. 无论 err 值如何,均应该先看 ret.get('items') 是否有内容
3. 如果后续没有更多数据,err 返回 EOF,markerOut 返回 None(但不通过该特征来判断是否结束)
'''
ops = {
'bucket': bucket,
Expand All @@ -27,4 +35,7 @@ def list_prefix(self, bucket, prefix=None, marker=None, limit=None):
if prefix is not None:
ops['prefix'] = prefix
url = '%s?%s' % ('/list', urllib.urlencode(ops))
return self.conn.call_with(url, body=None, content_type='application/x-www-form-urlencoded')
ret, err = self.conn.call_with(url, body=None, content_type='application/x-www-form-urlencoded')
if not ret.get('marker'):
err = EOF
return ret, err
2 changes: 1 addition & 1 deletion qiniu/test/rsf_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class TestRsf(unittest.TestCase):
def test_list_prefix(self):
c = rsf.Client()
ret, err = c.list_prefix(bucket_name)
assert err is None
assert err is rsf.EOF
self.assertEqual(len(ret.get('items'))>0, True)


Expand Down