Skip to content

Commit 052d33f

Browse files
committed
Merge pull request #166 from forrest-mao/update_entry
update entry construction
2 parents f936671 + 2d67ae8 commit 052d33f

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

qiniu/services/storage/bucket.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def copy(self, bucket, key, bucket_to, key_to):
156156
to = entry(bucket_to, key_to)
157157
return self.__rs_do('copy', resource, to)
158158

159-
def fetch(self, url, bucket, key):
159+
def fetch(self, url, bucket, key=None):
160160
"""抓取文件:
161161
从指定URL抓取资源,并将该资源存储到指定空间中,具体规格参考:
162162
http://developer.qiniu.com/docs/v6/api/reference/rs/fetch.html

qiniu/utils.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,7 @@ def entry(bucket, key):
151151
Returns:
152152
符合七牛API规格的数据格式
153153
"""
154-
return urlsafe_base64_encode('{0}:{1}'.format(bucket, key))
154+
if key is None:
155+
return urlsafe_base64_encode('{0}'.format(bucket))
156+
else:
157+
return urlsafe_base64_encode('{0}:{1}'.format(bucket, key))

test_qiniu.py

+6
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ def test_fetch(self):
134134
assert ret['key'] == 'fetch.html'
135135
assert ret['hash'] == 'FhwVT7vs6xqs1nu_vEdo_4x4qBMB'
136136

137+
def test_fetch_without_key(self):
138+
ret, info = self.bucket.fetch('http://developer.qiniu.com/docs/v6/sdk/python-sdk.html', bucket_name)
139+
print(info)
140+
assert ret['key'] == 'FhwVT7vs6xqs1nu_vEdo_4x4qBMB'
141+
assert ret['hash'] == 'FhwVT7vs6xqs1nu_vEdo_4x4qBMB'
142+
137143
def test_stat(self):
138144
ret, info = self.bucket.stat(bucket_name, 'python-sdk.html')
139145
print(info)

0 commit comments

Comments
 (0)