Skip to content

Commit 111422a

Browse files
committed
add futures for python2.7
1 parent 8992dbb commit 111422a

File tree

11 files changed

+31
-16
lines changed

11 files changed

+31
-16
lines changed

.github/workflows/ci-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
shell: bash -l {0}
4040
run: |
4141
python -m pip install --upgrade pip
42-
python -m pip install --ignore-installed "coverage<7.2" flake8 pytest pytest-cov freezegun requests scrutinizer-ocular codecov
42+
python -m pip install -I -e ".[dev]"
4343
- name: Run cases
4444
shell: bash -l {0}
4545
env:

qiniu/compat.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ def s(data):
5151
def u(data):
5252
return unicode(data, 'unicode_escape') # noqa
5353

54+
def is_seekable(data):
55+
try:
56+
data.seek(0, 1)
57+
return True
58+
except (AttributeError, IOError):
59+
return False
60+
5461
elif is_py3:
5562
from urllib.parse import urlparse # noqa
5663
import io
@@ -75,3 +82,6 @@ def s(data):
7582

7683
def u(data):
7784
return data
85+
86+
def is_seekable(data):
87+
return data.seekable()

qiniu/services/storage/legacy.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
import hashlib
23
import time
34

qiniu/services/storage/uploader.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22
import os
33

4-
from qiniu import config
4+
from qiniu.config import _BLOCK_SIZE, get_default
55

66
from qiniu.auth import Auth
77
from qiniu.utils import crc32, file_crc32, rfc_from_timestamp
@@ -37,7 +37,7 @@ def put_data(
3737
final_data = b''
3838
if hasattr(data, 'read'):
3939
while True:
40-
tmp_data = data.read(config._BLOCK_SIZE)
40+
tmp_data = data.read(_BLOCK_SIZE)
4141
if len(tmp_data) == 0:
4242
break
4343
else:
@@ -84,7 +84,7 @@ def put_file(
8484
with open(file_path, 'rb') as input_stream:
8585
file_name = os.path.basename(file_path)
8686
modify_time = int(os.path.getmtime(file_path))
87-
if size > config.get_default('default_upload_threshold'):
87+
if size > get_default('default_upload_threshold'):
8888
ret, info = put_stream(
8989
up_token, key, input_stream, file_name, size, hostscache_dir, params,
9090
mime_type, progress_handler,

qiniu/services/storage/uploaders/abc/resume_uploader_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __init__(
3232
concurrent_executor: futures.Executor
3333
kwargs
3434
"""
35-
super().__init__(bucket_name, **kwargs)
35+
super(ResumeUploaderBase, self).__init__(bucket_name, **kwargs)
3636

3737
self.part_size = kwargs.get('part_size', 4 * (1024 ** 2))
3838

qiniu/services/storage/uploaders/abc/uploader_base.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from qiniu.auth import Auth # noqa
77

88

9-
class UploaderBase:
9+
class UploaderBase(object):
1010
"""
1111
Attributes
1212
----------
@@ -33,8 +33,6 @@ def __init__(
3333
kwargs
3434
The others arguments may be used by subclass.
3535
"""
36-
super().__init__()
37-
3836
self.bucket_name = bucket_name
3937

4038
# change the default when implements AuthProvider

qiniu/services/storage/uploaders/form_uploader.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from os import path
33
from time import time
44

5+
from qiniu.compat import is_seekable
56
from qiniu.utils import b, io_crc32
67
from qiniu.auth import Auth
78
from qiniu.http import qn_http_client
@@ -18,7 +19,7 @@ def __init__(self, bucket_name, **kwargs):
1819
kwargs
1920
auth, regions
2021
"""
21-
super().__init__(bucket_name, **kwargs)
22+
super(FormUploader, self).__init__(bucket_name, **kwargs)
2223

2324
self.progress_handler = kwargs.get(
2425
'progress_handler',
@@ -162,7 +163,7 @@ def __upload_data(
162163
if resp.ok() and ret:
163164
return ret, resp
164165
if (
165-
not data.seekable() or
166+
not is_seekable(data) or
166167
not resp.need_retry()
167168
):
168169
return ret, resp
@@ -231,7 +232,7 @@ def __get_file_crc32(self, data):
231232
str
232233
"""
233234
result = None
234-
if not data.seekable():
235+
if not is_seekable(data):
235236
return result
236237
result = io_crc32(data)
237238
data.seek(0)

qiniu/services/storage/uploaders/io_chunked.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import io
22
from collections import namedtuple
33

4+
from qiniu.compat import is_seekable
5+
46

57
ChunkInfo = namedtuple(
68
'ChunkInfo',
@@ -21,7 +23,7 @@ def __init__(
2123
lock,
2224
buffer_size=4 * (1024 ** 2) # 4MB just for demo
2325
):
24-
if not base_io.seekable():
26+
if not is_seekable(base_io):
2527
raise TypeError('"base_io" must be seekable')
2628
self.__base_io = base_io
2729
self.__chunk_start = chunk_offset

qiniu/services/storage/uploaders/resume_uploader_v1.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from threading import Lock
88
from time import time
99

10+
from qiniu.compat import is_seekable
1011
from qiniu.auth import Auth
1112
from qiniu.http import qn_http_client, ResponseInfo
1213
from qiniu.utils import b, io_crc32, urlsafe_base64_encode
@@ -585,7 +586,7 @@ def __upload_part(
585586
)
586587
return part, resp
587588
if (
588-
not chunked_data.seekable() or
589+
not is_seekable(chunked_data) or
589590
not resp.need_retry()
590591
):
591592
return part, resp

qiniu/services/storage/uploaders/resume_uploader_v2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from threading import Lock
66
from time import time
77

8+
from qiniu.compat import is_seekable
89
from qiniu.auth import Auth
910
from qiniu.http import qn_http_client, ResponseInfo
1011
from qiniu.utils import b, io_md5, urlsafe_base64_encode
@@ -694,7 +695,7 @@ def __upload_part(
694695
)
695696
return part, resp
696697
if (
697-
not chunked_data.seekable() or
698+
not is_seekable(chunked_data) or
698699
not resp.need_retry()
699700
):
700701
return part, resp

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,13 @@ def find_version(*file_paths):
5454
'Topic :: Software Development :: Libraries :: Python Modules'
5555
],
5656
install_requires=[
57-
'requests'
57+
'requests',
58+
'futures; python_version == "2.7"'
5859
],
5960
extras_require={
6061
'dev': [
6162
'coverage<7.2',
62-
'flask8',
63+
'flake8',
6364
'pytest',
6465
'pytest-cov',
6566
'freezegun',

0 commit comments

Comments
 (0)