Skip to content

resume upload part concurrently #440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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