Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
筑梦之路
bypy
提交
026fd003
B
bypy
项目概览
筑梦之路
/
bypy
与 Fork 源项目一致
从无法访问的项目Fork
通知
4
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
bypy
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
026fd003
编写于
6月 04, 2017
作者:
H
Hou Tianze
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Change all uploads to streaming
上级
6f52df9a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
37 addition
and
36 deletion
+37
-36
bypy/bypy.py
bypy/bypy.py
+36
-36
requirements.txt
requirements.txt
+1
-0
未找到文件。
bypy/bypy.py
浏览文件 @
026fd003
...
...
@@ -138,6 +138,10 @@ if Pool != None:
# global instance for non-member function to access
gbypyinst
=
None
pcsurl
=
const
.
PcsUrl
cpcsurl
=
const
.
CPcsUrl
dpcsurl
=
const
.
DPcsUrl
# This crap is here to avoid circular imports
# What a fantastic packing architecture Python has!
def
makemppr
(
pr
):
...
...
@@ -382,17 +386,9 @@ class ByPy(object):
mirror
=
mirror
.
lower
()
if
len
(
mirror
)
>
0
and
mirror
!=
const
.
PcsDomain
:
self
.
setpcsurl
(
mirror
)
else
:
if
selectmirror
:
self
.
__select_fastest_mirror
()
else
:
# use the default domain
global
pcsurl
global
cpcsurl
global
dpcsurl
pcsurl
=
const
.
PcsUrl
cpcsurl
=
const
.
CPcsUrl
dpcsurl
=
const
.
DPcsUrl
elif
selectmirror
:
self
.
__select_fastest_mirror
()
# else: already set in global
if
self
.
__checkssl
:
# sort of undocumented by requests
...
...
@@ -1348,16 +1344,38 @@ get information of the given path (dir / file) at Baidu Yun.
perr
(
"'{}' >>==> '{}' FAILED."
.
format
(
self
.
__current_file
,
args
))
return
const
.
EHashMismatch
# want to be proper? properness doesn't work
# there seems to be a bug at Baidu's handling of http text:
# Content-Disposition: ... filename=utf-8''yourfile.ext
# (pass '-ddd' to this program to verify this)
# when you specify a unicode file name, which will be encoded
# using the utf-8'' syntax
# so, we put a work-around here: we always call our file 'file'
# NOTE: an empty file name '' doesn't seem to work, so we
# need to give it a name at will, but empty one.
# apperantly, Baidu PCS doesn't use this file name for
# checking / verification, so we are probably safe here.
#files = { 'file' : (os.path.basename(self.__current_file), self.__current_slice) } )
#files = { 'file' : (os.path.basename(localpath), f) })
#files = { 'file' : ('file', f) })
def
__stream_upload
(
self
,
fo
,
pars
,
act
,
remotepath
,
url
=
cpcsurl
+
'file'
,
uploadfilename
=
'file'
):
# https://stackoverflow.com/a/35784072/404271
form
=
multipart
.
encoder
.
MultipartEncoder
({
'file'
:
(
uploadfilename
,
fo
,
'application/octet-stream'
)})
headers
=
{
"Content-Type"
:
form
.
content_type
}
return
self
.
__post
(
url
,
pars
,
act
,
remotepath
,
headers
=
headers
,
data
=
form
)
def
__upload_slice
(
self
,
remotepath
):
pars
=
{
'method'
:
'upload'
,
'type'
:
'tmpfile'
}
return
self
.
__post
(
cpcsurl
+
'file'
,
pars
,
self
.
__upload_slice_act
,
remotepath
,
# want to be proper? properness doesn't work (search this sentence for more occurence)
#files = { 'file' : (os.path.basename(self.__current_file), self.__current_slice) } )
files
=
{
'file'
:
(
'file'
,
self
.
__current_slice
)
}
)
return
self
.
__stream_upload
(
self
.
__current_slice
,
pars
,
self
.
__upload_slice_act
,
remotepath
)
def
__update_progress_entry
(
self
,
fullpath
):
progress
=
jsonload
(
const
.
ProgressPath
)
...
...
@@ -1526,26 +1544,8 @@ get information of the given path (dir / file) at Baidu Yun.
self
.
__add_isrev_param
(
ondup
,
pars
)
with
io
.
open
(
localpath
,
'rb'
)
as
f
:
# https://stackoverflow.com/a/35784072/404271
form
=
multipart
.
encoder
.
MultipartEncoder
({
'file'
:
(
'file'
,
f
,
'application/octet-stream'
)})
headers
=
{
"Content-Type"
:
form
.
content_type
}
return
self
.
__post
(
cpcsurl
+
'file'
,
pars
,
self
.
__upload_one_file_act
,
remotepath
,
# wants to be proper? properness doesn't work
# there seems to be a bug at Baidu's handling of http text:
# Content-Disposition: ... filename=utf-8''yourfile.ext
# (pass '-ddd' to this program to verify this)
# when you specify a unicode file name, which will be encoded
# using the utf-8'' syntax
# so, we put a work-around here: we always call our file 'file'
# NOTE: an empty file name '' doesn't seem to work, so we
# need to give it a name at will, but empty one.
# apperantly, Baidu PCS doesn't use this file name for
# checking / verification, so we are probably safe here.
#files = { 'file' : (os.path.basename(localpath), f) })
#files = { 'file' : ('file', f) })
headers
=
headers
,
data
=
form
)
return
self
.
__stream_upload
(
f
,
pars
,
self
.
__upload_one_file_act
,
remotepath
)
#TODO: upload empty directories as well?
def
__walk_upload
(
self
,
localpath
,
remotepath
,
ondup
,
walk
):
...
...
requirements.txt
浏览文件 @
026fd003
#requests[security]
requests
requests-toolbelt
multiprocess
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录