Skip to content

Commit

Permalink
resume upload part concurrently (#440)
Browse files Browse the repository at this point in the history
  • Loading branch information
lihsai0 authored Oct 8, 2023
1 parent 7d6eb2d commit f04c995
Show file tree
Hide file tree
Showing 17 changed files with 2,710 additions and 444 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
shell: bash -l {0}
run: |
python -m pip install --upgrade pip
python -m pip install --ignore-installed "coverage<7.2" flake8 pytest pytest-cov freezegun requests scrutinizer-ocular codecov
python -m pip install -I -e ".[dev]"
- name: Run cases
shell: bash -l {0}
env:
Expand Down
8 changes: 8 additions & 0 deletions qiniu/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def upload_token(
key: 上传的文件名,默认为空
expires: 上传凭证的过期时间,默认为3600s
policy: 上传策略,默认为空
strict_policy: 严格模式,将校验 policy 字段,默认为 True
Returns:
上传凭证
Expand Down Expand Up @@ -175,6 +176,13 @@ def up_token_decode(up_token):
dict_policy = json.loads(decode_policy)
return ak, sign, dict_policy

@staticmethod
def get_bucket_name(up_token):
_, _, policy = Auth.up_token_decode(up_token)
if not policy or not policy['scope']:
return None
return policy['scope'].split(':', 1)[0]

def __upload_token(self, policy):
data = json.dumps(policy, separators=(',', ':'))
return self.token_with_data(data)
Expand Down
11 changes: 11 additions & 0 deletions qiniu/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
pythoncompat
"""

import os
import sys

try:
Expand Down Expand Up @@ -51,6 +52,13 @@ def s(data):
def u(data):
return unicode(data, 'unicode_escape') # noqa

def is_seekable(data):
try:
data.seek(0, os.SEEK_CUR)
return True
except (AttributeError, IOError):
return False

elif is_py3:
from urllib.parse import urlparse # noqa
import io
Expand All @@ -75,3 +83,6 @@ def s(data):

def u(data):
return data

def is_seekable(data):
return data.seekable()
2 changes: 2 additions & 0 deletions qiniu/region.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ def get_api_host(self, ak, bucket, home_dir=None):
return api_hosts[0]

def get_up_host(self, ak, bucket, home_dir):
if home_dir is None:
home_dir = os.getcwd()
bucket_hosts = self.get_bucket_hosts(ak, bucket, home_dir)
if 'upHosts' not in bucket_hosts:
bucket_hosts = self.get_bucket_hosts(ak, bucket, home_dir, force=True)
Expand Down
Loading

0 comments on commit f04c995

Please sign in to comment.