From 85eef756353e13efcb24c726320cd2617c2a7bd8 Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Wed, 14 Mar 2012 22:31:32 +0100 Subject: [PATCH 1/5] Move classes around --- github/{ => GithubObjects}/AuthenticatedUser.py | 0 github/{ => GithubObjects}/Authorization.py | 0 github/{ => GithubObjects}/Branch.py | 0 github/{ => GithubObjects}/Commit.py | 0 github/{ => GithubObjects}/CommitComment.py | 0 github/{ => GithubObjects}/Download.py | 0 github/{ => GithubObjects}/Event.py | 0 github/{ => GithubObjects}/Gist.py | 0 github/{ => GithubObjects}/GistComment.py | 0 github/{ => GithubObjects}/GitBlob.py | 0 github/{ => GithubObjects}/GitCommit.py | 0 github/{ => GithubObjects}/GitRef.py | 0 github/{ => GithubObjects}/GitTag.py | 0 github/{ => GithubObjects}/GitTree.py | 0 github/{ => GithubObjects}/GithubObject.UnitTest.py | 0 github/{ => GithubObjects}/GithubObject.py | 0 github/{ => GithubObjects}/Hook.py | 0 github/{ => GithubObjects}/Issue.py | 0 github/{ => GithubObjects}/IssueComment.py | 0 github/{ => GithubObjects}/IssueEvent.py | 0 github/{ => GithubObjects}/Label.py | 0 github/{ => GithubObjects}/Milestone.py | 0 github/{ => GithubObjects}/NamedUser.py | 0 github/{ => GithubObjects}/ObjectCapacities/ArgumentsChecker.py | 0 github/{ => GithubObjects}/ObjectCapacities/Basic.py | 0 github/{ => GithubObjects}/ObjectCapacities/List.py | 0 github/{ => GithubObjects}/ObjectCapacities/TypePolicies.py | 0 github/{ => GithubObjects}/ObjectCapacities/__init__.py | 0 github/{ => GithubObjects}/Organization.py | 0 github/{ => GithubObjects}/PullRequest.py | 0 github/{ => GithubObjects}/PullRequestComment.py | 0 github/{ => GithubObjects}/PullRequestFile.py | 0 github/{ => GithubObjects}/Repository.py | 0 github/{ => GithubObjects}/RepositoryKey.py | 0 github/{ => GithubObjects}/Tag.py | 0 github/{ => GithubObjects}/Team.py | 0 github/{ => GithubObjects}/UserKey.py | 0 github/{GithubObjects.py => GithubObjects/__init__.py} | 0 38 files changed, 0 insertions(+), 0 deletions(-) rename github/{ => GithubObjects}/AuthenticatedUser.py (100%) rename github/{ => GithubObjects}/Authorization.py (100%) rename github/{ => GithubObjects}/Branch.py (100%) rename github/{ => GithubObjects}/Commit.py (100%) rename github/{ => GithubObjects}/CommitComment.py (100%) rename github/{ => GithubObjects}/Download.py (100%) rename github/{ => GithubObjects}/Event.py (100%) rename github/{ => GithubObjects}/Gist.py (100%) rename github/{ => GithubObjects}/GistComment.py (100%) rename github/{ => GithubObjects}/GitBlob.py (100%) rename github/{ => GithubObjects}/GitCommit.py (100%) rename github/{ => GithubObjects}/GitRef.py (100%) rename github/{ => GithubObjects}/GitTag.py (100%) rename github/{ => GithubObjects}/GitTree.py (100%) rename github/{ => GithubObjects}/GithubObject.UnitTest.py (100%) rename github/{ => GithubObjects}/GithubObject.py (100%) rename github/{ => GithubObjects}/Hook.py (100%) rename github/{ => GithubObjects}/Issue.py (100%) rename github/{ => GithubObjects}/IssueComment.py (100%) rename github/{ => GithubObjects}/IssueEvent.py (100%) rename github/{ => GithubObjects}/Label.py (100%) rename github/{ => GithubObjects}/Milestone.py (100%) rename github/{ => GithubObjects}/NamedUser.py (100%) rename github/{ => GithubObjects}/ObjectCapacities/ArgumentsChecker.py (100%) rename github/{ => GithubObjects}/ObjectCapacities/Basic.py (100%) rename github/{ => GithubObjects}/ObjectCapacities/List.py (100%) rename github/{ => GithubObjects}/ObjectCapacities/TypePolicies.py (100%) rename github/{ => GithubObjects}/ObjectCapacities/__init__.py (100%) rename github/{ => GithubObjects}/Organization.py (100%) rename github/{ => GithubObjects}/PullRequest.py (100%) rename github/{ => GithubObjects}/PullRequestComment.py (100%) rename github/{ => GithubObjects}/PullRequestFile.py (100%) rename github/{ => GithubObjects}/Repository.py (100%) rename github/{ => GithubObjects}/RepositoryKey.py (100%) rename github/{ => GithubObjects}/Tag.py (100%) rename github/{ => GithubObjects}/Team.py (100%) rename github/{ => GithubObjects}/UserKey.py (100%) rename github/{GithubObjects.py => GithubObjects/__init__.py} (100%) diff --git a/github/AuthenticatedUser.py b/github/GithubObjects/AuthenticatedUser.py similarity index 100% rename from github/AuthenticatedUser.py rename to github/GithubObjects/AuthenticatedUser.py diff --git a/github/Authorization.py b/github/GithubObjects/Authorization.py similarity index 100% rename from github/Authorization.py rename to github/GithubObjects/Authorization.py diff --git a/github/Branch.py b/github/GithubObjects/Branch.py similarity index 100% rename from github/Branch.py rename to github/GithubObjects/Branch.py diff --git a/github/Commit.py b/github/GithubObjects/Commit.py similarity index 100% rename from github/Commit.py rename to github/GithubObjects/Commit.py diff --git a/github/CommitComment.py b/github/GithubObjects/CommitComment.py similarity index 100% rename from github/CommitComment.py rename to github/GithubObjects/CommitComment.py diff --git a/github/Download.py b/github/GithubObjects/Download.py similarity index 100% rename from github/Download.py rename to github/GithubObjects/Download.py diff --git a/github/Event.py b/github/GithubObjects/Event.py similarity index 100% rename from github/Event.py rename to github/GithubObjects/Event.py diff --git a/github/Gist.py b/github/GithubObjects/Gist.py similarity index 100% rename from github/Gist.py rename to github/GithubObjects/Gist.py diff --git a/github/GistComment.py b/github/GithubObjects/GistComment.py similarity index 100% rename from github/GistComment.py rename to github/GithubObjects/GistComment.py diff --git a/github/GitBlob.py b/github/GithubObjects/GitBlob.py similarity index 100% rename from github/GitBlob.py rename to github/GithubObjects/GitBlob.py diff --git a/github/GitCommit.py b/github/GithubObjects/GitCommit.py similarity index 100% rename from github/GitCommit.py rename to github/GithubObjects/GitCommit.py diff --git a/github/GitRef.py b/github/GithubObjects/GitRef.py similarity index 100% rename from github/GitRef.py rename to github/GithubObjects/GitRef.py diff --git a/github/GitTag.py b/github/GithubObjects/GitTag.py similarity index 100% rename from github/GitTag.py rename to github/GithubObjects/GitTag.py diff --git a/github/GitTree.py b/github/GithubObjects/GitTree.py similarity index 100% rename from github/GitTree.py rename to github/GithubObjects/GitTree.py diff --git a/github/GithubObject.UnitTest.py b/github/GithubObjects/GithubObject.UnitTest.py similarity index 100% rename from github/GithubObject.UnitTest.py rename to github/GithubObjects/GithubObject.UnitTest.py diff --git a/github/GithubObject.py b/github/GithubObjects/GithubObject.py similarity index 100% rename from github/GithubObject.py rename to github/GithubObjects/GithubObject.py diff --git a/github/Hook.py b/github/GithubObjects/Hook.py similarity index 100% rename from github/Hook.py rename to github/GithubObjects/Hook.py diff --git a/github/Issue.py b/github/GithubObjects/Issue.py similarity index 100% rename from github/Issue.py rename to github/GithubObjects/Issue.py diff --git a/github/IssueComment.py b/github/GithubObjects/IssueComment.py similarity index 100% rename from github/IssueComment.py rename to github/GithubObjects/IssueComment.py diff --git a/github/IssueEvent.py b/github/GithubObjects/IssueEvent.py similarity index 100% rename from github/IssueEvent.py rename to github/GithubObjects/IssueEvent.py diff --git a/github/Label.py b/github/GithubObjects/Label.py similarity index 100% rename from github/Label.py rename to github/GithubObjects/Label.py diff --git a/github/Milestone.py b/github/GithubObjects/Milestone.py similarity index 100% rename from github/Milestone.py rename to github/GithubObjects/Milestone.py diff --git a/github/NamedUser.py b/github/GithubObjects/NamedUser.py similarity index 100% rename from github/NamedUser.py rename to github/GithubObjects/NamedUser.py diff --git a/github/ObjectCapacities/ArgumentsChecker.py b/github/GithubObjects/ObjectCapacities/ArgumentsChecker.py similarity index 100% rename from github/ObjectCapacities/ArgumentsChecker.py rename to github/GithubObjects/ObjectCapacities/ArgumentsChecker.py diff --git a/github/ObjectCapacities/Basic.py b/github/GithubObjects/ObjectCapacities/Basic.py similarity index 100% rename from github/ObjectCapacities/Basic.py rename to github/GithubObjects/ObjectCapacities/Basic.py diff --git a/github/ObjectCapacities/List.py b/github/GithubObjects/ObjectCapacities/List.py similarity index 100% rename from github/ObjectCapacities/List.py rename to github/GithubObjects/ObjectCapacities/List.py diff --git a/github/ObjectCapacities/TypePolicies.py b/github/GithubObjects/ObjectCapacities/TypePolicies.py similarity index 100% rename from github/ObjectCapacities/TypePolicies.py rename to github/GithubObjects/ObjectCapacities/TypePolicies.py diff --git a/github/ObjectCapacities/__init__.py b/github/GithubObjects/ObjectCapacities/__init__.py similarity index 100% rename from github/ObjectCapacities/__init__.py rename to github/GithubObjects/ObjectCapacities/__init__.py diff --git a/github/Organization.py b/github/GithubObjects/Organization.py similarity index 100% rename from github/Organization.py rename to github/GithubObjects/Organization.py diff --git a/github/PullRequest.py b/github/GithubObjects/PullRequest.py similarity index 100% rename from github/PullRequest.py rename to github/GithubObjects/PullRequest.py diff --git a/github/PullRequestComment.py b/github/GithubObjects/PullRequestComment.py similarity index 100% rename from github/PullRequestComment.py rename to github/GithubObjects/PullRequestComment.py diff --git a/github/PullRequestFile.py b/github/GithubObjects/PullRequestFile.py similarity index 100% rename from github/PullRequestFile.py rename to github/GithubObjects/PullRequestFile.py diff --git a/github/Repository.py b/github/GithubObjects/Repository.py similarity index 100% rename from github/Repository.py rename to github/GithubObjects/Repository.py diff --git a/github/RepositoryKey.py b/github/GithubObjects/RepositoryKey.py similarity index 100% rename from github/RepositoryKey.py rename to github/GithubObjects/RepositoryKey.py diff --git a/github/Tag.py b/github/GithubObjects/Tag.py similarity index 100% rename from github/Tag.py rename to github/GithubObjects/Tag.py diff --git a/github/Team.py b/github/GithubObjects/Team.py similarity index 100% rename from github/Team.py rename to github/GithubObjects/Team.py diff --git a/github/UserKey.py b/github/GithubObjects/UserKey.py similarity index 100% rename from github/UserKey.py rename to github/GithubObjects/UserKey.py diff --git a/github/GithubObjects.py b/github/GithubObjects/__init__.py similarity index 100% rename from github/GithubObjects.py rename to github/GithubObjects/__init__.py From 69cc298fd159f19eb204dd09f17d31dc4abc3d41 Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Wed, 14 Mar 2012 22:55:06 +0100 Subject: [PATCH 2/5] Make sure only three class definitions are distributed --- ReferenceOfClasses.md | 38 +++--- github/GenerateDocumentation.py | 1 - github/GithubObjects/AuthenticatedUser.py | 30 +++++ github/GithubObjects/Event.py | 9 +- github/GithubObjects/NamedUser.py | 23 ---- github/GithubObjects/Organization.py | 4 - github/GithubObjects/Repository.py | 15 --- github/GithubObjects/__init__.py | 152 ++++++++++++---------- 8 files changed, 143 insertions(+), 129 deletions(-) diff --git a/ReferenceOfClasses.md b/ReferenceOfClasses.md index b050afdf..5c47e16d 100644 --- a/ReferenceOfClasses.md +++ b/ReferenceOfClasses.md @@ -549,16 +549,6 @@ Attributes * `owned_private_repos` * `private_gists` -Events ------- -* `get_events()`: list of `Event` -* `get_public_events()`: list of `Event` - -Received events ---------------- -* `get_received_events()`: list of `Event` -* `get_public_received_events()`: list of `Event` - Followers --------- * `get_followers()`: list of `NamedUser` @@ -571,6 +561,16 @@ Orgs ---- * `get_orgs()`: list of `Organization` +Events +------ +* `get_events()`: list of `Event` +* `get_public_events()`: list of `Event` + +Received events +--------------- +* `get_received_events()`: list of `Event` +* `get_public_received_events()`: list of `Event` + Repos ----- * `get_repos( [type] )`: list of `Repository` @@ -636,10 +636,6 @@ Members * `has_in_members( member )`: bool * `member`: `NamedUser` -Events ------- -* `get_events()`: list of `Event` - Repos ----- * `get_repos( [type] )`: list of `Repository` @@ -655,6 +651,10 @@ Teams * `get_teams()`: list of `Team` * `create_team( name, [repo_names, permission] )`: `Team` +Events +------ +* `get_events()`: list of `Event` + Class `PullRequest` =================== @@ -782,11 +782,6 @@ Attributes * `parent`: `Repository` * `source`: `Repository` -Events ------- -* `get_events()`: list of `Event` -* `get_network_events()`: list of `Event` - Issues events ------------- * `get_issues_events()`: list of `IssueEvent` @@ -912,6 +907,11 @@ Teams ----- * `get_teams()`: list of `Team` +Events +------ +* `get_events()`: list of `Event` +* `get_network_events()`: list of `Event` + Class `RepositoryKey` ===================== diff --git a/github/GenerateDocumentation.py b/github/GenerateDocumentation.py index 3c784671..eff4441b 100644 --- a/github/GenerateDocumentation.py +++ b/github/GenerateDocumentation.py @@ -1,6 +1,5 @@ #!/bin/env python -import GithubObject import GithubObjects def generateDocumentation(): diff --git a/github/GithubObjects/AuthenticatedUser.py b/github/GithubObjects/AuthenticatedUser.py index c7762ed1..0826c8ff 100644 --- a/github/GithubObjects/AuthenticatedUser.py +++ b/github/GithubObjects/AuthenticatedUser.py @@ -5,6 +5,8 @@ from UserKey import UserKey from Event import Event from NamedUser import NamedUser from Organization import Organization +from Repository import Repository +from Gist import Gist def __getOrganizationEvents( user, org ): return [ @@ -13,6 +15,16 @@ def __getOrganizationEvents( user, org ): in user._github._dataRequest( "GET", "/users/" + user.login + "/events/orgs/" + org.login, None, None ) ] +def __createFork( user, repo ): + assert isinstance( repo, Repository ) + return Repository( user._github, user._github._dataRequest( "POST", repo._baseUrl() + "/forks", None, None ), lazy = True ) + +def __getStaredGists( user ): + return [ + Gist( user._github, attributes, lazy = True ) + for attributes in user._github._dataRequest( "GET", "/gists/starred", None, None ) + ] + AuthenticatedUser = GithubObject( "AuthenticatedUser", BaseUrl( lambda obj: "/user" ), @@ -58,4 +70,22 @@ AuthenticatedUser = GithubObject( ListGetable( [], [] ) ), MethodFromCallable( "get_organization_events", [ "org" ], [], __getOrganizationEvents, SimpleTypePolicy( "list of `Event`" ) ), + ExternalListOfObjects( "repos", "repo", Repository, + ListGetable( [], [ "type" ] ), + ElementGetable( [ "name" ], [], { "owner" : lambda user: { "login": user.login } } ), + ElementCreatable( [ "name" ], [ "description", "homepage", "private", "has_issues", "has_wiki", "has_downloads", "team_id", ] ) + ), + ExternalListOfObjects( "watched", "watched", Repository, + ListGetable( [], [] ), + ElementAddable(), + ElementRemovable(), + ElementHasable() + ), + SeveralAttributePolicies( [ MethodFromCallable( "create_fork", [ "repo" ], [], __createFork, ObjectTypePolicy( Repository ) ) ], "Forking" ), + ExternalListOfObjects( "gists", "gist", Gist, + ListGetable( [], [] ), + ElementCreatable( [ "public", "files", ], [ "description" ] ), + url = "/gists", + ), + MethodFromCallable( "get_starred_gists", [], [], __getStaredGists, SimpleTypePolicy( "list of `Gist`" ) ), ) diff --git a/github/GithubObjects/Event.py b/github/GithubObjects/Event.py index ba568058..f2f80853 100644 --- a/github/GithubObjects/Event.py +++ b/github/GithubObjects/Event.py @@ -1,9 +1,16 @@ from GithubObject import * +from Repository import Repository +from NamedUser import NamedUser +from Organization import Organization + Event = GithubObject( "Event", InternalSimpleAttributes( "type", "public", "payload", "created_at", "id", "commit_id", "url", "event", "issue", ), -) + InternalObjectAttribute( "repo", Repository ), + InternalObjectAttribute( "actor", NamedUser ), + InternalObjectAttribute( "org", Organization ), +) \ No newline at end of file diff --git a/github/GithubObjects/NamedUser.py b/github/GithubObjects/NamedUser.py index 0d28b88c..335f8be0 100644 --- a/github/GithubObjects/NamedUser.py +++ b/github/GithubObjects/NamedUser.py @@ -1,20 +1,5 @@ from GithubObject import * -from Event import Event - -def __getPublicEvents( user ): - return [ - Event( user._github, attributes, lazy = True ) - for attributes - in user._github._dataRequest( "GET", user._baseUrl() + "/events/public", None, None ) - ] - -def __getPublicReceivedEvents( user ): - return [ - Event( user._github, attributes, lazy = True ) - for attributes - in user._github._dataRequest( "GET", user._baseUrl() + "/received_events/public", None, None ) - ] NamedUser = GithubObject( "NamedUser", @@ -31,14 +16,6 @@ NamedUser = GithubObject( "disk_usage", "collaborators", "plan", "total_private_repos", "owned_private_repos", "private_gists", ), - ExternalListOfObjects( "events", "event", Event, - ListGetable( [], [] ) - ), - MethodFromCallable( "get_public_events", [], [], __getPublicEvents, SimpleTypePolicy( "list of `Event`" ) ), - ExternalListOfObjects( "received_events", "received_event", Event, - ListGetable( [], [] ) - ), - MethodFromCallable( "get_public_received_events", [], [], __getPublicReceivedEvents, SimpleTypePolicy( "list of `Event`" ) ), ) NamedUser._addAttributePolicy( diff --git a/github/GithubObjects/Organization.py b/github/GithubObjects/Organization.py index 5be8e67b..c257c10b 100644 --- a/github/GithubObjects/Organization.py +++ b/github/GithubObjects/Organization.py @@ -1,7 +1,6 @@ from GithubObject import * from NamedUser import NamedUser -from Event import Event Organization = GithubObject( "Organization", @@ -27,7 +26,4 @@ Organization = GithubObject( ElementRemovable(), ElementHasable() ), - ExternalListOfObjects( "events", "event", Event, - ListGetable( [], [] ) - ), ) diff --git a/github/GithubObjects/Repository.py b/github/GithubObjects/Repository.py index c5d702db..80f73920 100644 --- a/github/GithubObjects/Repository.py +++ b/github/GithubObjects/Repository.py @@ -1,7 +1,6 @@ from GithubObject import * from NamedUser import NamedUser -from Event import Event from IssueEvent import IssueEvent from RepositoryKey import RepositoryKey from Hook import Hook @@ -39,20 +38,6 @@ Repository = GithubObject( ) Repository._addAttributePolicy( InternalObjectAttribute( "parent", Repository ) ) Repository._addAttributePolicy( InternalObjectAttribute( "source", Repository ) ) -Repository._addAttributePolicy( - ExternalListOfObjects( "events", "event", Event, - ListGetable( [], [] ) - ), -) -def __getNetworkEvents( repo ): - return [ - Event( repo._github, attributes, lazy = True ) - for attributes - in repo._github._dataRequest( "GET", "/networks/" + repo.owner.login + "/" + repo.name + "/events", None, None ) - ] -Repository._addAttributePolicy( - MethodFromCallable( "get_network_events", [], [], __getNetworkEvents, SimpleTypePolicy( "list of `Event`" ) ) -) Repository._addAttributePolicy( ExternalListOfObjects( "issues/events", "issues_event", IssueEvent, ListGetable( [], [], __modifyAttributesForObjectsReferingRepo ), diff --git a/github/GithubObjects/__init__.py b/github/GithubObjects/__init__.py index 01619561..35af54f2 100644 --- a/github/GithubObjects/__init__.py +++ b/github/GithubObjects/__init__.py @@ -31,58 +31,109 @@ from Team import Team from GistComment import GistComment from Gist import Gist +#### Complete NamedUser + NamedUser._addAttributePolicy( ExternalListOfObjects( "orgs", "org", Organization, ListGetable( [], [] ) ) ) -__repoElementCreatable = ElementCreatable( [ "name" ], [ "description", "homepage", "private", "has_issues", "has_wiki", "has_downloads", "team_id", ] ) -__repoElementGetable = ElementGetable( [ "name" ], [], { "owner" : lambda user: { "login": user.login } } ) -__repoListGetable = ListGetable( [], [ "type" ] ) -AuthenticatedUser._addAttributePolicy( - ExternalListOfObjects( "repos", "repo", Repository, - __repoListGetable, - __repoElementGetable, - __repoElementCreatable - ) -) NamedUser._addAttributePolicy( - ExternalListOfObjects( "repos", "repo", Repository, - __repoListGetable, - __repoElementGetable - ) -) -Organization._addAttributePolicy( - ExternalListOfObjects( "repos", "repo", Repository, - __repoListGetable, - __repoElementGetable, - __repoElementCreatable + ExternalListOfObjects( "events", "event", Event, + ListGetable( [], [] ) ) ) -AuthenticatedUser._addAttributePolicy( - ExternalListOfObjects( "watched", "watched", Repository, - ListGetable( [], [] ), - ElementAddable(), - ElementRemovable(), - ElementHasable() +def __getPublicEvents( user ): + return [ + Event( user._github, attributes, lazy = True ) + for attributes + in user._github._dataRequest( "GET", user._baseUrl() + "/events/public", None, None ) + ] + +NamedUser._addAttributePolicy( + MethodFromCallable( "get_public_events", [], [], __getPublicEvents, SimpleTypePolicy( "list of `Event`" ) ) +) + +NamedUser._addAttributePolicy( + ExternalListOfObjects( "received_events", "received_event", Event, + ListGetable( [], [] ) ) ) + +def __getPublicReceivedEvents( user ): + return [ + Event( user._github, attributes, lazy = True ) + for attributes + in user._github._dataRequest( "GET", user._baseUrl() + "/received_events/public", None, None ) + ] + +NamedUser._addAttributePolicy( + MethodFromCallable( "get_public_received_events", [], [], __getPublicReceivedEvents, SimpleTypePolicy( "list of `Event`" ) ) +) + +NamedUser._addAttributePolicy( + ExternalListOfObjects( "repos", "repo", Repository, + ListGetable( [], [ "type" ] ), + ElementGetable( [ "name" ], [], { "owner" : lambda user: { "login": user.login } } ) + ) +) + NamedUser._addAttributePolicy( ExternalListOfObjects( "watched", "watched", Repository, ListGetable( [], [] ) ) ) -def __createForkForUser( user, repo ): - assert isinstance( repo, Repository ) - return Repository( user._github, user._github._dataRequest( "POST", repo._baseUrl() + "/forks", None, None ), lazy = True ) -AuthenticatedUser._addAttributePolicy( SeveralAttributePolicies( [ MethodFromCallable( "create_fork", [ "repo" ], [], __createForkForUser, ObjectTypePolicy( Repository ) ) ], "Forking" ) ) +NamedUser._addAttributePolicy( + ExternalListOfObjects( "gists", "gist", Gist, + ListGetable( [], [] ), + ) +) + +#### Complete Repository + +Repository._addAttributePolicy( + ExternalListOfObjects( "teams", "team", Team, + ListGetable( [], [] ) + ) +) + +Repository._addAttributePolicy( + ExternalListOfObjects( "events", "event", Event, + ListGetable( [], [] ) + ), +) + +def __getNetworkEvents( repo ): + return [ + Event( repo._github, attributes, lazy = True ) + for attributes + in repo._github._dataRequest( "GET", "/networks/" + repo.owner.login + "/" + repo.name + "/events", None, None ) + ] + +Repository._addAttributePolicy( + MethodFromCallable( "get_network_events", [], [], __getNetworkEvents, SimpleTypePolicy( "list of `Event`" ) ) +) + +#### Complete Organization + +Organization._addAttributePolicy( + ExternalListOfObjects( "repos", "repo", Repository, + ListGetable( [], [ "type" ] ), + ElementGetable( [ "name" ], [], { "owner" : lambda user: { "login": user.login } } ), + ElementCreatable( [ "name" ], [ "description", "homepage", "private", "has_issues", "has_wiki", "has_downloads", "team_id", ] ) + ) +) + def __createForkForOrg( org, repo ): assert isinstance( repo, Repository ) return Repository( org._github, org._github._dataRequest( "POST", repo._baseUrl() + "/forks", { "org": org.login }, None ), lazy = True ) -Organization._addAttributePolicy( SeveralAttributePolicies( [ MethodFromCallable( "create_fork", [ "repo" ], [], __createForkForOrg, ObjectTypePolicy( Repository ) ) ], "Forking" ) ) + +Organization._addAttributePolicy( + SeveralAttributePolicies( [ MethodFromCallable( "create_fork", [ "repo" ], [], __createForkForOrg, ObjectTypePolicy( Repository ) ) ], "Forking" ) +) Organization._addAttributePolicy( ExternalListOfObjects( "teams", "team", Team, @@ -90,40 +141,9 @@ Organization._addAttributePolicy( ElementCreatable( [ "name" ], [ "repo_names", "permission" ] ) ) ) -Repository._addAttributePolicy( - ExternalListOfObjects( "teams", "team", Team, + +Organization._addAttributePolicy( + ExternalListOfObjects( "events", "event", Event, ListGetable( [], [] ) - ) -) - -NamedUser._addAttributePolicy( - ExternalListOfObjects( "gists", "gist", Gist, - ListGetable( [], [] ), - ) -) - -AuthenticatedUser._addAttributePolicy( - ExternalListOfObjects( "gists", "gist", Gist, - ListGetable( [], [] ), - ElementCreatable( [ "public", "files", ], [ "description" ] ), - url = "/gists", - ) -) -def __getStaredGists( user ): - return [ - Gist( user._github, attributes, lazy = True ) - for attributes in user._github._dataRequest( "GET", "/gists/starred", None, None ) - ] -AuthenticatedUser._addAttributePolicy( - MethodFromCallable( "get_starred_gists", [], [], __getStaredGists, SimpleTypePolicy( "list of `Gist`" ) ), -) - -Event._addAttributePolicy( - InternalObjectAttribute( "repo", Repository ), -) -Event._addAttributePolicy( - InternalObjectAttribute( "actor", NamedUser ), -) -Event._addAttributePolicy( - InternalObjectAttribute( "org", Organization ), + ), ) From 8213df1d744f251aa8e52229643a9f6ce352f3c0 Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Wed, 14 Mar 2012 23:07:21 +0100 Subject: [PATCH 3/5] Simplify internal imports --- github/GithubObjects/AuthenticatedUser.py | 16 ++++----- github/GithubObjects/Branch.py | 4 +-- github/GithubObjects/Commit.py | 8 ++--- github/GithubObjects/CommitComment.py | 4 +-- github/GithubObjects/Event.py | 8 ++--- github/GithubObjects/Gist.py | 6 ++-- github/GithubObjects/GistComment.py | 4 +-- github/GithubObjects/GitCommit.py | 4 +-- github/GithubObjects/Issue.py | 12 +++---- github/GithubObjects/IssueComment.py | 4 +-- github/GithubObjects/IssueEvent.py | 4 +-- github/GithubObjects/Milestone.py | 6 ++-- github/GithubObjects/NamedUser.py | 1 - github/GithubObjects/Organization.py | 4 +-- github/GithubObjects/PullRequest.py | 10 +++--- github/GithubObjects/PullRequestComment.py | 4 +-- github/GithubObjects/Repository.py | 38 ++++++++++------------ github/GithubObjects/Tag.py | 4 +-- github/GithubObjects/Team.py | 6 ++-- github/GithubObjects/__init__.py | 36 ++++---------------- 20 files changed, 61 insertions(+), 122 deletions(-) diff --git a/github/GithubObjects/AuthenticatedUser.py b/github/GithubObjects/AuthenticatedUser.py index 0826c8ff..2a48a033 100644 --- a/github/GithubObjects/AuthenticatedUser.py +++ b/github/GithubObjects/AuthenticatedUser.py @@ -1,12 +1,10 @@ -from GithubObject import * - -from Authorization import Authorization -from UserKey import UserKey -from Event import Event -from NamedUser import NamedUser -from Organization import Organization -from Repository import Repository -from Gist import Gist +from Authorization import * +from UserKey import * +from Event import * +from NamedUser import * +from Organization import * +from Repository import * +from Gist import * def __getOrganizationEvents( user, org ): return [ diff --git a/github/GithubObjects/Branch.py b/github/GithubObjects/Branch.py index 840a4d62..30fbebc5 100644 --- a/github/GithubObjects/Branch.py +++ b/github/GithubObjects/Branch.py @@ -1,6 +1,4 @@ -from GithubObject import * - -from Commit import Commit +from Commit import * Branch = GithubObject( "Branch", diff --git a/github/GithubObjects/Commit.py b/github/GithubObjects/Commit.py index 992087e1..8d92597b 100644 --- a/github/GithubObjects/Commit.py +++ b/github/GithubObjects/Commit.py @@ -1,8 +1,6 @@ -from GithubObject import * - -from GitCommit import GitCommit -from NamedUser import NamedUser -from CommitComment import CommitComment +from GitCommit import * +from NamedUser import * +from CommitComment import * __modifyAttributesForObjectsReferingReferedRepo = { "_repo": lambda obj: obj._repo } diff --git a/github/GithubObjects/CommitComment.py b/github/GithubObjects/CommitComment.py index d51c912f..9d38fe34 100644 --- a/github/GithubObjects/CommitComment.py +++ b/github/GithubObjects/CommitComment.py @@ -1,6 +1,4 @@ -from GithubObject import * - -from NamedUser import NamedUser +from NamedUser import * CommitComment = GithubObject( "CommitComment", diff --git a/github/GithubObjects/Event.py b/github/GithubObjects/Event.py index f2f80853..1cdb4e96 100644 --- a/github/GithubObjects/Event.py +++ b/github/GithubObjects/Event.py @@ -1,8 +1,6 @@ -from GithubObject import * - -from Repository import Repository -from NamedUser import NamedUser -from Organization import Organization +from Repository import * +from NamedUser import * +from Organization import * Event = GithubObject( "Event", diff --git a/github/GithubObjects/Gist.py b/github/GithubObjects/Gist.py index 6d029282..9ce601c0 100644 --- a/github/GithubObjects/Gist.py +++ b/github/GithubObjects/Gist.py @@ -1,7 +1,5 @@ -from GithubObject import * - -from NamedUser import NamedUser -from GistComment import GistComment +from NamedUser import * +from GistComment import * def __isStarred( gist ): return gist._github._statusRequest( "GET", gist._baseUrl() + "/star", None, None ) == 204 diff --git a/github/GithubObjects/GistComment.py b/github/GithubObjects/GistComment.py index ae493f7c..88fd3b3b 100644 --- a/github/GithubObjects/GistComment.py +++ b/github/GithubObjects/GistComment.py @@ -1,6 +1,4 @@ -from GithubObject import * - -from NamedUser import NamedUser +from NamedUser import * GistComment = GithubObject( "GistComment", diff --git a/github/GithubObjects/GitCommit.py b/github/GithubObjects/GitCommit.py index aebaa599..c9aa31c2 100644 --- a/github/GithubObjects/GitCommit.py +++ b/github/GithubObjects/GitCommit.py @@ -1,6 +1,4 @@ -from GithubObject import * - -from GitTree import GitTree +from GitTree import * GitCommit = GithubObject( "GitCommit", diff --git a/github/GithubObjects/Issue.py b/github/GithubObjects/Issue.py index f03e69bf..92ae7365 100644 --- a/github/GithubObjects/Issue.py +++ b/github/GithubObjects/Issue.py @@ -1,10 +1,8 @@ -from GithubObject import * - -from NamedUser import NamedUser -from Milestone import Milestone -from Label import Label -from IssueComment import IssueComment -from IssueEvent import IssueEvent +from NamedUser import * +from Milestone import * +from Label import * +from IssueComment import * +from IssueEvent import * __modifyAttributesForObjectsReferingReferedRepo = { "_repo": lambda obj: obj._repo } diff --git a/github/GithubObjects/IssueComment.py b/github/GithubObjects/IssueComment.py index d22ff923..43c306a5 100644 --- a/github/GithubObjects/IssueComment.py +++ b/github/GithubObjects/IssueComment.py @@ -1,6 +1,4 @@ -from GithubObject import * - -from NamedUser import NamedUser +from NamedUser import * IssueComment = GithubObject( "IssueComment", diff --git a/github/GithubObjects/IssueEvent.py b/github/GithubObjects/IssueEvent.py index 88f0d482..c5b6fd29 100644 --- a/github/GithubObjects/IssueEvent.py +++ b/github/GithubObjects/IssueEvent.py @@ -1,6 +1,4 @@ -from GithubObject import * - -from NamedUser import NamedUser +from NamedUser import * IssueEvent = GithubObject( "IssueEvent", diff --git a/github/GithubObjects/Milestone.py b/github/GithubObjects/Milestone.py index a2531c93..b1ac5ef4 100644 --- a/github/GithubObjects/Milestone.py +++ b/github/GithubObjects/Milestone.py @@ -1,7 +1,5 @@ -from GithubObject import * - -from NamedUser import NamedUser -from Label import Label +from NamedUser import * +from Label import * __modifyAttributesForObjectsReferingReferedRepo = { "_repo": lambda obj: obj._repo } diff --git a/github/GithubObjects/NamedUser.py b/github/GithubObjects/NamedUser.py index 335f8be0..434f9299 100644 --- a/github/GithubObjects/NamedUser.py +++ b/github/GithubObjects/NamedUser.py @@ -1,6 +1,5 @@ from GithubObject import * - NamedUser = GithubObject( "NamedUser", BaseUrl( lambda obj: "/users/" + obj.login ), diff --git a/github/GithubObjects/Organization.py b/github/GithubObjects/Organization.py index c257c10b..7a63f2ac 100644 --- a/github/GithubObjects/Organization.py +++ b/github/GithubObjects/Organization.py @@ -1,6 +1,4 @@ -from GithubObject import * - -from NamedUser import NamedUser +from NamedUser import * Organization = GithubObject( "Organization", diff --git a/github/GithubObjects/PullRequest.py b/github/GithubObjects/PullRequest.py index a8947a62..3357e72d 100644 --- a/github/GithubObjects/PullRequest.py +++ b/github/GithubObjects/PullRequest.py @@ -1,9 +1,7 @@ -from GithubObject import * - -from NamedUser import NamedUser -from Commit import Commit -from PullRequestFile import PullRequestFile -from PullRequestComment import PullRequestComment +from NamedUser import * +from Commit import * +from PullRequestFile import * +from PullRequestComment import * __modifyAttributesForObjectsReferingReferedRepo = { "_repo": lambda obj: obj._repo } diff --git a/github/GithubObjects/PullRequestComment.py b/github/GithubObjects/PullRequestComment.py index 2985d92d..14d7ac6c 100644 --- a/github/GithubObjects/PullRequestComment.py +++ b/github/GithubObjects/PullRequestComment.py @@ -1,6 +1,4 @@ -from GithubObject import * - -from NamedUser import NamedUser +from NamedUser import * PullRequestComment = GithubObject( "PullRequestComment", diff --git a/github/GithubObjects/Repository.py b/github/GithubObjects/Repository.py index 80f73920..b1c8400d 100644 --- a/github/GithubObjects/Repository.py +++ b/github/GithubObjects/Repository.py @@ -1,23 +1,21 @@ -from GithubObject import * - -from NamedUser import NamedUser -from IssueEvent import IssueEvent -from RepositoryKey import RepositoryKey -from Hook import Hook -from GitBlob import GitBlob -from GitCommit import GitCommit -from GitRef import GitRef -from GitTag import GitTag -from GitTree import GitTree -from Label import Label -from Milestone import Milestone -from Issue import Issue -from Download import Download -from CommitComment import CommitComment -from Commit import Commit -from Tag import Tag -from Branch import Branch -from PullRequest import PullRequest +from NamedUser import * +from IssueEvent import * +from RepositoryKey import * +from Hook import * +from GitBlob import * +from GitCommit import * +from GitRef import * +from GitTag import * +from GitTree import * +from Label import * +from Milestone import * +from Issue import * +from Download import * +from CommitComment import * +from Commit import * +from Tag import * +from Branch import * +from PullRequest import * __modifyAttributesForObjectsReferingRepo = { "_repo": lambda repo: repo } diff --git a/github/GithubObjects/Tag.py b/github/GithubObjects/Tag.py index c04015da..cd65493d 100644 --- a/github/GithubObjects/Tag.py +++ b/github/GithubObjects/Tag.py @@ -1,6 +1,4 @@ -from GithubObject import * - -from Commit import Commit +from Commit import * Tag = GithubObject( "Tag", diff --git a/github/GithubObjects/Team.py b/github/GithubObjects/Team.py index 7cc9de62..4bd62e66 100644 --- a/github/GithubObjects/Team.py +++ b/github/GithubObjects/Team.py @@ -1,7 +1,5 @@ -from GithubObject import * - -from NamedUser import NamedUser -from Repository import Repository +from NamedUser import * +from Repository import * Team = GithubObject( "Team", diff --git a/github/GithubObjects/__init__.py b/github/GithubObjects/__init__.py index 35af54f2..4abe6c9b 100644 --- a/github/GithubObjects/__init__.py +++ b/github/GithubObjects/__init__.py @@ -1,35 +1,11 @@ from GithubObject import * -from Event import Event -from Hook import Hook -from Authorization import Authorization -from UserKey import UserKey -from AuthenticatedUser import AuthenticatedUser -from NamedUser import NamedUser -from Organization import Organization -from GitRef import GitRef -from GitTree import GitTree -from GitCommit import GitCommit -from GitBlob import GitBlob -from GitTag import GitTag -from Label import Label -from Milestone import Milestone -from IssueComment import IssueComment -from IssueEvent import IssueEvent -from Issue import Issue -from Download import Download -from CommitComment import CommitComment -from Commit import Commit -from Tag import Tag -from Branch import Branch -from PullRequestFile import PullRequestFile -from PullRequestComment import PullRequestComment -from PullRequest import PullRequest -from RepositoryKey import RepositoryKey -from Repository import Repository -from Team import Team -from GistComment import GistComment -from Gist import Gist +from AuthenticatedUser import * +from NamedUser import * +from Organization import * +from Repository import * +from Gist import * +from Team import * #### Complete NamedUser From 32ed0ebc377efbed5b482b3d49ff54bf1715d55a Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Wed, 14 Mar 2012 23:13:37 +0100 Subject: [PATCH 4/5] Move GithubObject --- .../ArgumentsChecker.py | 0 .../{ObjectCapacities => GithubObject}/Basic.py | 0 .../{ => GithubObject}/GithubObject.UnitTest.py | 0 github/GithubObjects/{ => GithubObject}/GithubObject.py | 8 ++++---- .../{ObjectCapacities => GithubObject}/List.py | 0 .../{ObjectCapacities => GithubObject}/TypePolicies.py | 0 github/GithubObjects/GithubObject/__init__.py | 1 + github/GithubObjects/ObjectCapacities/__init__.py | 0 8 files changed, 5 insertions(+), 4 deletions(-) rename github/GithubObjects/{ObjectCapacities => GithubObject}/ArgumentsChecker.py (100%) rename github/GithubObjects/{ObjectCapacities => GithubObject}/Basic.py (100%) rename github/GithubObjects/{ => GithubObject}/GithubObject.UnitTest.py (100%) rename github/GithubObjects/{ => GithubObject}/GithubObject.py (96%) rename github/GithubObjects/{ObjectCapacities => GithubObject}/List.py (100%) rename github/GithubObjects/{ObjectCapacities => GithubObject}/TypePolicies.py (100%) create mode 100644 github/GithubObjects/GithubObject/__init__.py delete mode 100644 github/GithubObjects/ObjectCapacities/__init__.py diff --git a/github/GithubObjects/ObjectCapacities/ArgumentsChecker.py b/github/GithubObjects/GithubObject/ArgumentsChecker.py similarity index 100% rename from github/GithubObjects/ObjectCapacities/ArgumentsChecker.py rename to github/GithubObjects/GithubObject/ArgumentsChecker.py diff --git a/github/GithubObjects/ObjectCapacities/Basic.py b/github/GithubObjects/GithubObject/Basic.py similarity index 100% rename from github/GithubObjects/ObjectCapacities/Basic.py rename to github/GithubObjects/GithubObject/Basic.py diff --git a/github/GithubObjects/GithubObject.UnitTest.py b/github/GithubObjects/GithubObject/GithubObject.UnitTest.py similarity index 100% rename from github/GithubObjects/GithubObject.UnitTest.py rename to github/GithubObjects/GithubObject/GithubObject.UnitTest.py diff --git a/github/GithubObjects/GithubObject.py b/github/GithubObjects/GithubObject/GithubObject.py similarity index 96% rename from github/GithubObjects/GithubObject.py rename to github/GithubObjects/GithubObject/GithubObject.py index 00d61745..023509b9 100644 --- a/github/GithubObjects/GithubObject.py +++ b/github/GithubObjects/GithubObject/GithubObject.py @@ -1,9 +1,9 @@ import itertools -from ObjectCapacities.ArgumentsChecker import * -from ObjectCapacities.Basic import * -from ObjectCapacities.List import * -from ObjectCapacities.TypePolicies import * +from ArgumentsChecker import * +from Basic import * +from List import * +from TypePolicies import * class BadGithubObjectException( Exception ): pass diff --git a/github/GithubObjects/ObjectCapacities/List.py b/github/GithubObjects/GithubObject/List.py similarity index 100% rename from github/GithubObjects/ObjectCapacities/List.py rename to github/GithubObjects/GithubObject/List.py diff --git a/github/GithubObjects/ObjectCapacities/TypePolicies.py b/github/GithubObjects/GithubObject/TypePolicies.py similarity index 100% rename from github/GithubObjects/ObjectCapacities/TypePolicies.py rename to github/GithubObjects/GithubObject/TypePolicies.py diff --git a/github/GithubObjects/GithubObject/__init__.py b/github/GithubObjects/GithubObject/__init__.py new file mode 100644 index 00000000..cbc7e4d6 --- /dev/null +++ b/github/GithubObjects/GithubObject/__init__.py @@ -0,0 +1 @@ +from GithubObject import * diff --git a/github/GithubObjects/ObjectCapacities/__init__.py b/github/GithubObjects/ObjectCapacities/__init__.py deleted file mode 100644 index e69de29b..00000000 From 6e421e9e85e12008758870bc046bc2c6120af72a Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Wed, 14 Mar 2012 23:24:49 +0100 Subject: [PATCH 5/5] Separate the three distributed classes --- github/GithubObjects/NamedUser_complete.py | 65 +++++++++ github/GithubObjects/Organization_complete.py | 34 +++++ github/GithubObjects/Repository_complete.py | 27 ++++ github/GithubObjects/__init__.py | 128 ++---------------- 4 files changed, 134 insertions(+), 120 deletions(-) create mode 100644 github/GithubObjects/NamedUser_complete.py create mode 100644 github/GithubObjects/Organization_complete.py create mode 100644 github/GithubObjects/Repository_complete.py diff --git a/github/GithubObjects/NamedUser_complete.py b/github/GithubObjects/NamedUser_complete.py new file mode 100644 index 00000000..4500ac75 --- /dev/null +++ b/github/GithubObjects/NamedUser_complete.py @@ -0,0 +1,65 @@ +from NamedUser import * + +from Organization import * +from Event import * +from Repository import * +from Gist import * + +NamedUser._addAttributePolicy( + ExternalListOfObjects( "orgs", "org", Organization, + ListGetable( [], [] ) + ) +) + +NamedUser._addAttributePolicy( + ExternalListOfObjects( "events", "event", Event, + ListGetable( [], [] ) + ) +) + +def __getPublicEvents( user ): + return [ + Event( user._github, attributes, lazy = True ) + for attributes + in user._github._dataRequest( "GET", user._baseUrl() + "/events/public", None, None ) + ] + +NamedUser._addAttributePolicy( + MethodFromCallable( "get_public_events", [], [], __getPublicEvents, SimpleTypePolicy( "list of `Event`" ) ) +) + +NamedUser._addAttributePolicy( + ExternalListOfObjects( "received_events", "received_event", Event, + ListGetable( [], [] ) + ) +) + +def __getPublicReceivedEvents( user ): + return [ + Event( user._github, attributes, lazy = True ) + for attributes + in user._github._dataRequest( "GET", user._baseUrl() + "/received_events/public", None, None ) + ] + +NamedUser._addAttributePolicy( + MethodFromCallable( "get_public_received_events", [], [], __getPublicReceivedEvents, SimpleTypePolicy( "list of `Event`" ) ) +) + +NamedUser._addAttributePolicy( + ExternalListOfObjects( "repos", "repo", Repository, + ListGetable( [], [ "type" ] ), + ElementGetable( [ "name" ], [], { "owner" : lambda user: { "login": user.login } } ) + ) +) + +NamedUser._addAttributePolicy( + ExternalListOfObjects( "watched", "watched", Repository, + ListGetable( [], [] ) + ) +) + +NamedUser._addAttributePolicy( + ExternalListOfObjects( "gists", "gist", Gist, + ListGetable( [], [] ), + ) +) diff --git a/github/GithubObjects/Organization_complete.py b/github/GithubObjects/Organization_complete.py new file mode 100644 index 00000000..98178096 --- /dev/null +++ b/github/GithubObjects/Organization_complete.py @@ -0,0 +1,34 @@ +from Organization import * + +from Repository import * +from Team import * +from Event import * + +Organization._addAttributePolicy( + ExternalListOfObjects( "repos", "repo", Repository, + ListGetable( [], [ "type" ] ), + ElementGetable( [ "name" ], [], { "owner" : lambda user: { "login": user.login } } ), + ElementCreatable( [ "name" ], [ "description", "homepage", "private", "has_issues", "has_wiki", "has_downloads", "team_id", ] ) + ) +) + +def __createForkForOrg( org, repo ): + assert isinstance( repo, Repository ) + return Repository( org._github, org._github._dataRequest( "POST", repo._baseUrl() + "/forks", { "org": org.login }, None ), lazy = True ) + +Organization._addAttributePolicy( + SeveralAttributePolicies( [ MethodFromCallable( "create_fork", [ "repo" ], [], __createForkForOrg, ObjectTypePolicy( Repository ) ) ], "Forking" ) +) + +Organization._addAttributePolicy( + ExternalListOfObjects( "teams", "team", Team, + ListGetable( [], [] ), + ElementCreatable( [ "name" ], [ "repo_names", "permission" ] ) + ) +) + +Organization._addAttributePolicy( + ExternalListOfObjects( "events", "event", Event, + ListGetable( [], [] ) + ), +) diff --git a/github/GithubObjects/Repository_complete.py b/github/GithubObjects/Repository_complete.py new file mode 100644 index 00000000..fb7d4e95 --- /dev/null +++ b/github/GithubObjects/Repository_complete.py @@ -0,0 +1,27 @@ +from Repository import * + +from Team import * +from Event import * + +Repository._addAttributePolicy( + ExternalListOfObjects( "teams", "team", Team, + ListGetable( [], [] ) + ) +) + +Repository._addAttributePolicy( + ExternalListOfObjects( "events", "event", Event, + ListGetable( [], [] ) + ), +) + +def __getNetworkEvents( repo ): + return [ + Event( repo._github, attributes, lazy = True ) + for attributes + in repo._github._dataRequest( "GET", "/networks/" + repo.owner.login + "/" + repo.name + "/events", None, None ) + ] + +Repository._addAttributePolicy( + MethodFromCallable( "get_network_events", [], [], __getNetworkEvents, SimpleTypePolicy( "list of `Event`" ) ) +) diff --git a/github/GithubObjects/__init__.py b/github/GithubObjects/__init__.py index 4abe6c9b..e19884f3 100644 --- a/github/GithubObjects/__init__.py +++ b/github/GithubObjects/__init__.py @@ -1,125 +1,13 @@ -from GithubObject import * - from AuthenticatedUser import * + +# This strange import pattern works around cyclic dependencies from NamedUser import * +from NamedUser_complete import * + from Organization import * +from Organization_complete import * + from Repository import * +from Repository_complete import * + from Gist import * -from Team import * - -#### Complete NamedUser - -NamedUser._addAttributePolicy( - ExternalListOfObjects( "orgs", "org", Organization, - ListGetable( [], [] ) - ) -) - -NamedUser._addAttributePolicy( - ExternalListOfObjects( "events", "event", Event, - ListGetable( [], [] ) - ) -) - -def __getPublicEvents( user ): - return [ - Event( user._github, attributes, lazy = True ) - for attributes - in user._github._dataRequest( "GET", user._baseUrl() + "/events/public", None, None ) - ] - -NamedUser._addAttributePolicy( - MethodFromCallable( "get_public_events", [], [], __getPublicEvents, SimpleTypePolicy( "list of `Event`" ) ) -) - -NamedUser._addAttributePolicy( - ExternalListOfObjects( "received_events", "received_event", Event, - ListGetable( [], [] ) - ) -) - -def __getPublicReceivedEvents( user ): - return [ - Event( user._github, attributes, lazy = True ) - for attributes - in user._github._dataRequest( "GET", user._baseUrl() + "/received_events/public", None, None ) - ] - -NamedUser._addAttributePolicy( - MethodFromCallable( "get_public_received_events", [], [], __getPublicReceivedEvents, SimpleTypePolicy( "list of `Event`" ) ) -) - -NamedUser._addAttributePolicy( - ExternalListOfObjects( "repos", "repo", Repository, - ListGetable( [], [ "type" ] ), - ElementGetable( [ "name" ], [], { "owner" : lambda user: { "login": user.login } } ) - ) -) - -NamedUser._addAttributePolicy( - ExternalListOfObjects( "watched", "watched", Repository, - ListGetable( [], [] ) - ) -) - -NamedUser._addAttributePolicy( - ExternalListOfObjects( "gists", "gist", Gist, - ListGetable( [], [] ), - ) -) - -#### Complete Repository - -Repository._addAttributePolicy( - ExternalListOfObjects( "teams", "team", Team, - ListGetable( [], [] ) - ) -) - -Repository._addAttributePolicy( - ExternalListOfObjects( "events", "event", Event, - ListGetable( [], [] ) - ), -) - -def __getNetworkEvents( repo ): - return [ - Event( repo._github, attributes, lazy = True ) - for attributes - in repo._github._dataRequest( "GET", "/networks/" + repo.owner.login + "/" + repo.name + "/events", None, None ) - ] - -Repository._addAttributePolicy( - MethodFromCallable( "get_network_events", [], [], __getNetworkEvents, SimpleTypePolicy( "list of `Event`" ) ) -) - -#### Complete Organization - -Organization._addAttributePolicy( - ExternalListOfObjects( "repos", "repo", Repository, - ListGetable( [], [ "type" ] ), - ElementGetable( [ "name" ], [], { "owner" : lambda user: { "login": user.login } } ), - ElementCreatable( [ "name" ], [ "description", "homepage", "private", "has_issues", "has_wiki", "has_downloads", "team_id", ] ) - ) -) - -def __createForkForOrg( org, repo ): - assert isinstance( repo, Repository ) - return Repository( org._github, org._github._dataRequest( "POST", repo._baseUrl() + "/forks", { "org": org.login }, None ), lazy = True ) - -Organization._addAttributePolicy( - SeveralAttributePolicies( [ MethodFromCallable( "create_fork", [ "repo" ], [], __createForkForOrg, ObjectTypePolicy( Repository ) ) ], "Forking" ) -) - -Organization._addAttributePolicy( - ExternalListOfObjects( "teams", "team", Team, - ListGetable( [], [] ), - ElementCreatable( [ "name" ], [ "repo_names", "permission" ] ) - ) -) - -Organization._addAttributePolicy( - ExternalListOfObjects( "events", "event", Event, - ListGetable( [], [] ) - ), -)