/ github / Download.py
Download.py
  1  ############################ Copyrights and license ############################
  2  #                                                                              #
  3  # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net>                 #
  4  # Copyright 2012 Zearin <zearin@gonk.net>                                      #
  5  # Copyright 2013 AKFish <akfish@gmail.com>                                     #
  6  # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net>                 #
  7  # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net>                 #
  8  # Copyright 2016 Jannis Gebauer <ja.geb@me.com>                                #
  9  # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com>          #
 10  # Copyright 2018 Wan Liuyang <tsfdye@gmail.com>                                #
 11  # Copyright 2018 sfdye <tsfdye@gmail.com>                                      #
 12  #                                                                              #
 13  # This file is part of PyGithub.                                               #
 14  # http://pygithub.readthedocs.io/                                              #
 15  #                                                                              #
 16  # PyGithub is free software: you can redistribute it and/or modify it under    #
 17  # the terms of the GNU Lesser General Public License as published by the Free  #
 18  # Software Foundation, either version 3 of the License, or (at your option)    #
 19  # any later version.                                                           #
 20  #                                                                              #
 21  # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY  #
 22  # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS    #
 23  # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
 24  # details.                                                                     #
 25  #                                                                              #
 26  # You should have received a copy of the GNU Lesser General Public License     #
 27  # along with PyGithub. If not, see <http://www.gnu.org/licenses/>.             #
 28  #                                                                              #
 29  ################################################################################
 30  from __future__ import annotations
 31  
 32  from datetime import datetime
 33  from typing import Any
 34  
 35  from github.GithubObject import Attribute, CompletableGithubObject, NotSet
 36  
 37  
 38  class Download(CompletableGithubObject):
 39      """
 40      This class represents Downloads. The reference can be found here https://docs.github.com/en/rest/reference/repos
 41      """
 42  
 43      def _initAttributes(self) -> None:
 44          self._accesskeyid: Attribute[str] = NotSet
 45          self._acl: Attribute[str] = NotSet
 46          self._bucket: Attribute[str] = NotSet
 47          self._content_type: Attribute[str] = NotSet
 48          self._created_at: Attribute[datetime] = NotSet
 49          self._description: Attribute[str] = NotSet
 50          self._download_count: Attribute[int] = NotSet
 51          self._expirationdate: Attribute[datetime] = NotSet
 52          self._html_url: Attribute[str] = NotSet
 53          self._id: Attribute[int] = NotSet
 54          self._mime_type: Attribute[str] = NotSet
 55          self._name: Attribute[str] = NotSet
 56          self._path: Attribute[str] = NotSet
 57          self._policy: Attribute[str] = NotSet
 58          self._prefix: Attribute[str] = NotSet
 59          self._redirect: Attribute[bool] = NotSet
 60          self._s3_url: Attribute[str] = NotSet
 61          self._signature: Attribute[str] = NotSet
 62          self._size: Attribute[int] = NotSet
 63          self._url: Attribute[str] = NotSet
 64  
 65      def __repr__(self) -> str:
 66          return self.get__repr__({"id": self._id.value})
 67  
 68      @property
 69      def accesskeyid(self) -> str:
 70          self._completeIfNotSet(self._accesskeyid)
 71          return self._accesskeyid.value
 72  
 73      @property
 74      def acl(self) -> str:
 75          self._completeIfNotSet(self._acl)
 76          return self._acl.value
 77  
 78      @property
 79      def bucket(self) -> str:
 80          self._completeIfNotSet(self._bucket)
 81          return self._bucket.value
 82  
 83      @property
 84      def content_type(self) -> str:
 85          self._completeIfNotSet(self._content_type)
 86          return self._content_type.value
 87  
 88      @property
 89      def created_at(self) -> datetime:
 90          self._completeIfNotSet(self._created_at)
 91          return self._created_at.value
 92  
 93      @property
 94      def description(self) -> str:
 95          self._completeIfNotSet(self._description)
 96          return self._description.value
 97  
 98      @property
 99      def download_count(self) -> int:
100          self._completeIfNotSet(self._download_count)
101          return self._download_count.value
102  
103      @property
104      def expirationdate(self) -> datetime:
105          self._completeIfNotSet(self._expirationdate)
106          return self._expirationdate.value
107  
108      @property
109      def html_url(self) -> str:
110          self._completeIfNotSet(self._html_url)
111          return self._html_url.value
112  
113      @property
114      def id(self) -> int:
115          self._completeIfNotSet(self._id)
116          return self._id.value
117  
118      @property
119      def mime_type(self) -> str:
120          self._completeIfNotSet(self._mime_type)
121          return self._mime_type.value
122  
123      @property
124      def name(self) -> str:
125          self._completeIfNotSet(self._name)
126          return self._name.value
127  
128      @property
129      def path(self) -> str:
130          self._completeIfNotSet(self._path)
131          return self._path.value
132  
133      @property
134      def policy(self) -> str:
135          self._completeIfNotSet(self._policy)
136          return self._policy.value
137  
138      @property
139      def prefix(self) -> str:
140          self._completeIfNotSet(self._prefix)
141          return self._prefix.value
142  
143      @property
144      def redirect(self) -> bool:
145          self._completeIfNotSet(self._redirect)
146          return self._redirect.value
147  
148      @property
149      def s3_url(self) -> str:
150          self._completeIfNotSet(self._s3_url)
151          return self._s3_url.value
152  
153      @property
154      def signature(self) -> str:
155          self._completeIfNotSet(self._signature)
156          return self._signature.value
157  
158      @property
159      def size(self) -> int:
160          self._completeIfNotSet(self._size)
161          return self._size.value
162  
163      @property
164      def url(self) -> str:
165          self._completeIfNotSet(self._url)
166          return self._url.value
167  
168      def delete(self) -> None:
169          """
170          :calls: `DELETE /repos/{owner}/{repo}/downloads/{id} <https://docs.github.com/en/rest/reference/repos>`_
171          """
172          headers, data = self._requester.requestJsonAndCheck("DELETE", self.url)
173  
174      def _useAttributes(self, attributes: dict[str, Any]) -> None:
175          if "accesskeyid" in attributes:  # pragma no branch
176              self._accesskeyid = self._makeStringAttribute(
177                  attributes["accesskeyid"]
178              )  # pragma no cover (was covered only by create_download, which has been removed)
179          if "acl" in attributes:  # pragma no branch
180              self._acl = self._makeStringAttribute(
181                  attributes["acl"]
182              )  # pragma no cover (was covered only by create_download, which has been removed)
183          if "bucket" in attributes:  # pragma no branch
184              self._bucket = self._makeStringAttribute(
185                  attributes["bucket"]
186              )  # pragma no cover (was covered only by create_download, which has been removed)
187          if "content_type" in attributes:  # pragma no branch
188              self._content_type = self._makeStringAttribute(attributes["content_type"])
189          if "created_at" in attributes:  # pragma no branch
190              self._created_at = self._makeDatetimeAttribute(attributes["created_at"])
191          if "description" in attributes:  # pragma no branch
192              self._description = self._makeStringAttribute(attributes["description"])
193          if "download_count" in attributes:  # pragma no branch
194              self._download_count = self._makeIntAttribute(attributes["download_count"])
195          if "expirationdate" in attributes:  # pragma no branch
196              self._expirationdate = self._makeDatetimeAttribute(
197                  attributes["expirationdate"]
198              )  # pragma no cover (was covered only by create_download, which has been removed)
199          if "html_url" in attributes:  # pragma no branch
200              self._html_url = self._makeStringAttribute(attributes["html_url"])
201          if "id" in attributes:  # pragma no branch
202              self._id = self._makeIntAttribute(attributes["id"])
203          if "mime_type" in attributes:  # pragma no branch
204              self._mime_type = self._makeStringAttribute(
205                  attributes["mime_type"]
206              )  # pragma no cover (was covered only by create_download, which has been removed)
207          if "name" in attributes:  # pragma no branch
208              self._name = self._makeStringAttribute(attributes["name"])
209          if "path" in attributes:  # pragma no branch
210              self._path = self._makeStringAttribute(
211                  attributes["path"]
212              )  # pragma no cover (was covered only by create_download, which has been removed)
213          if "policy" in attributes:  # pragma no branch
214              self._policy = self._makeStringAttribute(
215                  attributes["policy"]
216              )  # pragma no cover (was covered only by create_download, which has been removed)
217          if "prefix" in attributes:  # pragma no branch
218              self._prefix = self._makeStringAttribute(
219                  attributes["prefix"]
220              )  # pragma no cover (was covered only by create_download, which has been removed)
221          if "redirect" in attributes:  # pragma no branch
222              self._redirect = self._makeBoolAttribute(
223                  attributes["redirect"]
224              )  # pragma no cover (was covered only by create_download, which has been removed)
225          if "s3_url" in attributes:  # pragma no branch
226              self._s3_url = self._makeStringAttribute(
227                  attributes["s3_url"]
228              )  # pragma no cover (was covered only by create_download, which has been removed)
229          if "signature" in attributes:  # pragma no branch
230              self._signature = self._makeStringAttribute(
231                  attributes["signature"]
232              )  # pragma no cover (was covered only by create_download, which has been removed)
233          if "size" in attributes:  # pragma no branch
234              self._size = self._makeIntAttribute(attributes["size"])
235          if "url" in attributes:  # pragma no branch
236              self._url = self._makeStringAttribute(attributes["url"])