From 6e421e9e85e12008758870bc046bc2c6120af72a Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Wed, 14 Mar 2012 23:24:49 +0100 Subject: [PATCH] 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( [], [] ) - ), -)