Mercurial > repos > bcclaywell > argo_navis
comparison venv/lib/python2.7/site-packages/github/ContentFile.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 Vincent Jacques <vincent@vincent-jacques.net> # | |
| 6 # Copyright 2012 Zearin <zearin@gonk.net> # | |
| 7 # Copyright 2013 AKFish <akfish@gmail.com> # | |
| 8 # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # | |
| 9 # # | |
| 10 # This file is part of PyGithub. http://jacquev6.github.com/PyGithub/ # | |
| 11 # # | |
| 12 # PyGithub is free software: you can redistribute it and/or modify it under # | |
| 13 # the terms of the GNU Lesser General Public License as published by the Free # | |
| 14 # Software Foundation, either version 3 of the License, or (at your option) # | |
| 15 # any later version. # | |
| 16 # # | |
| 17 # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # | |
| 18 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # | |
| 19 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # | |
| 20 # details. # | |
| 21 # # | |
| 22 # You should have received a copy of the GNU Lesser General Public License # | |
| 23 # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # | |
| 24 # # | |
| 25 # ############################################################################## | |
| 26 | |
| 27 import base64 | |
| 28 import sys | |
| 29 | |
| 30 import github.GithubObject | |
| 31 import github.Repository | |
| 32 | |
| 33 | |
| 34 atLeastPython3 = sys.hexversion >= 0x03000000 | |
| 35 | |
| 36 | |
| 37 class ContentFile(github.GithubObject.CompletableGithubObject): | |
| 38 """ | |
| 39 This class represents ContentFiles as returned for example by http://developer.github.com/v3/todo | |
| 40 """ | |
| 41 | |
| 42 @property | |
| 43 def content(self): | |
| 44 """ | |
| 45 :type: string | |
| 46 """ | |
| 47 self._completeIfNotSet(self._content) | |
| 48 return self._content.value | |
| 49 | |
| 50 @property | |
| 51 def decoded_content(self): | |
| 52 assert self.encoding == "base64", "unsupported encoding: %s" % self.encoding | |
| 53 if atLeastPython3: | |
| 54 content = bytearray(self.content, "utf-8") # pragma no cover (covered by tests with Python 3.2) | |
| 55 else: | |
| 56 content = self.content | |
| 57 return base64.b64decode(content) | |
| 58 | |
| 59 @property | |
| 60 def encoding(self): | |
| 61 """ | |
| 62 :type: string | |
| 63 """ | |
| 64 self._completeIfNotSet(self._encoding) | |
| 65 return self._encoding.value | |
| 66 | |
| 67 @property | |
| 68 def git_url(self): | |
| 69 """ | |
| 70 :type: string | |
| 71 """ | |
| 72 self._completeIfNotSet(self._git_url) | |
| 73 return self._git_url.value | |
| 74 | |
| 75 @property | |
| 76 def html_url(self): | |
| 77 """ | |
| 78 :type: string | |
| 79 """ | |
| 80 self._completeIfNotSet(self._html_url) | |
| 81 return self._html_url.value | |
| 82 | |
| 83 @property | |
| 84 def name(self): | |
| 85 """ | |
| 86 :type: string | |
| 87 """ | |
| 88 self._completeIfNotSet(self._name) | |
| 89 return self._name.value | |
| 90 | |
| 91 @property | |
| 92 def path(self): | |
| 93 """ | |
| 94 :type: string | |
| 95 """ | |
| 96 self._completeIfNotSet(self._path) | |
| 97 return self._path.value | |
| 98 | |
| 99 @property | |
| 100 def repository(self): | |
| 101 """ | |
| 102 :type: :class:`github.Repository.Repository` | |
| 103 """ | |
| 104 if self._repository is github.GithubObject.NotSet: | |
| 105 # The repository was not set automatically, so it must be looked up by url. | |
| 106 repo_url = "/".join(self.url.split("/")[:6]) # pragma no cover (Should be covered) | |
| 107 self._repository = github.GithubObject._ValuedAttribute(github.Repository.Repository(self._requester, self._headers, {'url': repo_url}, completed=False)) # pragma no cover (Should be covered) | |
| 108 return self._repository.value | |
| 109 | |
| 110 @property | |
| 111 def sha(self): | |
| 112 """ | |
| 113 :type: string | |
| 114 """ | |
| 115 self._completeIfNotSet(self._sha) | |
| 116 return self._sha.value | |
| 117 | |
| 118 @property | |
| 119 def size(self): | |
| 120 """ | |
| 121 :type: integer | |
| 122 """ | |
| 123 self._completeIfNotSet(self._size) | |
| 124 return self._size.value | |
| 125 | |
| 126 @property | |
| 127 def type(self): | |
| 128 """ | |
| 129 :type: string | |
| 130 """ | |
| 131 self._completeIfNotSet(self._type) | |
| 132 return self._type.value | |
| 133 | |
| 134 @property | |
| 135 def url(self): | |
| 136 """ | |
| 137 :type: string | |
| 138 """ | |
| 139 self._completeIfNotSet(self._url) | |
| 140 return self._url.value | |
| 141 | |
| 142 def _initAttributes(self): | |
| 143 self._content = github.GithubObject.NotSet | |
| 144 self._encoding = github.GithubObject.NotSet | |
| 145 self._git_url = github.GithubObject.NotSet | |
| 146 self._html_url = github.GithubObject.NotSet | |
| 147 self._name = github.GithubObject.NotSet | |
| 148 self._path = github.GithubObject.NotSet | |
| 149 self._repository = github.GithubObject.NotSet | |
| 150 self._sha = github.GithubObject.NotSet | |
| 151 self._size = github.GithubObject.NotSet | |
| 152 self._type = github.GithubObject.NotSet | |
| 153 | |
| 154 def _useAttributes(self, attributes): | |
| 155 if "content" in attributes: # pragma no branch | |
| 156 self._content = self._makeStringAttribute(attributes["content"]) | |
| 157 if "encoding" in attributes: # pragma no branch | |
| 158 self._encoding = self._makeStringAttribute(attributes["encoding"]) | |
| 159 if "git_url" in attributes: # pragma no branch | |
| 160 self._git_url = self._makeStringAttribute(attributes["git_url"]) | |
| 161 if "html_url" in attributes: # pragma no branch | |
| 162 self._html_url = self._makeStringAttribute(attributes["html_url"]) | |
| 163 if "name" in attributes: # pragma no branch | |
| 164 self._name = self._makeStringAttribute(attributes["name"]) | |
| 165 if "path" in attributes: # pragma no branch | |
| 166 self._path = self._makeStringAttribute(attributes["path"]) | |
| 167 if "repository" in attributes: # pragma no branch | |
| 168 self._repository = self._makeClassAttribute(github.Repository.Repository, attributes["repository"]) | |
| 169 if "sha" in attributes: # pragma no branch | |
| 170 self._sha = self._makeStringAttribute(attributes["sha"]) | |
| 171 if "size" in attributes: # pragma no branch | |
| 172 self._size = self._makeIntAttribute(attributes["size"]) | |
| 173 if "type" in attributes: # pragma no branch | |
| 174 self._type = self._makeStringAttribute(attributes["type"]) | |
| 175 if "url" in attributes: # pragma no branch | |
| 176 self._url = self._makeStringAttribute(attributes["url"]) |
