Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit4f8d901

Browse files
authored
Merge pull request#1252 from python-gitlab/feat/multipart-uploads
feat: support multipart uploads
2 parentsfd179d4 +2fa3004 commit4f8d901

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

‎gitlab/__init__.py‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@
2727
fromgitlab.constimport*# noqa
2828
fromgitlab.exceptionsimport*# noqa
2929
fromgitlabimportutils# noqa
30+
fromrequests_toolbelt.multipart.encoderimportMultipartEncoder
31+
3032

3133
__title__="python-gitlab"
32-
__version__="2.5.0"
34+
__version__="2.6.0"
3335
__author__="Gauvain Pocentek"
3436
__email__="gauvainpocentek@gmail.com"
3537
__license__="LGPL3"
@@ -496,9 +498,11 @@ def http_request(
496498

497499
# We need to deal with json vs. data when uploading files
498500
iffiles:
499-
data=post_data
500501
json=None
501-
delopts["headers"]["Content-type"]
502+
post_data["file"]=files.get("file")
503+
post_data["avatar"]=files.get("avatar")
504+
data=MultipartEncoder(post_data)
505+
opts["headers"]["Content-type"]=data.content_type
502506
else:
503507
json=post_data
504508
data=None
@@ -509,9 +513,7 @@ def http_request(
509513
# The Requests behavior is right but it seems that web servers don't
510514
# always agree with this decision (this is the case with a default
511515
# gitlab installation)
512-
req=requests.Request(
513-
verb,url,json=json,data=data,params=params,files=files,**opts
514-
)
516+
req=requests.Request(verb,url,json=json,data=data,params=params,**opts)
515517
prepped=self.session.prepare_request(req)
516518
prepped.url=utils.sanitized_url(prepped.url)
517519
settings=self.session.merge_environment_settings(

‎gitlab/v4/objects/__init__.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,7 +1615,7 @@ def import_group(self, file, path, name, parent_id=None, **kwargs):
16151615
Returns:
16161616
dict: A representation of the import status.
16171617
"""
1618-
files= {"file": ("file.tar.gz",file)}
1618+
files= {"file": ("file.tar.gz",file,"application/octet-stream")}
16191619
data= {"path":path,"name":name}
16201620
ifparent_idisnotNone:
16211621
data["parent_id"]=parent_id
@@ -5488,8 +5488,8 @@ def import_project(
54885488
Returns:
54895489
dict: A representation of the import status.
54905490
"""
5491-
files= {"file": ("file.tar.gz",file)}
5492-
data= {"path":path,"overwrite":overwrite}
5491+
files= {"file": ("file.tar.gz",file,"application/octet-stream")}
5492+
data= {"path":path,"overwrite":str(overwrite)}
54935493
ifoverride_params:
54945494
fork,vinoverride_params.items():
54955495
data["override_params[%s]"%k]=v

‎requirements.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
requests==2.24.0
2+
requests-toolbelt>=0.9.1

‎setup.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def get_version():
2626
license="LGPLv3",
2727
url="https://github.com/python-gitlab/python-gitlab",
2828
packages=find_packages(),
29-
install_requires=["requests>=2.22.0"],
29+
install_requires=["requests>=2.22.0","requests-toolbelt>=0.9.1"],
3030
python_requires=">=3.6.0",
3131
entry_points={"console_scripts": ["gitlab = gitlab.cli:main"]},
3232
classifiers=[

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp