From b27529abb95fdd3467f271f9f3a8739451beb2df Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Wed, 22 Feb 2012 07:57:29 +0100 Subject: [PATCH] Refactor --- github/GithubObject.py | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/github/GithubObject.py b/github/GithubObject.py index 2c4352fa..4f938acc 100644 --- a/github/GithubObject.py +++ b/github/GithubObject.py @@ -137,31 +137,37 @@ class Creatable: def apply( self, list, cls ): self.__type = list.type self.__attributeName = list.attributeName - cls._addMethod( self.__createName, self.__executeCreate ) + cls._addMethod( self.__createName, self.__execute ) - def __executeCreate( self, obj, *args, **kwds ): + def __execute( self, obj, *args, **kwds ): data = self.__createArgumentsChecker.check( args, kwds ) return self.__type( obj._github, obj._github._dataRequest( "POST", obj._baseUrl + "/" + self.__attributeName, None, data ), lazy = True ) +class ListGetable: + def apply( self, list, cls ): + self.__type = list.type + self.__attributeName = list.attributeName + cls._addMethod( "get_" + list.attributeName, self.__execute ) + + def __execute( self, obj ): + return [ + self.__type( obj._github, attributes, lazy = True ) + for attributes in obj._github._dataRequest( "GET", obj._baseUrl + "/" + self.__attributeName, None, None ) + ] + ### @todo Merge ObjectGetter in ListOfObjects, with a SingleGettable similar to Creatable ### @todo Add a ListGetable that couls be False for non-getable lists (repo/git/commits for example) class ListOfObjects: - def __init__( self, attributeName, type, creatable = None ): + def __init__( self, attributeName, type, *capacities ): self.attributeName = attributeName self.type = type self.__getName = "get_" + attributeName - self.creatable = creatable + self.__capacities = list( capacities ) + self.__capacities.append( ListGetable() ) def apply( self, cls ): - cls._addMethod( self.__getName, self.__executeGet ) - if self.creatable: - self.creatable.apply( self, cls ) - - def __executeGet( self, obj ): - return [ - self.type( obj._github, attributes, lazy = True ) - for attributes in obj._github._dataRequest( "GET", obj._baseUrl + "/" + self.attributeName, None, None ) - ] + for capacity in self.__capacities: + capacity.apply( self, cls ) class MethodFromCallable: def __init__( self, name, callable ):