Factorize the creation of attributes (preparation for #195)

This commit is contained in:
Vincent Jacques
2013-09-12 09:27:25 +02:00
parent 4a5009741a
commit 597e123029
55 changed files with 620 additions and 1132 deletions
+10 -26
View File
@@ -217,38 +217,22 @@ class Commit(github.GithubObject.CompletableGithubObject):
def _useAttributes(self, attributes):
if "author" in attributes: # pragma no branch
assert attributes["author"] is None or isinstance(attributes["author"], dict), attributes["author"]
self._author = github.GithubObject.ValuedAttribute(None if attributes["author"] is None else github.NamedUser.NamedUser(self._requester, self._headers, attributes["author"], completed=False))
self._author = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["author"])
if "comments_url" in attributes: # pragma no branch
assert attributes["comments_url"] is None or isinstance(attributes["comments_url"], (str, unicode)), attributes["comments_url"]
self._comments_url = github.GithubObject.ValuedAttribute(attributes["comments_url"])
self._comments_url = self._makeStringAttribute(attributes["comments_url"])
if "commit" in attributes: # pragma no branch
assert attributes["commit"] is None or isinstance(attributes["commit"], dict), attributes["commit"]
self._commit = github.GithubObject.ValuedAttribute(None if attributes["commit"] is None else github.GitCommit.GitCommit(self._requester, self._headers, attributes["commit"], completed=False))
self._commit = self._makeClassAttribute(github.GitCommit.GitCommit, attributes["commit"])
if "committer" in attributes: # pragma no branch
assert attributes["committer"] is None or isinstance(attributes["committer"], dict), attributes["committer"]
self._committer = github.GithubObject.ValuedAttribute(None if attributes["committer"] is None else github.NamedUser.NamedUser(self._requester, self._headers, attributes["committer"], completed=False))
self._committer = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["committer"])
if "files" in attributes: # pragma no branch
assert attributes["files"] is None or all(isinstance(element, dict) for element in attributes["files"]), attributes["files"]
self._files = github.GithubObject.ValuedAttribute(None if attributes["files"] is None else [
github.File.File(self._requester, self._headers, element, completed=False)
for element in attributes["files"]
])
self._files = self._makeListOfClassesAttribute(github.File.File, attributes["files"])
if "html_url" in attributes: # pragma no branch
assert attributes["html_url"] is None or isinstance(attributes["html_url"], (str, unicode)), attributes["html_url"]
self._html_url = github.GithubObject.ValuedAttribute(attributes["html_url"])
self._html_url = self._makeStringAttribute(attributes["html_url"])
if "parents" in attributes: # pragma no branch
assert attributes["parents"] is None or all(isinstance(element, dict) for element in attributes["parents"]), attributes["parents"]
self._parents = github.GithubObject.ValuedAttribute(None if attributes["parents"] is None else [
Commit(self._requester, self._headers, element, completed=False)
for element in attributes["parents"]
])
self._parents = self._makeListOfClassesAttribute(Commit, attributes["parents"])
if "sha" in attributes: # pragma no branch
assert attributes["sha"] is None or isinstance(attributes["sha"], (str, unicode)), attributes["sha"]
self._sha = github.GithubObject.ValuedAttribute(attributes["sha"])
self._sha = self._makeStringAttribute(attributes["sha"])
if "stats" in attributes: # pragma no branch
assert attributes["stats"] is None or isinstance(attributes["stats"], dict), attributes["stats"]
self._stats = github.GithubObject.ValuedAttribute(None if attributes["stats"] is None else github.CommitStats.CommitStats(self._requester, self._headers, attributes["stats"], completed=False))
self._stats = self._makeClassAttribute(github.CommitStats.CommitStats, attributes["stats"])
if "url" in attributes: # pragma no branch
assert attributes["url"] is None or isinstance(attributes["url"], (str, unicode)), attributes["url"]
self._url = github.GithubObject.ValuedAttribute(attributes["url"])
self._url = self._makeStringAttribute(attributes["url"])