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

Commitd46ae36

Browse files
committed
Add decorator for new methods requiring app creds
1 parent13b1d46 commitd46ae36

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

‎github3/decorators.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,28 @@ def auth_wrapper(self, *args, **kwargs):
6767
returnauth_wrapper
6868

6969

70+
defrequires_app_credentials(func):
71+
"""Require client_id and client_secret to be associated.
72+
73+
This is used to note and enforce which methods require a client_id and
74+
client_secret to be used.
75+
76+
"""
77+
@wraps(func)
78+
defauth_wrapper(self,*args,**kwargs):
79+
ifhasattr(self,'_session')andself._session.params:
80+
returnfunc(self,*args,**kwargs)
81+
else:
82+
fromgithub3.modelsimportGitHubError
83+
# Mock a 401 response
84+
r=generate_fake_error_response(
85+
'{"message": "Requires username/password authentication"}'
86+
)
87+
raiseGitHubError(r)
88+
89+
returnauth_wrapper
90+
91+
7092
defgenerate_fake_error_response(msg,status_code=401,encoding='utf-8'):
7193
r=Response()
7294
r.status_code=status_code

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp