Skip to content

Commit e85400e

Browse files
authored
Merge pull request #237 from songfei9315/master
fix home
2 parents f789b28 + bff2ae5 commit e85400e

File tree

6 files changed

+16
-12
lines changed

6 files changed

+16
-12
lines changed

examples/download.py

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
secret_key = '...'
99

1010
q = Auth(access_key, secret_key)
11+
bucket_domain = "..."
12+
key = "..."
1113

1214
#有两种方式构造base_url的形式
1315
base_url = 'http://%s/%s' % (bucket_domain, key)

examples/upload_callback.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# -*- coding: utf-8 -*-
22
# flake8: noqa
33

4-
from qiniu import Auth, put_file, etag,
4+
from qiniu import Auth, put_file, etag
55
import qiniu.config
66

77
access_key = '...'
8-
secret_key = ...'
8+
secret_key = '...'
99

1010
q = Auth(access_key, secret_key)
1111

1212
bucket_name = 'Bucket_Name'
1313

14-
key = 'my-python-logo.png';
14+
key = 'my-python-logo.png'
1515

1616
#上传文件到七牛后, 七牛将文件名和文件大小回调给业务服务器。
1717
policy={
@@ -27,3 +27,4 @@
2727
print(info)
2828
assert ret['key'] == key
2929
assert ret['hash'] == etag(localfile)
30+

examples/upload_pfops.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
from qiniu import Auth, put_file, etag, urlsafe_base64_encode
44
import qiniu.config
55

6-
# access_key = '...'
7-
# secret_key = '...'
6+
access_key = '...'
7+
secret_key = '...'
88

99
# 初始化Auth状态
1010
q = Auth(access_key, secret_key)

qiniu/main.py

+1
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ def main():
3030
else:
3131
print(' '.join(r))
3232

33+
3334
if __name__ == '__main__':
3435
main()

qiniu/zone.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44
import time
55
import requests
6-
6+
import tempfile
77
from qiniu import compat
88
from qiniu import utils
99

@@ -19,11 +19,12 @@ class Zone(object):
1919
up_host: 首选上传地址
2020
up_host_backup: 备用上传地址
2121
"""
22-
def __init__(self, up_host=None, up_host_backup=None, io_host=None, host_cache={}, scheme="http"):
22+
def __init__(self, up_host=None, up_host_backup=None, io_host=None, host_cache={}, scheme="http", home_dir=tempfile.gettempdir()):
2323
"""初始化Zone类"""
2424
self.up_host, self.up_host_backup, self.io_host = up_host, up_host_backup, io_host
2525
self.host_cache = host_cache
2626
self.scheme = scheme
27+
self.home_dir = home_dir
2728

2829
def get_up_host_by_token(self, up_token):
2930
ak, bucket = self.unmarshal_up_token(up_token)
@@ -113,16 +114,15 @@ def host_cache_from_file(self):
113114
f.close()
114115
return
115116

117+
def host_cache_file_path(self):
118+
return os.path.join(self.home_dir, ".qiniu_pythonsdk_hostscache.json")
119+
116120
def host_cache_to_file(self):
117121
path = self.host_cache_file_path()
118122
with open(path, 'w') as f:
119123
compat.json.dump(self.host_cache, f)
120124
f.close()
121125

122-
def host_cache_file_path(self):
123-
home = os.getenv("HOME")
124-
return home + "/.qiniu_pythonsdk_hostscache.json"
125-
126126
def bucket_hosts(self, ak, bucket):
127127
url = "{0}/v1/query?ak={1}&bucket={2}".format(UC_HOST, ak, bucket)
128128
ret = requests.get(url)

test_qiniu.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ def test_hasRead_WithoutSeek_retry2(self):
355355
key = 'withReadAndWithoutSeek_retry2'
356356
data = urlopen("http://www.qiniu.com")
357357
set_default(default_zone=Zone('http://a', 'http://upload.qiniu.com'))
358-
token = self.q.upload_token(bucket_name)
358+
token = self.q.upload_token(bucket_name, key)
359359
ret, info = put_data(token, key, data)
360360
print(info)
361361
assert ret is not None

0 commit comments

Comments
 (0)