From f2bc0ea9429da8423d272d62bab6b782e3205b30 Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Wed, 22 Feb 2012 19:41:01 +0000 Subject: [PATCH] Remove default ListGetable capacity from lists --- github/GithubObject.UnitTest.py | 8 ++++---- github/GithubObject.py | 2 +- github/GithubObjects.py | 11 ++++------- github/{ => ObjectCapacities}/ArgumentsChecker.py | 0 github/ObjectCapacities/List.py | 10 +++++----- 5 files changed, 14 insertions(+), 17 deletions(-) rename github/{ => ObjectCapacities}/ArgumentsChecker.py (100%) diff --git a/github/GithubObject.UnitTest.py b/github/GithubObject.UnitTest.py index 6b9ead71..5be5e52d 100644 --- a/github/GithubObject.UnitTest.py +++ b/github/GithubObject.UnitTest.py @@ -221,7 +221,7 @@ class GithubObjectWithListOfReferences( TestCaseWithGithubTestObject ): a3s = self.o.get_a3s( "foobar" ) self.assertEqual( len( a3s ), 3 ) -class GithubObjectWithListOfObjects( TestCaseWithGithubTestObject ): +class GithubObjectWithListGetableList( TestCaseWithGithubTestObject ): ContainedObject = GithubObject( "ContainedObject", BaseUrl( lambda obj: "/test/a3s/" + obj.id ), @@ -232,7 +232,7 @@ class GithubObjectWithListOfObjects( TestCaseWithGithubTestObject ): "GithubTestObject", BaseUrl( lambda obj: "/test" ), BasicAttributes( "a1", "a2" ), - ListOfObjects( "a3s", ContainedObject ) + ListOfObjects( "a3s", ContainedObject, ListGetable() ) ) def testGetList( self ): @@ -275,7 +275,7 @@ class GithubObjectWithModifiableListOfReferences( TestCaseWithGithubTestObject ) self.expectStatusGet( "/test/a3s/idQuery" ).andReturn( 404 ) self.assertFalse( self.o.has_in_a3s( a3ToQuery ) ) -class GithubObjectWithModifiableListOfObjects( TestCaseWithGithubTestObject ): +class GithubObjectWithElementCreatableList( TestCaseWithGithubTestObject ): ContainedObject = GithubObject( "ContainedObject", BaseUrl( lambda obj: "/test/a3s/" + obj.id ), @@ -343,7 +343,7 @@ class GithubObjectWithElementGetableList( TestCaseWithGithubTestObject ): "GithubTestObject", BaseUrl( lambda obj: "/test" ), BasicAttributes( "a1", "a2" ), - ListOfObjects( "a3s", ContainedObject, ElementGetable( "a3" ) ) + ListOfObjects( "a3s", ContainedObject, ElementGetable( "a3", lambda obj, id: { "id": id } ) ) ) def testGetList( self ): diff --git a/github/GithubObject.py b/github/GithubObject.py index d409baa1..4ddd9ee1 100644 --- a/github/GithubObject.py +++ b/github/GithubObject.py @@ -1,6 +1,6 @@ import itertools -import ArgumentsChecker +import ObjectCapacities.ArgumentsChecker as ArgumentsChecker from ObjectCapacities.Basic import AttributeFromCallable, MethodFromCallable from ObjectCapacities.List import ListOfObjects, ListOfReferences, ListGetable, ElementCreatable, ElementGetable diff --git a/github/GithubObjects.py b/github/GithubObjects.py index 111260d7..cbf134ee 100644 --- a/github/GithubObjects.py +++ b/github/GithubObjects.py @@ -81,13 +81,10 @@ Repository._addAttributePolicy( ComplexAttribute( "source", Repository ) ) Repository._addAttributePolicy( ListOfReferences( "forks", Repository ) ) __repoCreatable = ElementCreatable( "repo", [ "name" ], [ "description", "homepage", "private", "has_issues", "has_wiki", "has_downloads", "team_id", ] ) -AuthenticatedUser._addAttributePolicy( ListOfObjects( "repos", Repository, __repoCreatable ) ) -NamedUser._addAttributePolicy( ListOfObjects( "repos", Repository ) ) -Organization._addAttributePolicy( ListOfObjects( "repos", Repository, __repoCreatable ) ) - -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 } } ) ) +__repoElementGetable = ElementGetable( "repo", lambda obj, name: { "owner": { "login": obj.login }, "name": name } ) +AuthenticatedUser._addAttributePolicy( ListOfObjects( "repos", Repository, ListGetable(), __repoElementGetable, __repoCreatable ) ) +NamedUser._addAttributePolicy( ListOfObjects( "repos", Repository, ListGetable(), __repoElementGetable ) ) +Organization._addAttributePolicy( ListOfObjects( "repos", Repository, ListGetable(), __repoElementGetable, __repoCreatable ) ) AuthenticatedUser._addAttributePolicy( ListOfReferences( "watched", Repository, addable = True, removable = True, hasable = True ) ) NamedUser._addAttributePolicy( ListOfReferences( "watched", Repository ) ) diff --git a/github/ArgumentsChecker.py b/github/ObjectCapacities/ArgumentsChecker.py similarity index 100% rename from github/ArgumentsChecker.py rename to github/ObjectCapacities/ArgumentsChecker.py diff --git a/github/ObjectCapacities/List.py b/github/ObjectCapacities/List.py index 9c8ce222..268e89a7 100644 --- a/github/ObjectCapacities/List.py +++ b/github/ObjectCapacities/List.py @@ -78,24 +78,24 @@ class ListGetable: ] class ElementGetable: - def __init__( self, singularName ): + def __init__( self, singularName, attributes ): self.__getName = "get_" + singularName + self.__attributes = attributes def apply( self, list, cls ): self.__type = list.type self.__attributeName = list.attributeName cls._addMethod( self.__getName, self.__execute ) - def __execute( self, obj, identity ): - return self.__type( obj._github, obj._github._dataRequest( "GET", obj._baseUrl + "/" + self.__attributeName + "/" + identity, None, None ), lazy = True ) + def __execute( self, obj, *args, **kwds ): + return self.__type( obj._github, self.__attributes( obj, *args, **kwds ), lazy = False ) class ListOfObjects: def __init__( self, attributeName, type, *capacities ): self.attributeName = attributeName self.type = type self.__getName = "get_" + attributeName - self.__capacities = list( capacities ) - self.__capacities.append( ListGetable() ) + self.__capacities = capacities def apply( self, cls ): for capacity in self.__capacities: