diff --git a/github/GithubObject.py b/github/GithubObject.py index 99643878..471157df 100644 --- a/github/GithubObject.py +++ b/github/GithubObject.py @@ -3,21 +3,11 @@ import itertools import ObjectCapacities.ArgumentsChecker as ArgumentsChecker from ObjectCapacities.Basic import AttributeFromCallable, MethodFromCallable from ObjectCapacities.List import ListAttribute, ListGetable, ElementCreatable, ElementGetable, ElementAddable, ElementRemovable, ElementHasable, ListAddable, ListSetable, ListDeletable +from TypePolicies import SimpleTypePolicy, ObjectTypePolicy class BadGithubObjectException( Exception ): pass -class SimpleTypePolicy: - def create( self, obj, rawValue ): - return rawValue - -class ObjectTypePolicy: - def __init__( self, type ): - self.__type = type - - def create( self, obj, rawValue ): - return self.__type( obj._github, rawValue, lazy = True ) - class InternalAttribute: class AttributeDefinition: def __init__( self, typePolicy ): diff --git a/github/ObjectCapacities/List.py b/github/ObjectCapacities/List.py index a3f05348..9b06d354 100644 --- a/github/ObjectCapacities/List.py +++ b/github/ObjectCapacities/List.py @@ -47,6 +47,19 @@ class ElementCreatable: data = self.__argumentsChecker.check( args, kwds ) return self.__type( obj._github, self.__modifyAttributes( obj, obj._github._dataRequest( "POST", obj._baseUrl + "/" + self.__attributeName, None, data ) ), lazy = True ) +class ElementGetable: + 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, *args, **kwds ): + return self.__type( obj._github, self.__attributes( obj, *args, **kwds ), lazy = False ) + class ListGetable: def __init__( self, mandatoryParameters, optionalParameters, modifyAttributes = lambda obj, attributes: attributes ): self.__argumentsChecker = ArgumentsChecker.ArgumentsChecker( mandatoryParameters, optionalParameters ) @@ -64,19 +77,6 @@ class ListGetable: for attributes in obj._github._dataRequest( "GET", obj._baseUrl + "/" + self.__attributeName, params, None ) ] -class ElementGetable: - 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, *args, **kwds ): - return self.__type( obj._github, self.__attributes( obj, *args, **kwds ), lazy = False ) - class ListAddable: def apply( self, list, cls ): self.__type = list.type diff --git a/github/TypePolicies.py b/github/TypePolicies.py new file mode 100644 index 00000000..906c7a75 --- /dev/null +++ b/github/TypePolicies.py @@ -0,0 +1,10 @@ +class SimpleTypePolicy: + def create( self, obj, rawValue ): + return rawValue + +class ObjectTypePolicy: + def __init__( self, type ): + self.__type = type + + def create( self, obj, rawValue ): + return self.__type( obj._github, rawValue, lazy = True )