Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
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
108 changes: 54 additions & 54 deletions 108 Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions 8 changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## [2.1.11] - 2019-05-10
### Fixed
- Error -1 when uploading large files to Qiniu
- TypeError in py3k when uploading files to Qiniu using BytesIO / StringIO
- Upgraded urlib3 to 1.24.3 (CVE-2019-11324)
### Added
- email argument for User.login

## [2.1.10] - 2019-03-18
### Changed
- Upgrade Qiniu SDK
Expand Down
49 changes: 46 additions & 3 deletions 49 leancloud/file_.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
logger = logging.getLogger(__name__)


DEFAULT_TIMEOUT = 30

class File(object):
_class_name = '_File' # walks like a leancloud.Object

Expand All @@ -35,6 +37,7 @@ def __init__(self, name='', data=None, mime_type=None):
self._url = None
self._acl = None
self.current_user = leancloud.User.get_current()
self.timeout = 30
self._metadata = {
'owner': 'unknown'
}
Expand Down Expand Up @@ -74,11 +77,20 @@ def __init__(self, name='', data=None, mime_type=None):
chunk = data.read(4096)
if not chunk:
break
checksum.update(chunk)

try:
checksum.update(chunk)
except TypeError:
checksum.update(chunk.encode('utf-8'))

self._metadata['_checksum'] = checksum.hexdigest()
self._metadata['size'] = data.tell()

# 3.5MB, 1Mbps * 30s
# increase timeout
if self._metadata['size'] > 3750000:
self.timeout = self.timeout * int(self._metadata['size'] / 3750000)

data.seek(0, os.SEEK_SET)

self._source = data
Expand Down Expand Up @@ -164,10 +176,41 @@ def destroy(self):
if response.status_code != 200:
raise LeanCloudError(1, "the file is not sucessfully destroyed")

def _save_to_qiniu_internal_py3(self, token, key):
from qiniu.services.storage.uploader import crc32, _form_put, put_data

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_save_to_qiniu_internal_py3 看上去没用到 put_data,可以不用 import ?

from qiniu.config import _BLOCK_SIZE

final_data = ''
while True:
tmp_data = self._source.read(_BLOCK_SIZE)
if len(tmp_data) == 0:
break
elif len(final_data) == 0:
final_data = tmp_data
else:
final_data += tmp_data
else:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个 else 语句可以直接去掉?因为循环的条件是 while True

final_data = self._source.data

crc = crc32(final_data)
return _form_put(
token, key,
final_data, None,
self.mime_type, crc
)

def _save_to_qiniu(self, token, key):
import qiniu
self._source.seek(0)
ret, info = qiniu.put_data(token, key, self._source)

import qiniu
qiniu.set_default(connection_timeout=self.timeout)

if six.PY3:
# use patched put_data implementation for py3k
ret, info = self._save_to_qiniu_internal_py3(token, key)
else:
# use put_data implementation provided by qiniu-sdk
ret, info = qiniu.put_data(token, key, self._source)
self._source.seek(0)

if info.status_code != 200:
Expand Down
2 changes: 1 addition & 1 deletion 2 setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

setup(
name='leancloud',
version='2.1.10',
version='2.1.11',
description='LeanCloud Python SDK',
url='https://leancloud.cn/',
author='asaka',
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.