3
3
import os
4
4
import time
5
5
import requests
6
-
6
+ import tempfile
7
7
from qiniu import compat
8
8
from qiniu import utils
9
9
@@ -19,11 +19,12 @@ class Zone(object):
19
19
up_host: 首选上传地址
20
20
up_host_backup: 备用上传地址
21
21
"""
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 () ):
23
23
"""初始化Zone类"""
24
24
self .up_host , self .up_host_backup , self .io_host = up_host , up_host_backup , io_host
25
25
self .host_cache = host_cache
26
26
self .scheme = scheme
27
+ self .home_dir = home_dir
27
28
28
29
def get_up_host_by_token (self , up_token ):
29
30
ak , bucket = self .unmarshal_up_token (up_token )
@@ -113,16 +114,15 @@ def host_cache_from_file(self):
113
114
f .close ()
114
115
return
115
116
117
+ def host_cache_file_path (self ):
118
+ return os .path .join (self .home_dir , ".qiniu_pythonsdk_hostscache.json" )
119
+
116
120
def host_cache_to_file (self ):
117
121
path = self .host_cache_file_path ()
118
122
with open (path , 'w' ) as f :
119
123
compat .json .dump (self .host_cache , f )
120
124
f .close ()
121
125
122
- def host_cache_file_path (self ):
123
- home = os .getenv ("HOME" )
124
- return home + "/.qiniu_pythonsdk_hostscache.json"
125
-
126
126
def bucket_hosts (self , ak , bucket ):
127
127
url = "{0}/v1/query?ak={1}&bucket={2}" .format (UC_HOST , ak , bucket )
128
128
ret = requests .get (url )
0 commit comments