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

Commitbf2d944

Browse files
committed
feat(api,cli): make user agent configurable
1 parent48cb89b commitbf2d944

File tree

5 files changed

+31
-9
lines changed

5 files changed

+31
-9
lines changed

‎gitlab/__init__.py‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,20 @@
2424
importrequests.utils
2525

2626
importgitlab.config
27+
fromgitlab.__version__import (
28+
__author__,
29+
__copyright__,
30+
__email__,
31+
__license__,
32+
__title__,
33+
__version__,
34+
)
2735
fromgitlab.constimport*# noqa
2836
fromgitlab.exceptionsimport*# noqa
2937
fromgitlabimportutils# noqa
3038
fromrequests_toolbelt.multipart.encoderimportMultipartEncoder
3139

3240

33-
__title__="python-gitlab"
34-
__version__="2.6.0"
35-
__author__="Gauvain Pocentek"
36-
__email__="gauvainpocentek@gmail.com"
37-
__license__="LGPL3"
38-
__copyright__="Copyright 2013-2019 Gauvain Pocentek"
39-
4041
warnings.filterwarnings("default",category=DeprecationWarning,module="^gitlab")
4142

4243
REDIRECT_MSG= (
@@ -81,6 +82,7 @@ def __init__(
8182
per_page=None,
8283
pagination=None,
8384
order_by=None,
85+
user_agent=USER_AGENT,
8486
):
8587

8688
self._api_version=str(api_version)
@@ -90,7 +92,7 @@ def __init__(
9092
#: Timeout to use for requests to gitlab server
9193
self.timeout=timeout
9294
#: Headers that will be used in request to GitLab
93-
self.headers= {"User-Agent":"%s/%s"% (__title__,__version__)}
95+
self.headers= {"User-Agent":user_agent}
9496

9597
#: Whether SSL certificates should be validated
9698
self.ssl_verify=ssl_verify
@@ -204,6 +206,7 @@ def from_config(cls, gitlab_id=None, config_files=None):
204206
per_page=config.per_page,
205207
pagination=config.pagination,
206208
order_by=config.order_by,
209+
user_agent=config.user_agent,
207210
)
208211

209212
defauth(self):

‎gitlab/__version__.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
__author__="Gauvain Pocentek, python-gitlab team"
2+
__copyright__="Copyright 2013-2019 Gauvain Pocentek, 2019-2021 python-gitlab team"
3+
__email__="gauvainpocentek@gmail.com"
4+
__license__="LGPL3"
5+
__title__="python-gitlab"
6+
__version__="2.6.0"

‎gitlab/config.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
importos
1919
importconfigparser
2020

21+
fromgitlab.constimportUSER_AGENT
22+
2123

2224
def_env_config():
2325
if"PYTHON_GITLAB_CFG"inos.environ:
@@ -177,3 +179,9 @@ def __init__(self, gitlab_id=None, config_files=None):
177179
self.order_by=self._config.get(self.gitlab_id,"order_by")
178180
exceptException:
179181
pass
182+
183+
self.user_agent=USER_AGENT
184+
try:
185+
self.user_agent=self._config.get("global","user_agent")
186+
exceptException:
187+
pass

‎gitlab/const.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
# You should have received a copy of the GNU Lesser General Public License
1616
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1717

18+
fromgitlab.__version__import__title__,__version__
19+
20+
1821
NO_ACCESS=0
1922
MINIMAL_ACCESS=5
2023
GUEST_ACCESS=10
@@ -51,3 +54,5 @@
5154

5255
# specific project scope
5356
SEARCH_SCOPE_PROJECT_NOTES="notes"
57+
58+
USER_AGENT="{}/{}".format(__title__,__version__)

‎setup.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
defget_version():
9-
withopen("gitlab/__init__.py")asf:
9+
withopen("gitlab/__version__.py")asf:
1010
forlineinf:
1111
ifline.startswith("__version__"):
1212
returneval(line.split("=")[-1])

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp