From 12e7ee9e2807659b4ce58d020186c378b0e5ea40 Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Mon, 20 Feb 2012 17:31:24 +0100 Subject: [PATCH] Implement Owner.get_repo as an ObjectGetter --- github/GithubObject.UnitTest.py | 2 +- github/GithubObject.py | 2 +- github/GithubObjects.py | 8 +++----- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/github/GithubObject.UnitTest.py b/github/GithubObject.UnitTest.py index 37bb88d9..0a9ea27f 100644 --- a/github/GithubObject.UnitTest.py +++ b/github/GithubObject.UnitTest.py @@ -297,7 +297,7 @@ class GithubObjectWithObjectGetter( TestCaseWithGithubTestObject ): "GithubTestObject", BaseUrl( lambda obj: "/test" ), BasicAttributes( "a1", "a2" ), - ObjectGetter( "a3", ContainedObject, lambda id : { "id": id } ) + ObjectGetter( "a3", ContainedObject, lambda obj, id : { "id": id } ) ) def testGetList( self ): diff --git a/github/GithubObject.py b/github/GithubObject.py index df43e943..4ade07dd 100644 --- a/github/GithubObject.py +++ b/github/GithubObject.py @@ -192,7 +192,7 @@ class ObjectGetter( MethodFromCallable ): self.__type = type def __execute( self, obj, *args, **kwds ): - return self.__type( obj._github, self.__attributes( *args, **kwds ), lazy = False ) + return self.__type( obj._github, self.__attributes( obj, *args, **kwds ), lazy = False ) def GithubObject( className, *attributePolicies ): class GithubObject: diff --git a/github/GithubObjects.py b/github/GithubObjects.py index 7b380200..61a29701 100644 --- a/github/GithubObjects.py +++ b/github/GithubObjects.py @@ -84,11 +84,9 @@ AuthenticatedUser._addAttributePolicy( ListOfObjects( "repos", Repository, creat NamedUser._addAttributePolicy( ListOfObjects( "repos", Repository ) ) Organization._addAttributePolicy( ListOfObjects( "repos", Repository, creatable = True, singularName = "repo" ) ) -def __repoFromUser( user, name ): - return Repository( user._github, { "name": name, "owner": { "login": user.login } }, lazy = False ) -AuthenticatedUser._addAttributePolicy( MethodFromCallable( "get_repo", __repoFromUser ) ) -NamedUser._addAttributePolicy( MethodFromCallable( "get_repo", __repoFromUser ) ) -Organization._addAttributePolicy( MethodFromCallable( "get_repo", __repoFromUser ) ) +AuthenticatedUser._addAttributePolicy( ObjectGetter( "repo", Repository, lambda user, name: { "name": name, "owner": { "login": user.login } } ) ) +NamedUser._addAttributePolicy( ObjectGetter( "repo", Repository, lambda user, name: { "name": name, "owner": { "login": user.login } } ) ) +Organization._addAttributePolicy( ObjectGetter( "repo", Repository, lambda organization, name: { "name": name, "owner": { "login": organization.login } } ) ) AuthenticatedUser._addAttributePolicy( ListOfReferences( "watched", Repository, addable = True, removable = True, hasable = True ) ) NamedUser._addAttributePolicy( ListOfReferences( "watched", Repository ) )