Add support to create Repository objects lazily in MainClass.

This lets users do the following without issuing an unnecessary request:

issues_of_my_repository = g.get_repo('PyGithub/PyGithub').get_issues()

Since the GithubObject layer handles laziness transparently, lazy
loading is enabled by default, and can be disabled via the `lazy`
kwarg. This does not affect any test except tests that pertain to
caching or laziness itself.
This commit is contained in:
Uriel Corfa
2015-03-26 20:56:27 -07:00
parent ca13204dd5
commit 626d29c938
8 changed files with 111 additions and 15 deletions
+4 -1
View File
@@ -188,13 +188,16 @@ class Github(object):
)
return github.Organization.Organization(self.__requester, headers, data, completed=True)
def get_repo(self, full_name_or_id):
def get_repo(self, full_name_or_id, lazy=True):
"""
:calls: `GET /repos/:owner/:repo <http://developer.github.com/v3/repos>`_ or `GET /repositories/:id <http://developer.github.com/v3/repos>`_
:rtype: :class:`github.Repository.Repository`
"""
assert isinstance(full_name_or_id, (str, unicode, int)), full_name_or_id
url_base = "/repositories/" if isinstance(full_name_or_id, int) else "/repos/"
url = "%s%s" % (url_base, full_name_or_id)
if lazy:
return Repository.Repository(self.__requester, {}, {"url": url}, completed=False)
headers, data = self.__requester.requestJsonAndCheck(
"GET",
"%s%s" % (url_base, full_name_or_id)