Skip to content

Commit 63ee927

Browse files
committed
bug fix
1 parent 3506dff commit 63ee927

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

qiniu/auth/up.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55

66
class Client(rpc.Client):
77
up_token = None
8-
8+
99
def __init__(self, up_token, host=None):
1010
if host is None:
1111
host = conf.UP_HOST
12+
if host.startswith("http://"):
13+
host = host[7:]
1214
self.up_token = up_token
1315
super(Client, self).__init__(host)
1416

qiniu/resumable_io.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,14 @@ def put(uptoken, key, f, fsize, extra):
8484
if extra.chunk_size is None:
8585
extra.chunk_size = _chunk_size
8686

87-
client = auth.up.Client(uptoken)
8887
for i in xrange(0, block_cnt):
8988
try_time = extra.try_times
9089
read_length = _block_size
9190
if (i+1)*_block_size > fsize:
9291
read_length = fsize - i*_block_size
9392
data_slice = f.read(read_length)
9493
while True:
95-
err = resumable_block_put(client, data_slice, i, extra)
94+
err = resumable_block_put(data_slice, i, extra, uptoken)
9695
if err is None:
9796
break
9897

@@ -105,30 +104,33 @@ def put(uptoken, key, f, fsize, extra):
105104

106105
# ----------------------------------------------------------
107106

108-
def resumable_block_put(client, block, index, extra):
107+
def resumable_block_put(block, index, extra, uptoken):
109108
block_size = len(block)
110109

110+
mkblk_client = auth.up.Client(uptoken, conf.UP_HOST)
111111
if extra.progresses[index] is None or "ctx" not in extra.progresses[index]:
112112
end_pos = extra.chunk_size-1
113113
if block_size < extra.chunk_size:
114114
end_pos = block_size-1
115115
chunk = block[: end_pos]
116116
crc32 = gen_crc32(chunk)
117117
chunk = bytearray(chunk)
118-
extra.progresses[index], err = mkblock(client, block_size, chunk)
118+
extra.progresses[index], err = mkblock(mkblk_client, block_size, chunk)
119119
if not extra.progresses[index]["crc32"] == crc32:
120120
return err_unmatched_checksum
121121
if err is not None:
122122
extra.notify_err(index, end_pos + 1, err)
123123
return err
124124
extra.notify(index, end_pos + 1, extra.progresses[index])
125125

126+
bput_client = auth.up.Client(uptoken, extra.progresses[index]["host"])
126127
while extra.progresses[index]["offset"] < block_size:
127128
offset = extra.progresses[index]["offset"]
128129
chunk = block[offset: offset+extra.chunk_size-1]
129130
crc32 = gen_crc32(chunk)
130131
chunk = bytearray(chunk)
131-
extra.progresses[index], err = putblock(client, extra.progresses[index], chunk)
132+
133+
extra.progresses[index], err = putblock(bput_client, extra.progresses[index], chunk)
132134
if not extra.progresses[index]["crc32"] == crc32:
133135
return err_unmatched_checksum
134136
if err is not None:

0 commit comments

Comments
 (0)