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

Commit9199f6a

Browse files
committed
Merge pull requestsigmavirus24#33 from seveas/requires_basic_auth
Better error messages for authorization methods
2 parentsbfa988e +e3e6c38 commit9199f6a

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

‎github3/auths.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
77
"""
88

9+
fromgithub3.decoratorsimportrequires_basic_auth
910
fromgithub3.modelsimportGitHubCore
1011
fromjsonimportdumps
1112

@@ -44,10 +45,12 @@ def __repr__(self):
4445
def_update_(self,auth):
4546
self.__init__(auth,self._session)
4647

48+
@requires_basic_auth
4749
defdelete(self):
4850
"""delete this authorization"""
4951
returnself._boolean(self._delete(self._api),204,404)
5052

53+
@requires_basic_auth
5154
defupdate(self,scopes=[],add_scopes=[],rm_scopes=[],note='',
5255
note_url=''):
5356
"""Update this authorization.

‎github3/decorators.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,33 @@ def auth_wrapper(self, *args, **kwargs):
5050
r.raw=StringIO('{"message": "Requires authentication"}'.encode())
5151
raiseGitHubError(r)
5252
returnauth_wrapper
53+
54+
defrequires_basic_auth(func):
55+
"""Decorator to note which object methods require username/password
56+
authorization and won't work with token based authorization.
57+
58+
.. note::
59+
This decorator causes the wrapped methods to lose their proper
60+
signature. Please refer to the documentation for each of those.
61+
"""
62+
#note = """.. note::
63+
#The signature of this function may not appear correctly in
64+
#documentation. Please adhere to the defined parameters and their
65+
#types.
66+
#"""
67+
## Append the above note to each function this is applied to
68+
#func.__doc__ = '\n\n'.join([func.__doc__, note])
69+
70+
@wraps(func)
71+
defauth_wrapper(self,*args,**kwargs):
72+
ifhasattr(self,'_session')andself._session.auth:
73+
returnfunc(self,*args,**kwargs)
74+
else:
75+
fromgithub3.modelsimportGitHubError
76+
# Mock a 401 response
77+
r=Response()
78+
r.status_code=401
79+
r.encoding='utf-8'
80+
r.raw=StringIO('{"message": "Requires username/password authentication"}'.encode())
81+
raiseGitHubError(r)
82+
returnauth_wrapper

‎github3/github.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
fromgithub3.orgsimportOrganization
1818
fromgithub3.reposimportRepository
1919
fromgithub3.usersimportUser,Key
20-
fromgithub3.decoratorsimportrequires_auth
20+
fromgithub3.decoratorsimportrequires_auth,requires_basic_auth
2121

2222

2323
classGitHub(GitHubCore):
@@ -40,7 +40,7 @@ def _iter_follow(self, which, number):
4040
url=self._build_url('user',which)
4141
returnself._iter(number,url,User)
4242

43-
@requires_auth
43+
@requires_basic_auth
4444
defauthorization(self,id_num):
4545
"""Get information about authorization ``id``.
4646
@@ -320,7 +320,7 @@ def issue(self, owner, repository, number):
320320
returnrepo.issue(number)
321321
returnNone
322322

323-
@requires_auth
323+
@requires_basic_auth
324324
deflist_authorizations(self):
325325
"""List authorizations for the authenticated user.
326326
@@ -330,7 +330,7 @@ def list_authorizations(self):
330330
json=self._json(self._get(url),200)
331331
return [Authorization(a,self)forainjson]
332332

333-
@requires_auth
333+
@requires_basic_auth
334334
defiter_authorizations(self,number=-1):
335335
"""Iterate over authorizations for the authenticated user.
336336

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp