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

Commit087c288

Browse files
committed
Add requires_auth decorator to GitHubCore.
GitHubCore is imported in just about every module so it only makes sense toplace it there.
1 parent38efe43 commit087c288

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

‎github3/models.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,22 @@ def to_json(self):
100100
"""Return the json representing this object."""
101101
returnself._json_data
102102

103+
@staticmethod
104+
defrequires_auth(func):
105+
"""Decorator to note which class methods require authorization."""
106+
defauth_wrapper(self,*args,**kwargs):
107+
auth=False
108+
ifhasattr(self,'_session'):
109+
auth=self._session.author \
110+
self._session.headers['Authorization']
111+
112+
ifauth:
113+
returnfunc(self,*args,**kwargs)
114+
else:
115+
raiseError(type('Faux Request', (object, ),
116+
{'status_code':401,'message':'Requires authentication'}
117+
))
118+
103119

104120
classBaseComment(GitHubCore):
105121
"""The :class:`BaseComment <BaseComment>` object. A basic class for Gist,
@@ -150,13 +166,15 @@ def created_at(self):
150166
"""datetime object representing when the comment was created."""
151167
returnself._created
152168

169+
@GitHubCore.requires_auth
153170
defdelete(self):
154171
"""Delete this comment.
155172
156173
:returns: bool
157174
"""
158-
returnself._delete(self._api)
175+
returnself._boolean(self._delete(self._api),204,404)
159176

177+
@GitHubCore.requires_auth
160178
defedit(self,body):
161179
"""Edit this comment.
162180

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp