Skip to content

Commit

Permalink
Merge pull request qiniu#166 from forrest-mao/update_entry
Browse files Browse the repository at this point in the history
update entry construction
  • Loading branch information
longbai committed May 22, 2015
2 parents f936671 + 2d67ae8 commit 052d33f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion qiniu/services/storage/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def copy(self, bucket, key, bucket_to, key_to):
to = entry(bucket_to, key_to)
return self.__rs_do('copy', resource, to)

def fetch(self, url, bucket, key):
def fetch(self, url, bucket, key=None):
"""抓取文件:
从指定URL抓取资源,并将该资源存储到指定空间中,具体规格参考:
http://developer.qiniu.com/docs/v6/api/reference/rs/fetch.html
Expand Down
5 changes: 4 additions & 1 deletion qiniu/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,7 @@ def entry(bucket, key):
Returns:
符合七牛API规格的数据格式
"""
return urlsafe_base64_encode('{0}:{1}'.format(bucket, key))
if key is None:
return urlsafe_base64_encode('{0}'.format(bucket))
else:
return urlsafe_base64_encode('{0}:{1}'.format(bucket, key))
6 changes: 6 additions & 0 deletions test_qiniu.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ def test_fetch(self):
assert ret['key'] == 'fetch.html'
assert ret['hash'] == 'FhwVT7vs6xqs1nu_vEdo_4x4qBMB'

def test_fetch_without_key(self):
ret, info = self.bucket.fetch('http://developer.qiniu.com/docs/v6/sdk/python-sdk.html', bucket_name)
print(info)
assert ret['key'] == 'FhwVT7vs6xqs1nu_vEdo_4x4qBMB'
assert ret['hash'] == 'FhwVT7vs6xqs1nu_vEdo_4x4qBMB'

def test_stat(self):
ret, info = self.bucket.stat(bucket_name, 'python-sdk.html')
print(info)
Expand Down

0 comments on commit 052d33f

Please sign in to comment.