Mercurial > repos > bcclaywell > argo_navis
comparison venv/lib/python2.7/site-packages/github/Gist.py @ 0:d67268158946 draft
planemo upload commit a3f181f5f126803c654b3a66dd4e83a48f7e203b
| author | bcclaywell |
|---|---|
| date | Mon, 12 Oct 2015 17:43:33 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:d67268158946 |
|---|---|
| 1 # -*- coding: utf-8 -*- | |
| 2 | |
| 3 # ########################## Copyrights and license ############################ | |
| 4 # # | |
| 5 # Copyright 2012 Steve English <steve.english@navetas.com> # | |
| 6 # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # | |
| 7 # Copyright 2012 Zearin <zearin@gonk.net> # | |
| 8 # Copyright 2013 AKFish <akfish@gmail.com> # | |
| 9 # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # | |
| 10 # # | |
| 11 # This file is part of PyGithub. http://jacquev6.github.com/PyGithub/ # | |
| 12 # # | |
| 13 # PyGithub is free software: you can redistribute it and/or modify it under # | |
| 14 # the terms of the GNU Lesser General Public License as published by the Free # | |
| 15 # Software Foundation, either version 3 of the License, or (at your option) # | |
| 16 # any later version. # | |
| 17 # # | |
| 18 # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # | |
| 19 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # | |
| 20 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # | |
| 21 # details. # | |
| 22 # # | |
| 23 # You should have received a copy of the GNU Lesser General Public License # | |
| 24 # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # | |
| 25 # # | |
| 26 # ############################################################################## | |
| 27 | |
| 28 import github.GithubObject | |
| 29 import github.PaginatedList | |
| 30 | |
| 31 import github.GistComment | |
| 32 import github.NamedUser | |
| 33 import github.GistFile | |
| 34 import github.GistHistoryState | |
| 35 | |
| 36 | |
| 37 class Gist(github.GithubObject.CompletableGithubObject): | |
| 38 """ | |
| 39 This class represents Gists as returned for example by http://developer.github.com/v3/todo | |
| 40 """ | |
| 41 | |
| 42 @property | |
| 43 def comments(self): | |
| 44 """ | |
| 45 :type: integer | |
| 46 """ | |
| 47 self._completeIfNotSet(self._comments) | |
| 48 return self._comments.value | |
| 49 | |
| 50 @property | |
| 51 def comments_url(self): | |
| 52 """ | |
| 53 :type: string | |
| 54 """ | |
| 55 self._completeIfNotSet(self._comments_url) | |
| 56 return self._comments_url.value | |
| 57 | |
| 58 @property | |
| 59 def commits_url(self): | |
| 60 """ | |
| 61 :type: string | |
| 62 """ | |
| 63 self._completeIfNotSet(self._commits_url) | |
| 64 return self._commits_url.value | |
| 65 | |
| 66 @property | |
| 67 def created_at(self): | |
| 68 """ | |
| 69 :type: datetime.datetime | |
| 70 """ | |
| 71 self._completeIfNotSet(self._created_at) | |
| 72 return self._created_at.value | |
| 73 | |
| 74 @property | |
| 75 def description(self): | |
| 76 """ | |
| 77 :type: string | |
| 78 """ | |
| 79 self._completeIfNotSet(self._description) | |
| 80 return self._description.value | |
| 81 | |
| 82 @property | |
| 83 def files(self): | |
| 84 """ | |
| 85 :type: dict of string to :class:`github.GistFile.GistFile` | |
| 86 """ | |
| 87 self._completeIfNotSet(self._files) | |
| 88 return self._files.value | |
| 89 | |
| 90 @property | |
| 91 def fork_of(self): | |
| 92 """ | |
| 93 :type: :class:`github.Gist.Gist` | |
| 94 """ | |
| 95 self._completeIfNotSet(self._fork_of) | |
| 96 return self._fork_of.value | |
| 97 | |
| 98 @property | |
| 99 def forks(self): | |
| 100 """ | |
| 101 :type: list of :class:`github.Gist.Gist` | |
| 102 """ | |
| 103 self._completeIfNotSet(self._forks) | |
| 104 return self._forks.value | |
| 105 | |
| 106 @property | |
| 107 def forks_url(self): | |
| 108 """ | |
| 109 :type: string | |
| 110 """ | |
| 111 self._completeIfNotSet(self._forks_url) | |
| 112 return self._forks_url.value | |
| 113 | |
| 114 @property | |
| 115 def git_pull_url(self): | |
| 116 """ | |
| 117 :type: string | |
| 118 """ | |
| 119 self._completeIfNotSet(self._git_pull_url) | |
| 120 return self._git_pull_url.value | |
| 121 | |
| 122 @property | |
| 123 def git_push_url(self): | |
| 124 """ | |
| 125 :type: string | |
| 126 """ | |
| 127 self._completeIfNotSet(self._git_push_url) | |
| 128 return self._git_push_url.value | |
| 129 | |
| 130 @property | |
| 131 def history(self): | |
| 132 """ | |
| 133 :type: list of :class:`github.GistHistoryState.GistHistoryState` | |
| 134 """ | |
| 135 self._completeIfNotSet(self._history) | |
| 136 return self._history.value | |
| 137 | |
| 138 @property | |
| 139 def html_url(self): | |
| 140 """ | |
| 141 :type: string | |
| 142 """ | |
| 143 self._completeIfNotSet(self._html_url) | |
| 144 return self._html_url.value | |
| 145 | |
| 146 @property | |
| 147 def id(self): | |
| 148 """ | |
| 149 :type: string | |
| 150 """ | |
| 151 self._completeIfNotSet(self._id) | |
| 152 return self._id.value | |
| 153 | |
| 154 @property | |
| 155 def owner(self): | |
| 156 """ | |
| 157 :type: :class:`github.NamedUser.NamedUser` | |
| 158 """ | |
| 159 self._completeIfNotSet(self._owner) | |
| 160 return self._owner.value | |
| 161 | |
| 162 @property | |
| 163 def public(self): | |
| 164 """ | |
| 165 :type: bool | |
| 166 """ | |
| 167 self._completeIfNotSet(self._public) | |
| 168 return self._public.value | |
| 169 | |
| 170 @property | |
| 171 def updated_at(self): | |
| 172 """ | |
| 173 :type: datetime.datetime | |
| 174 """ | |
| 175 self._completeIfNotSet(self._updated_at) | |
| 176 return self._updated_at.value | |
| 177 | |
| 178 @property | |
| 179 def url(self): | |
| 180 """ | |
| 181 :type: string | |
| 182 """ | |
| 183 self._completeIfNotSet(self._url) | |
| 184 return self._url.value | |
| 185 | |
| 186 @property | |
| 187 def user(self): | |
| 188 """ | |
| 189 :type: :class:`github.NamedUser.NamedUser` | |
| 190 """ | |
| 191 self._completeIfNotSet(self._user) | |
| 192 return self._user.value | |
| 193 | |
| 194 def create_comment(self, body): | |
| 195 """ | |
| 196 :calls: `POST /gists/:gist_id/comments <http://developer.github.com/v3/gists/comments>`_ | |
| 197 :param body: string | |
| 198 :rtype: :class:`github.GistComment.GistComment` | |
| 199 """ | |
| 200 assert isinstance(body, (str, unicode)), body | |
| 201 post_parameters = { | |
| 202 "body": body, | |
| 203 } | |
| 204 headers, data = self._requester.requestJsonAndCheck( | |
| 205 "POST", | |
| 206 self.url + "/comments", | |
| 207 input=post_parameters | |
| 208 ) | |
| 209 return github.GistComment.GistComment(self._requester, headers, data, completed=True) | |
| 210 | |
| 211 def create_fork(self): | |
| 212 """ | |
| 213 :calls: `POST /gists/:id/forks <http://developer.github.com/v3/gists>`_ | |
| 214 :rtype: :class:`github.Gist.Gist` | |
| 215 """ | |
| 216 headers, data = self._requester.requestJsonAndCheck( | |
| 217 "POST", | |
| 218 self.url + "/forks" | |
| 219 ) | |
| 220 return Gist(self._requester, headers, data, completed=True) | |
| 221 | |
| 222 def delete(self): | |
| 223 """ | |
| 224 :calls: `DELETE /gists/:id <http://developer.github.com/v3/gists>`_ | |
| 225 :rtype: None | |
| 226 """ | |
| 227 headers, data = self._requester.requestJsonAndCheck( | |
| 228 "DELETE", | |
| 229 self.url | |
| 230 ) | |
| 231 | |
| 232 def edit(self, description=github.GithubObject.NotSet, files=github.GithubObject.NotSet): | |
| 233 """ | |
| 234 :calls: `PATCH /gists/:id <http://developer.github.com/v3/gists>`_ | |
| 235 :param description: string | |
| 236 :param files: dict of string to :class:`github.InputFileContent.InputFileContent` | |
| 237 :rtype: None | |
| 238 """ | |
| 239 assert description is github.GithubObject.NotSet or isinstance(description, (str, unicode)), description | |
| 240 assert files is github.GithubObject.NotSet or all(element is None or isinstance(element, github.InputFileContent) for element in files.itervalues()), files | |
| 241 post_parameters = dict() | |
| 242 if description is not github.GithubObject.NotSet: | |
| 243 post_parameters["description"] = description | |
| 244 if files is not github.GithubObject.NotSet: | |
| 245 post_parameters["files"] = dict((key, None if value is None else value._identity) for key, value in files.iteritems()) | |
| 246 headers, data = self._requester.requestJsonAndCheck( | |
| 247 "PATCH", | |
| 248 self.url, | |
| 249 input=post_parameters | |
| 250 ) | |
| 251 self._useAttributes(data) | |
| 252 | |
| 253 def get_comment(self, id): | |
| 254 """ | |
| 255 :calls: `GET /gists/:gist_id/comments/:id <http://developer.github.com/v3/gists/comments>`_ | |
| 256 :param id: integer | |
| 257 :rtype: :class:`github.GistComment.GistComment` | |
| 258 """ | |
| 259 assert isinstance(id, (int, long)), id | |
| 260 headers, data = self._requester.requestJsonAndCheck( | |
| 261 "GET", | |
| 262 self.url + "/comments/" + str(id) | |
| 263 ) | |
| 264 return github.GistComment.GistComment(self._requester, headers, data, completed=True) | |
| 265 | |
| 266 def get_comments(self): | |
| 267 """ | |
| 268 :calls: `GET /gists/:gist_id/comments <http://developer.github.com/v3/gists/comments>`_ | |
| 269 :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.GistComment.GistComment` | |
| 270 """ | |
| 271 return github.PaginatedList.PaginatedList( | |
| 272 github.GistComment.GistComment, | |
| 273 self._requester, | |
| 274 self.url + "/comments", | |
| 275 None | |
| 276 ) | |
| 277 | |
| 278 def is_starred(self): | |
| 279 """ | |
| 280 :calls: `GET /gists/:id/star <http://developer.github.com/v3/gists>`_ | |
| 281 :rtype: bool | |
| 282 """ | |
| 283 status, headers, data = self._requester.requestJson( | |
| 284 "GET", | |
| 285 self.url + "/star" | |
| 286 ) | |
| 287 return status == 204 | |
| 288 | |
| 289 def reset_starred(self): | |
| 290 """ | |
| 291 :calls: `DELETE /gists/:id/star <http://developer.github.com/v3/gists>`_ | |
| 292 :rtype: None | |
| 293 """ | |
| 294 headers, data = self._requester.requestJsonAndCheck( | |
| 295 "DELETE", | |
| 296 self.url + "/star" | |
| 297 ) | |
| 298 | |
| 299 def set_starred(self): | |
| 300 """ | |
| 301 :calls: `PUT /gists/:id/star <http://developer.github.com/v3/gists>`_ | |
| 302 :rtype: None | |
| 303 """ | |
| 304 headers, data = self._requester.requestJsonAndCheck( | |
| 305 "PUT", | |
| 306 self.url + "/star" | |
| 307 ) | |
| 308 | |
| 309 def _initAttributes(self): | |
| 310 self._comments = github.GithubObject.NotSet | |
| 311 self._comments_url = github.GithubObject.NotSet | |
| 312 self._commits_url = github.GithubObject.NotSet | |
| 313 self._created_at = github.GithubObject.NotSet | |
| 314 self._description = github.GithubObject.NotSet | |
| 315 self._files = github.GithubObject.NotSet | |
| 316 self._fork_of = github.GithubObject.NotSet | |
| 317 self._forks = github.GithubObject.NotSet | |
| 318 self._forks_url = github.GithubObject.NotSet | |
| 319 self._git_pull_url = github.GithubObject.NotSet | |
| 320 self._git_push_url = github.GithubObject.NotSet | |
| 321 self._history = github.GithubObject.NotSet | |
| 322 self._html_url = github.GithubObject.NotSet | |
| 323 self._id = github.GithubObject.NotSet | |
| 324 self._owner = github.GithubObject.NotSet | |
| 325 self._public = github.GithubObject.NotSet | |
| 326 self._updated_at = github.GithubObject.NotSet | |
| 327 self._url = github.GithubObject.NotSet | |
| 328 self._user = github.GithubObject.NotSet | |
| 329 | |
| 330 def _useAttributes(self, attributes): | |
| 331 if "comments" in attributes: # pragma no branch | |
| 332 self._comments = self._makeIntAttribute(attributes["comments"]) | |
| 333 if "comments_url" in attributes: # pragma no branch | |
| 334 self._comments_url = self._makeStringAttribute(attributes["comments_url"]) | |
| 335 if "commits_url" in attributes: # pragma no branch | |
| 336 self._commits_url = self._makeStringAttribute(attributes["commits_url"]) | |
| 337 if "created_at" in attributes: # pragma no branch | |
| 338 self._created_at = self._makeDatetimeAttribute(attributes["created_at"]) | |
| 339 if "description" in attributes: # pragma no branch | |
| 340 self._description = self._makeStringAttribute(attributes["description"]) | |
| 341 if "files" in attributes: # pragma no branch | |
| 342 self._files = self._makeDictOfStringsToClassesAttribute(github.GistFile.GistFile, attributes["files"]) | |
| 343 if "fork_of" in attributes: # pragma no branch | |
| 344 self._fork_of = self._makeClassAttribute(Gist, attributes["fork_of"]) | |
| 345 if "forks" in attributes: # pragma no branch | |
| 346 self._forks = self._makeListOfClassesAttribute(Gist, attributes["forks"]) | |
| 347 if "forks_url" in attributes: # pragma no branch | |
| 348 self._forks_url = self._makeStringAttribute(attributes["forks_url"]) | |
| 349 if "git_pull_url" in attributes: # pragma no branch | |
| 350 self._git_pull_url = self._makeStringAttribute(attributes["git_pull_url"]) | |
| 351 if "git_push_url" in attributes: # pragma no branch | |
| 352 self._git_push_url = self._makeStringAttribute(attributes["git_push_url"]) | |
| 353 if "history" in attributes: # pragma no branch | |
| 354 self._history = self._makeListOfClassesAttribute(github.GistHistoryState.GistHistoryState, attributes["history"]) | |
| 355 if "html_url" in attributes: # pragma no branch | |
| 356 self._html_url = self._makeStringAttribute(attributes["html_url"]) | |
| 357 if "id" in attributes: # pragma no branch | |
| 358 self._id = self._makeStringAttribute(attributes["id"]) | |
| 359 if "owner" in attributes: # pragma no branch | |
| 360 self._owner = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["owner"]) | |
| 361 if "public" in attributes: # pragma no branch | |
| 362 self._public = self._makeBoolAttribute(attributes["public"]) | |
| 363 if "updated_at" in attributes: # pragma no branch | |
| 364 self._updated_at = self._makeDatetimeAttribute(attributes["updated_at"]) | |
| 365 if "url" in attributes: # pragma no branch | |
| 366 self._url = self._makeStringAttribute(attributes["url"]) | |
| 367 if "user" in attributes: # pragma no branch | |
| 368 self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["user"]) |
