Skip to content

Commit 7f49b76

Browse files
committed
change new rpc
1 parent bbf9756 commit 7f49b76

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

qiniu/resumable_io.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,15 @@ def put_file(uptoken, key, localfile, extra):
7171
return ret
7272

7373

74-
def put(uptoken, key, f, fsize, extra):
74+
def put(uptoken, key, f, fsize, extra, host=None):
7575
""" 上传二进制流, 通过将data "切片" 分段上传 """
7676
if not isinstance(extra, PutExtra):
7777
print("extra must the instance of PutExtra")
7878
return
7979

80+
if host is None:
81+
host = conf.UP_HOST
82+
8083
block_cnt = block_count(fsize)
8184
if extra.progresses is None:
8285
extra.progresses = [None] * block_cnt
@@ -97,7 +100,7 @@ def put(uptoken, key, f, fsize, extra):
97100
read_length = fsize - i * _block_size
98101
data_slice = f.read(read_length)
99102
while True:
100-
err = resumable_block_put(data_slice, i, extra, uptoken)
103+
err = resumable_block_put(data_slice, i, extra, uptoken, host)
101104
if err is None:
102105
break
103106

@@ -106,19 +109,19 @@ def put(uptoken, key, f, fsize, extra):
106109
return None, err_put_failed
107110
print err, ".. retry"
108111

109-
mkfile_host = extra.progresses[-1]["host"] if block_cnt else conf.UP_HOST
112+
mkfile_host = extra.progresses[-1]["host"] if block_cnt else host
110113
mkfile_client = auth_up.Client(uptoken, mkfile_host)
111-
return mkfile(mkfile_client, key, fsize, extra)
114+
return mkfile(mkfile_client, key, fsize, extra, mkfile_host)
112115

113116

114-
def resumable_block_put(block, index, extra, uptoken):
117+
def resumable_block_put(block, index, extra, uptoken, host):
115118
block_size = len(block)
116119

117-
mkblk_client = auth_up.Client(uptoken, conf.UP_HOST)
120+
mkblk_client = auth_up.Client(uptoken, host)
118121
if extra.progresses[index] is None or "ctx" not in extra.progresses[index]:
119122
crc32 = gen_crc32(block)
120123
block = bytearray(block)
121-
extra.progresses[index], err = mkblock(mkblk_client, block_size, block)
124+
extra.progresses[index], err = mkblock(mkblk_client, block_size, block, host)
122125
if err is not None:
123126
extra.notify_err(index, block_size, err)
124127
return err
@@ -133,8 +136,8 @@ def block_count(size):
133136
return (size + _block_mask) / _block_size
134137

135138

136-
def mkblock(client, block_size, first_chunk):
137-
url = "http://%s/mkblk/%s" % (conf.UP_HOST, block_size)
139+
def mkblock(client, block_size, first_chunk, host):
140+
url = "http://%s/mkblk/%s" % (host, block_size)
138141
content_type = "application/octet-stream"
139142
return client.call_with(url, first_chunk, content_type, len(first_chunk))
140143

@@ -146,8 +149,8 @@ def putblock(client, block_ret, chunk):
146149
return client.call_with(url, chunk, content_type, len(chunk))
147150

148151

149-
def mkfile(client, key, fsize, extra):
150-
url = ["http://%s/mkfile/%s" % (conf.UP_HOST, fsize)]
152+
def mkfile(client, key, fsize, extra, host):
153+
url = ["http://%s/mkfile/%s" % (host, fsize)]
151154

152155
if extra.mimetype:
153156
url.append("mimeType/%s" % urlsafe_b64encode(extra.mimetype))

0 commit comments

Comments
 (0)