mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 19:01:15 +00:00
Replace modifyAttributes by attributeModifiers
This commit is contained in:
@@ -133,7 +133,7 @@ Label = GithubObject(
|
||||
Deletable(),
|
||||
)
|
||||
|
||||
__modifyAttributesForObjectsReferingReferedRepo = lambda obj, attributes: dict( itertools.chain( attributes.iteritems(), { "_repo": obj._repo }.iteritems() ) )
|
||||
__modifyAttributesForObjectsReferingReferedRepo = { "_repo": lambda obj: obj._repo }
|
||||
|
||||
Milestone = GithubObject(
|
||||
"Milestone",
|
||||
@@ -251,7 +251,7 @@ Branch = GithubObject(
|
||||
InternalObjectAttribute( "commit", Commit )
|
||||
)
|
||||
|
||||
__modifyAttributesForObjectsReferingRepo = lambda obj, attributes: dict( itertools.chain( attributes.iteritems(), { "_repo": obj }.iteritems() ) )
|
||||
__modifyAttributesForObjectsReferingRepo = { "_repo": lambda obj: obj }
|
||||
Repository = GithubObject(
|
||||
"Repository",
|
||||
BaseUrl( lambda obj: "/repos/" + obj.owner.login + "/" + obj.name ),
|
||||
|
||||
@@ -34,9 +34,9 @@ class ElementHasable( ListCapacity ):
|
||||
return obj._github._statusRequest( "GET", obj._baseUrl + "/" + self.attributeName + "/" + self.typePolicy.getIdentity( toBeQueried ), None, None ) == 204
|
||||
|
||||
class ElementCreatable( ListCapacity ):
|
||||
def __init__( self, mandatoryParameters, optionalParameters, modifyAttributes = lambda obj, attributes: attributes ):
|
||||
def __init__( self, mandatoryParameters, optionalParameters, attributeModifiers = {} ):
|
||||
self.__argumentsChecker = ArgumentsChecker( mandatoryParameters, optionalParameters )
|
||||
self.__modifyAttributes = modifyAttributes
|
||||
self.__attributeModifiers = attributeModifiers
|
||||
|
||||
def apply( self, cls ):
|
||||
cls._addMethod( "create_" + self.singularName, self.__execute )
|
||||
@@ -46,6 +46,11 @@ class ElementCreatable( ListCapacity ):
|
||||
attributes = obj._github._dataRequest( "POST", obj._baseUrl + "/" + self.attributeName, None, data )
|
||||
return self.typePolicy.createLazy( obj, self.__modifyAttributes( obj, attributes ) )
|
||||
|
||||
def __modifyAttributes( self, obj, attributes ):
|
||||
for attributeName, attributeModifier in self.__attributeModifiers.iteritems():
|
||||
attributes[ attributeName ] = attributeModifier( obj )
|
||||
return attributes
|
||||
|
||||
class ElementGetable( ListCapacity ):
|
||||
def __init__( self, mandatoryParameters, optionalParameters, objReferenceName = None ):
|
||||
self.__argumentsChecker = ArgumentsChecker( mandatoryParameters, optionalParameters )
|
||||
@@ -75,9 +80,9 @@ class SeveralElementsRemovable( ListCapacity ):
|
||||
obj._github._statusRequest( "DELETE", obj._baseUrl + "/" + self.attributeName, None, [ self.typePolicy.getIdentity( toBeDeleted ) for toBeDeleted in toBeDeleteds ] )
|
||||
|
||||
class ListGetable( ListCapacity ):
|
||||
def __init__( self, mandatoryParameters, optionalParameters, modifyAttributes = lambda obj, attributes: attributes ):
|
||||
def __init__( self, mandatoryParameters, optionalParameters, attributeModifiers = {} ):
|
||||
self.__argumentsChecker = ArgumentsChecker( mandatoryParameters, optionalParameters )
|
||||
self.__modifyAttributes = modifyAttributes
|
||||
self.__attributeModifiers = attributeModifiers
|
||||
|
||||
def apply( self, cls ):
|
||||
cls._addMethod( "get_" + self.safeAttributeName, self.__execute )
|
||||
@@ -89,6 +94,11 @@ class ListGetable( ListCapacity ):
|
||||
for attributes in obj._github._dataRequest( "GET", obj._baseUrl + "/" + self.attributeName, params, None )
|
||||
]
|
||||
|
||||
def __modifyAttributes( self, obj, attributes ):
|
||||
for attributeName, attributeModifier in self.__attributeModifiers.iteritems():
|
||||
attributes[ attributeName ] = attributeModifier( obj )
|
||||
return attributes
|
||||
|
||||
class ListSetable( ListCapacity ):
|
||||
def apply( self, cls ):
|
||||
cls._addMethod( "set_" + self.safeAttributeName, self.__execute )
|
||||
|
||||
Reference in New Issue
Block a user