Skip to content

Commit 0d7f6e1

Browse files
committed
Merge pull request #47 from SunRunAway/feature/rsf_eof
Feature/rsf eof
2 parents ccdc380 + 9737402 commit 0d7f6e1

File tree

5 files changed

+30
-4
lines changed

5 files changed

+30
-4
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
## CHANGE LOG
22

3+
### v6.0.1
4+
5+
2013-06-27 issue [#43](https://github.com/qiniu/python-sdk/pull/43)
6+
7+
- 遵循 [sdkspec v6.0.2](https://github.com/qiniu/sdkspec/tree/v6.0.2)
8+
- 现在,rsf.list_prefix在没有更多数据时,err 会返回 rsf.EOF
9+
310
### v6.0.0
411

512
2013-06-26 issue [#42](https://github.com/qiniu/python-sdk/pull/42)

docs/demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def batch():
326326
# @endgist
327327

328328
def list_prefix():
329-
''' 列出文件操作 '''
329+
''' 前缀查询操作 '''
330330
rets, err = qiniu.rsf.Client().list_prefix(bucket_name, prefix="test", limit=3)
331331
if err is not None:
332332
error(err)

qiniu/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11
# -*- coding: utf-8 -*-
2+
'''
3+
Qiniu Resource Storage SDK for Python
4+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5+
6+
For detailed document, please see:
7+
<https://github.com/qiniu/python-sdk/blob/develop/docs/README.md>
8+
'''
9+
210
__version__ = '6.0.1'

qiniu/rsf.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import conf
44
import urllib
55

6+
EOF = 'EOF'
7+
8+
69
class Client(object):
710
conn = None
811
def __init__(self, mac=None):
@@ -11,11 +14,16 @@ def __init__(self, mac=None):
1114
self.conn = auth.digest.Client(host=conf.RSF_HOST, mac=mac)
1215

1316
def list_prefix(self, bucket, prefix=None, marker=None, limit=None):
14-
'''
17+
'''前缀查询:
1518
* bucket => str
1619
* prefix => str
1720
* marker => str
1821
* limit => int
22+
* return ret => {'items': items, 'marker': markerOut}, err => str
23+
24+
1. 首次请求 marker = None
25+
2. 无论 err 值如何,均应该先看 ret.get('items') 是否有内容
26+
3. 如果后续没有更多数据,err 返回 EOF,markerOut 返回 None(但不通过该特征来判断是否结束)
1927
'''
2028
ops = {
2129
'bucket': bucket,
@@ -27,4 +35,7 @@ def list_prefix(self, bucket, prefix=None, marker=None, limit=None):
2735
if prefix is not None:
2836
ops['prefix'] = prefix
2937
url = '%s?%s' % ('/list', urllib.urlencode(ops))
30-
return self.conn.call_with(url, body=None, content_type='application/x-www-form-urlencoded')
38+
ret, err = self.conn.call_with(url, body=None, content_type='application/x-www-form-urlencoded')
39+
if not ret.get('marker'):
40+
err = EOF
41+
return ret, err

qiniu/test/rsf_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class TestRsf(unittest.TestCase):
1212
def test_list_prefix(self):
1313
c = rsf.Client()
1414
ret, err = c.list_prefix(bucket_name)
15-
assert err is None
15+
assert err is rsf.EOF
1616
self.assertEqual(len(ret.get('items'))>0, True)
1717

1818

0 commit comments

Comments
 (0)