/ github / GitTreeElement.py
GitTreeElement.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  
31  from typing import Any, Dict
32  
33  from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet
34  
35  
36  class GitTreeElement(NonCompletableGithubObject):
37      """
38      This class represents GitTreeElements
39      """
40  
41      def _initAttributes(self) -> None:
42          self._mode: Attribute[str] = NotSet
43          self._path: Attribute[str] = NotSet
44          self._sha: Attribute[str] = NotSet
45          self._size: Attribute[int] = NotSet
46          self._type: Attribute[str] = NotSet
47          self._url: Attribute[str] = NotSet
48  
49      def __repr__(self) -> str:
50          return self.get__repr__({"sha": self._sha.value, "path": self._path.value})
51  
52      @property
53      def mode(self) -> str:
54          return self._mode.value
55  
56      @property
57      def path(self) -> str:
58          return self._path.value
59  
60      @property
61      def sha(self) -> str:
62          return self._sha.value
63  
64      @property
65      def size(self) -> int:
66          return self._size.value
67  
68      @property
69      def type(self) -> str:
70          return self._type.value
71  
72      @property
73      def url(self) -> str:
74          return self._url.value
75  
76      def _useAttributes(self, attributes: Dict[str, Any]) -> None:
77          if "mode" in attributes:  # pragma no branch
78              self._mode = self._makeStringAttribute(attributes["mode"])
79          if "path" in attributes:  # pragma no branch
80              self._path = self._makeStringAttribute(attributes["path"])
81          if "sha" in attributes:  # pragma no branch
82              self._sha = self._makeStringAttribute(attributes["sha"])
83          if "size" in attributes:  # pragma no branch
84              self._size = self._makeIntAttribute(attributes["size"])
85          if "type" in attributes:  # pragma no branch
86              self._type = self._makeStringAttribute(attributes["type"])
87          if "url" in attributes:  # pragma no branch
88              self._url = self._makeStringAttribute(attributes["url"])