diff --git a/github/GithubObjects.py b/github/GithubObjects.py index 5e7ad31e..1b768f4a 100644 --- a/github/GithubObjects.py +++ b/github/GithubObjects.py @@ -183,7 +183,7 @@ Issue = GithubObject( ), ExternalListOfObjects( "comments", "comment", IssueComment, ListGetable( [], [], __modifyAttributesForObjectsReferingReferedRepo ), - ElementGetable( [ "id" ], [], "_repo" ), + ElementGetable( [ "id" ], [], __modifyAttributesForObjectsReferingReferedRepo ), ElementCreatable( [ "body" ], [], __modifyAttributesForObjectsReferingReferedRepo ), ), ) @@ -251,7 +251,7 @@ Branch = GithubObject( InternalObjectAttribute( "commit", Commit ) ) -__modifyAttributesForObjectsReferingRepo = { "_repo": lambda obj: obj } +__modifyAttributesForObjectsReferingRepo = { "_repo": lambda repo: repo } Repository = GithubObject( "Repository", BaseUrl( lambda obj: "/repos/" + obj.owner.login + "/" + obj.name ), @@ -272,53 +272,53 @@ Repository = GithubObject( Editable( [ "name" ], [ "description", "homepage", "public", "has_issues", "has_wiki", "has_downloads" ] ), ExternalListOfObjects( "git/refs", "git_ref", GitRef, ListGetable( [], [], __modifyAttributesForObjectsReferingRepo ), - ElementGetable( [ "ref" ], [], "_repo" ), + ElementGetable( [ "ref" ], [], __modifyAttributesForObjectsReferingRepo ), ElementCreatable( [ "ref", "sha" ], [], __modifyAttributesForObjectsReferingRepo ) ), ExternalListOfObjects( "git/commits", "git_commit", GitCommit, - ElementGetable( [ "sha" ], [], "_repo" ), + ElementGetable( [ "sha" ], [], __modifyAttributesForObjectsReferingRepo ), ElementCreatable( [ "message", "tree", "parents" ], [ "author", "commiter" ], __modifyAttributesForObjectsReferingRepo ) ), ExternalListOfObjects( "git/trees", "git_tree", GitTree, - ElementGetable( [ "sha" ], [], "_repo" ), + ElementGetable( [ "sha" ], [], __modifyAttributesForObjectsReferingRepo ), ElementCreatable( [ "tree" ], [], __modifyAttributesForObjectsReferingRepo ) ), ExternalListOfObjects( "git/blobs", "git_blob", GitBlob, - ElementGetable( [ "sha" ], [], "_repo" ), + ElementGetable( [ "sha" ], [], __modifyAttributesForObjectsReferingRepo ), ElementCreatable( [ "content", "encoding" ], [], __modifyAttributesForObjectsReferingRepo ) ), ExternalListOfObjects( "git/tags", "git_tag", GitTag, - ElementGetable( [ "sha" ], [], "_repo" ), + ElementGetable( [ "sha" ], [], __modifyAttributesForObjectsReferingRepo ), ElementCreatable( [ "tag", "message", "object", "type" ], [ "tagger" ], __modifyAttributesForObjectsReferingRepo ) ), ExternalListOfObjects( "labels", "label", Label, ListGetable( [], [], __modifyAttributesForObjectsReferingRepo ), - ElementGetable( [ "name" ], [], "_repo" ), + ElementGetable( [ "name" ], [], __modifyAttributesForObjectsReferingRepo ), ElementCreatable( [ "name", "color" ], [], __modifyAttributesForObjectsReferingRepo ), ), ExternalListOfObjects( "milestones", "milestone", Milestone, ListGetable( [], [ "state", "sort", "direction" ], __modifyAttributesForObjectsReferingRepo ), - ElementGetable( [ "number" ], [], "_repo" ), + ElementGetable( [ "number" ], [], __modifyAttributesForObjectsReferingRepo ), ElementCreatable( [ "title" ], [ "state", "description", "due_on" ], __modifyAttributesForObjectsReferingRepo ) ), ExternalListOfObjects( "issues", "issue", Issue, ListGetable( [], [ "milestone", "state", "assignee", "mentioned", "labels", "sort", "direction", "since" ], __modifyAttributesForObjectsReferingRepo ), - ElementGetable( [ "number" ], [], "_repo" ), + ElementGetable( [ "number" ], [], __modifyAttributesForObjectsReferingRepo ), ElementCreatable( [ "title" ], [ "body", "assignee", "milestone", "labels", ], __modifyAttributesForObjectsReferingRepo ) ), ExternalSimpleAttribute( "languages" ), ExternalListOfObjects( "downloads", "download", Download, ListGetable( [], [], __modifyAttributesForObjectsReferingRepo ), - ElementGetable( [ "id" ], [], "_repo" ), + ElementGetable( [ "id" ], [], __modifyAttributesForObjectsReferingRepo ), ElementCreatable( [ "name", "size" ], [ "description", "content_type" ], __modifyAttributesForObjectsReferingRepo ), ), ExternalListOfObjects( "comments", "comment", CommitComment, ListGetable( [], [], __modifyAttributesForObjectsReferingRepo ), - ElementGetable( [ "id" ], [], "_repo" ), + ElementGetable( [ "id" ], [], __modifyAttributesForObjectsReferingRepo ), ), ExternalListOfObjects( "commits", "commit", Commit, ListGetable( [], [ "sha", "path" ], __modifyAttributesForObjectsReferingRepo ), - ElementGetable( [ "sha" ], [], "_repo" ), + ElementGetable( [ "sha" ], [], __modifyAttributesForObjectsReferingRepo ), ), ExternalListOfObjects( "tags", "tag", Tag, ListGetable( [], [], __modifyAttributesForObjectsReferingRepo ), @@ -332,7 +332,7 @@ Repository._addAttributePolicy( InternalObjectAttribute( "source", Repository ) Repository._addAttributePolicy( ExternalListOfObjects( "forks", "fork", Repository, ListGetable( [], [] ) ) ) __repoElementCreatable = ElementCreatable( [ "name" ], [ "description", "homepage", "private", "has_issues", "has_wiki", "has_downloads", "team_id", ] ) -__repoElementGetable = ElementGetable( [ "name" ], [], "owner" ) +__repoElementGetable = ElementGetable( [ "name" ], [], { "owner" : lambda user: user } ) __repoListGetable = ListGetable( [], [] ) AuthenticatedUser._addAttributePolicy( ExternalListOfObjects( "repos", "repo", Repository, __repoListGetable, __repoElementGetable, __repoElementCreatable ) ) NamedUser._addAttributePolicy( ExternalListOfObjects( "repos", "repo", Repository, __repoListGetable, __repoElementGetable ) ) diff --git a/github/ObjectCapacities/List.py b/github/ObjectCapacities/List.py index 9329470e..4483d329 100644 --- a/github/ObjectCapacities/List.py +++ b/github/ObjectCapacities/List.py @@ -43,8 +43,7 @@ class ElementCreatable( ListCapacity ): def __execute( self, obj, *args, **kwds ): data = self.__argumentsChecker.check( args, kwds ) - attributes = obj._github._dataRequest( "POST", obj._baseUrl + "/" + self.attributeName, None, data ) - return self.typePolicy.createLazy( obj, self.__modifyAttributes( obj, attributes ) ) + return self.typePolicy.createLazy( obj, self.__modifyAttributes( obj, obj._github._dataRequest( "POST", obj._baseUrl + "/" + self.attributeName, None, data ) ) ) def __modifyAttributes( self, obj, attributes ): for attributeName, attributeModifier in self.__attributeModifiers.iteritems(): @@ -52,18 +51,20 @@ class ElementCreatable( ListCapacity ): return attributes class ElementGetable( ListCapacity ): - def __init__( self, mandatoryParameters, optionalParameters, objReferenceName = None ): + def __init__( self, mandatoryParameters, optionalParameters, attributeModifiers = {} ): self.__argumentsChecker = ArgumentsChecker( mandatoryParameters, optionalParameters ) - self.__objReferenceName = objReferenceName + self.__attributeModifiers = attributeModifiers def apply( self, cls ): cls._addMethod( "get_" + self.singularName, self.__execute ) def __execute( self, obj, *args, **kwds ): - attributes = self.__argumentsChecker.check( args, kwds ) - if self.__objReferenceName is not None: - attributes[ self.__objReferenceName ] = obj - return self.typePolicy.createNonLazy( obj, attributes ) + return self.typePolicy.createNonLazy( obj, self.__modifyAttributes( obj, self.__argumentsChecker.check( args, kwds ) ) ) + + def __modifyAttributes( self, obj, attributes ): + for attributeName, attributeModifier in self.__attributeModifiers.iteritems(): + attributes[ attributeName ] = attributeModifier( obj ) + return attributes class SeveralElementsAddable( ListCapacity ): def apply( self, cls ):