This commit is contained in:
Vincent Jacques
2012-05-04 14:02:07 +02:00
parent 3468e9ea1e
commit 229b218ce6
42 changed files with 399 additions and 1586 deletions
+13 -23
View File
@@ -5,15 +5,8 @@ import GithubObjects.Organization
import GithubObjects.Gist
class Github:
def __init__( self, login, password, debugFile = None ):
def __init__( self, login, password ):
self.__requester = Requester( login, password )
self.__debugFile = debugFile
def _dataRequest( self, verb, url, parameters, data ):
return self.__requester.dataRequest( verb, url, parameters, data )
def _statusRequest( self, verb, url, parameters, data ):
return self.__requester.statusRequest( verb, url, parameters, data )
def get_user( self, login = None ):
if login is None:
@@ -21,31 +14,28 @@ class Github:
"url": "https://api.github.com/user",
# "login": self.__login # @todo ?
}
return GithubObjects.AuthenticatedUser.AuthenticatedUser( self, attributes, lazy = True )
return GithubObjects.AuthenticatedUser.AuthenticatedUser( self.__requester, attributes, lazy = True )
else:
attributes = {
"url": "https://api.github.com/users/" + login,
"login": login,
}
return GithubObjects.NamedUser.NamedUser( self, attributes, lazy = False )
return GithubObjects.NamedUser.NamedUser( self.__requester, attributes, lazy = False )
def get_organization( self, login ):
attributes = {
"url": "https://api.github.com/orgs/" + login,
"login": login,
}
return GithubObjects.Organization.Organization( self, attributes, lazy = False )
return GithubObjects.Organization.Organization( self.__requester, attributes, lazy = False )
def get_gist( self, id ):
return GithubObjects.Gist.Gist( self, { "id": id }, lazy = False )
# def get_gist( self, id ):
# return GithubObjects.Gist.Gist( self.__requester, { "id": id }, lazy = False )
def get_gists( self ):
return [
GithubObjects.Gist.Gist( self, attributes, lazy = True )
for attributes
in self._dataRequest( "GET", "/gists/public", None, None )
]
def _printDebug( self, *args ):
if self.__debugFile is not None:
self.__debugFile.write( " ".join( str( arg ) for arg in args ) + "\n" )
# def get_gists( self ):
# status, headers, data = self.__requester.request( "GET", "/gists/public", None, None )
# return [
# GithubObjects.Gist.Gist( self.__requester, attributes, lazy = True )
# for attributes
# in data
# ]
+49 -49
View File
@@ -11,8 +11,8 @@ import Event
import Authorization
class AuthenticatedUser( object ):
def __init__( self, github, attributes, lazy ):
self.__github = github
def __init__( self, requester, attributes, lazy ):
self.__requester = requester
self.__completed = False
self.__initAttributes()
self.__useAttributes( attributes )
@@ -148,7 +148,7 @@ class AuthenticatedUser( object ):
pass
def add_to_following( self, following ):
result = self.__github._statusRequest(
status, headers, data = self.__requester.request(
"PUT",
self.url + "/following/" + following.login,
None,
@@ -156,7 +156,7 @@ class AuthenticatedUser( object ):
)
def add_to_watched( self, watched ):
result = self.__github._statusRequest(
status, headers, data = self.__requester.request(
"PUT",
self.url + "/watched/" + watched.login,
None,
@@ -167,13 +167,13 @@ class AuthenticatedUser( object ):
pass
def create_fork( self, repo ):
result = self.__github._statusRequest(
status, headers, data = self.__requester.request(
"POST",
"/repos/" + repo.owner.login + "/" + repo.name + "/forks",
None,
None
)
return Repository.Repository( self.__github, result, lazy = True )
return Repository.Repository( self.__requester, data, lazy = True )
def create_gist( self, public, files, description = None ):
pass
@@ -201,31 +201,31 @@ class AuthenticatedUser( object ):
post_parameters[ "hireable" ] = hireable
if bio is not None:
post_parameters[ "bio" ] = bio
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"PATCH",
"https://api.github.com/user",
None,
post_parameters
)
self.__useAttributes( result )
self.__useAttributes( data )
def get_authorization( self, id ):
pass
def get_authorizations( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/authorizations",
None,
None
)
return [
Authorization.Authorization( self.__github, element, lazy = True )
for element in result
Authorization.Authorization( self.__requester, element, lazy = True )
for element in data
]
def get_emails( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/emails",
None,
@@ -233,154 +233,154 @@ class AuthenticatedUser( object ):
)
def get_events( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/events",
None,
None
)
return [
Event.Event( self.__github, element, lazy = True )
for element in result
Event.Event( self.__requester, element, lazy = True )
for element in data
]
def get_followers( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/followers",
None,
None
)
return [
NamedUser.NamedUser( self.__github, element, lazy = True )
for element in result
NamedUser.NamedUser( self.__requester, element, lazy = True )
for element in data
]
def get_following( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/following",
None,
None
)
return [
NamedUser.NamedUser( self.__github, element, lazy = True )
for element in result
NamedUser.NamedUser( self.__requester, element, lazy = True )
for element in data
]
def get_gists( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/gists",
None,
None
)
return [
Gist.Gist( self.__github, element, lazy = True )
for element in result
Gist.Gist( self.__requester, element, lazy = True )
for element in data
]
def get_issues( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/issues",
None,
None
)
return [
Issue.Issue( self.__github, element, lazy = True )
for element in result
Issue.Issue( self.__requester, element, lazy = True )
for element in data
]
def get_key( self, id ):
pass
def get_keys( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/keys",
None,
None
)
return [
UserKey.UserKey( self.__github, element, lazy = True )
for element in result
UserKey.UserKey( self.__requester, element, lazy = True )
for element in data
]
def get_organization_events( self, org ):
pass
def get_orgs( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/orgs",
None,
None
)
return [
Organization.Organization( self.__github, element, lazy = True )
for element in result
Organization.Organization( self.__requester, element, lazy = True )
for element in data
]
def get_repo( self, name ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
"https://api.github.com/repos/" + self.login + "/" + name,
None,
None
)
return Repository.Repository( self.__github, result, lazy = True )
return Repository.Repository( self.__requester, data, lazy = True )
def get_repos( self, type = None ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/repos",
None,
None
)
return [
Repository.Repository( self.__github, element, lazy = True )
for element in result
Repository.Repository( self.__requester, element, lazy = True )
for element in data
]
def get_starred_gists( self ):
pass
def get_watched( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/watched",
None,
None
)
return [
Repository.Repository( self.__github, element, lazy = True )
for element in result
Repository.Repository( self.__requester, element, lazy = True )
for element in data
]
def has_in_following( self, following ):
result = self.__github._statusRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/following/" + following.login,
None,
None
)
return result == 204
return status == 204
def has_in_watched( self, watched ):
result = self.__github._statusRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/watched/" + watched.login,
None,
None
)
return result == 204
return status == 204
def remove_from_emails( self, *emails ):
pass
def remove_from_following( self, following ):
result = self.__github._statusRequest(
status, headers, data = self.__requester.request(
"DELETE",
self.url + "/following/" + following.login,
None,
@@ -388,7 +388,7 @@ class AuthenticatedUser( object ):
)
def remove_from_watched( self, watched ):
result = self.__github._statusRequest(
status, headers, data = self.__requester.request(
"DELETE",
self.url + "/watched/" + watched.login,
None,
@@ -428,13 +428,13 @@ class AuthenticatedUser( object ):
# @todo Do not generate __complete if type has no url attribute
def __complete( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.__url,
None,
None
)
self.__useAttributes( result )
self.__useAttributes( data )
self.__completed = True
def __useAttributes( self, attributes ):
+6 -6
View File
@@ -3,8 +3,8 @@
class Authorization( object ):
def __init__( self, github, attributes, lazy ):
self.__github = github
def __init__( self, requester, attributes, lazy ):
self.__requester = requester
self.__completed = False
self.__initAttributes()
self.__useAttributes( attributes )
@@ -72,13 +72,13 @@ class Authorization( object ):
post_parameters[ "note" ] = note
if note_url is not None:
post_parameters[ "note_url" ] = note_url
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"PATCH",
"https://api.github.com/user",
None,
post_parameters
)
self.__useAttributes( result )
self.__useAttributes( data )
def __initAttributes( self ):
self.__app = None
@@ -97,13 +97,13 @@ class Authorization( object ):
# @todo Do not generate __complete if type has no url attribute
def __complete( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.__url,
None,
None
)
self.__useAttributes( result )
self.__useAttributes( data )
self.__completed = True
def __useAttributes( self, attributes ):
+5 -5
View File
@@ -4,8 +4,8 @@
import Commit
class Branch( object ):
def __init__( self, github, attributes, lazy ):
self.__github = github
def __init__( self, requester, attributes, lazy ):
self.__requester = requester
self.__completed = False
self.__initAttributes()
self.__useAttributes( attributes )
@@ -32,18 +32,18 @@ class Branch( object ):
# @todo Do not generate __complete if type has no url attribute
def __complete( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.__url,
None,
None
)
self.__useAttributes( result )
self.__useAttributes( data )
self.__completed = True
def __useAttributes( self, attributes ):
#@todo No need to check if attribute is in attributes when attribute is mandatory
if "commit" in attributes:
self.__commit = Commit.Commit( self.__github, attributes[ "commit" ], lazy = True )
self.__commit = Commit.Commit( self.__requester, attributes[ "commit" ], lazy = True )
if "name" in attributes:
self.__name = attributes[ "name" ]
+10 -10
View File
@@ -6,8 +6,8 @@ import GitCommit
import CommitComment
class Commit( object ):
def __init__( self, github, attributes, lazy ):
self.__github = github
def __init__( self, requester, attributes, lazy ):
self.__requester = requester
self.__completed = False
self.__initAttributes()
self.__useAttributes( attributes )
@@ -58,15 +58,15 @@ class Commit( object ):
pass
def get_comments( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/comments",
None,
None
)
return [
CommitComment.CommitComment( self.__github, element, lazy = True )
for element in result
CommitComment.CommitComment( self.__requester, element, lazy = True )
for element in data
]
def __initAttributes( self ):
@@ -85,23 +85,23 @@ class Commit( object ):
# @todo Do not generate __complete if type has no url attribute
def __complete( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.__url,
None,
None
)
self.__useAttributes( result )
self.__useAttributes( data )
self.__completed = True
def __useAttributes( self, attributes ):
#@todo No need to check if attribute is in attributes when attribute is mandatory
if "author" in attributes:
self.__author = NamedUser.NamedUser( self.__github, attributes[ "author" ], lazy = True )
self.__author = NamedUser.NamedUser( self.__requester, attributes[ "author" ], lazy = True )
if "commit" in attributes:
self.__commit = GitCommit.GitCommit( self.__github, attributes[ "commit" ], lazy = True )
self.__commit = GitCommit.GitCommit( self.__requester, attributes[ "commit" ], lazy = True )
if "committer" in attributes:
self.__committer = NamedUser.NamedUser( self.__github, attributes[ "committer" ], lazy = True )
self.__committer = NamedUser.NamedUser( self.__requester, attributes[ "committer" ], lazy = True )
if "files" in attributes:
self.__files = attributes[ "files" ]
if "parents" in attributes:
+7 -7
View File
@@ -4,8 +4,8 @@
import NamedUser
class CommitComment( object ):
def __init__( self, github, attributes, lazy ):
self.__github = github
def __init__( self, requester, attributes, lazy ):
self.__requester = requester
self.__completed = False
self.__initAttributes()
self.__useAttributes( attributes )
@@ -74,13 +74,13 @@ class CommitComment( object ):
post_parameters = {
"body": body,
}
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"PATCH",
"https://api.github.com/user",
None,
post_parameters
)
self.__useAttributes( result )
self.__useAttributes( data )
def __initAttributes( self ):
self.__body = None
@@ -101,13 +101,13 @@ class CommitComment( object ):
# @todo Do not generate __complete if type has no url attribute
def __complete( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.__url,
None,
None
)
self.__useAttributes( result )
self.__useAttributes( data )
self.__completed = True
def __useAttributes( self, attributes ):
@@ -133,4 +133,4 @@ class CommitComment( object ):
if "url" in attributes:
self.__url = attributes[ "url" ]
if "user" in attributes:
self.__user = NamedUser.NamedUser( self.__github, attributes[ "user" ], lazy = True )
self.__user = NamedUser.NamedUser( self.__requester, attributes[ "user" ], lazy = True )
+4 -4
View File
@@ -3,8 +3,8 @@
class Download( object ):
def __init__( self, github, attributes, lazy ):
self.__github = github
def __init__( self, requester, attributes, lazy ):
self.__requester = requester
self.__completed = False
self.__initAttributes()
self.__useAttributes( attributes )
@@ -142,13 +142,13 @@ class Download( object ):
# @todo Do not generate __complete if type has no url attribute
def __complete( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.__url,
None,
None
)
self.__useAttributes( result )
self.__useAttributes( data )
self.__completed = True
def __useAttributes( self, attributes ):
+7 -7
View File
@@ -6,8 +6,8 @@ import Repository
import NamedUser
class Event( object ):
def __init__( self, github, attributes, lazy ):
self.__github = github
def __init__( self, requester, attributes, lazy ):
self.__requester = requester
self.__completed = False
self.__initAttributes()
self.__useAttributes( attributes )
@@ -94,19 +94,19 @@ class Event( object ):
# @todo Do not generate __complete if type has no url attribute
def __complete( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.__url,
None,
None
)
self.__useAttributes( result )
self.__useAttributes( data )
self.__completed = True
def __useAttributes( self, attributes ):
#@todo No need to check if attribute is in attributes when attribute is mandatory
if "actor" in attributes:
self.__actor = NamedUser.NamedUser( self.__github, attributes[ "actor" ], lazy = True )
self.__actor = NamedUser.NamedUser( self.__requester, attributes[ "actor" ], lazy = True )
if "commit_id" in attributes:
self.__commit_id = attributes[ "commit_id" ]
if "created_at" in attributes:
@@ -118,13 +118,13 @@ class Event( object ):
if "issue" in attributes:
self.__issue = attributes[ "issue" ]
if "org" in attributes:
self.__org = Organization.Organization( self.__github, attributes[ "org" ], lazy = True )
self.__org = Organization.Organization( self.__requester, attributes[ "org" ], lazy = True )
if "payload" in attributes:
self.__payload = attributes[ "payload" ]
if "public" in attributes:
self.__public = attributes[ "public" ]
if "repo" in attributes:
self.__repo = Repository.Repository( self.__github, attributes[ "repo" ], lazy = True )
self.__repo = Repository.Repository( self.__requester, attributes[ "repo" ], lazy = True )
if "type" in attributes:
self.__type = attributes[ "type" ]
if "url" in attributes:
+10 -10
View File
@@ -6,8 +6,8 @@ import Gist
import GistComment
class Gist( object ):
def __init__( self, github, attributes, lazy ):
self.__github = github
def __init__( self, requester, attributes, lazy ):
self.__requester = requester
self.__completed = False
self.__initAttributes()
self.__useAttributes( attributes )
@@ -100,27 +100,27 @@ class Gist( object ):
post_parameters[ "description" ] = description
if files is not None:
post_parameters[ "files" ] = files
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"PATCH",
"https://api.github.com/user",
None,
post_parameters
)
self.__useAttributes( result )
self.__useAttributes( data )
def get_comment( self, id ):
pass
def get_comments( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/comments",
None,
None
)
return [
GistComment.GistComment( self.__github, element, lazy = True )
for element in result
GistComment.GistComment( self.__requester, element, lazy = True )
for element in data
]
def is_starred( self ):
@@ -154,13 +154,13 @@ class Gist( object ):
# @todo Do not generate __complete if type has no url attribute
def __complete( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.__url,
None,
None
)
self.__useAttributes( result )
self.__useAttributes( data )
self.__completed = True
def __useAttributes( self, attributes ):
@@ -192,4 +192,4 @@ class Gist( object ):
if "url" in attributes:
self.__url = attributes[ "url" ]
if "user" in attributes:
self.__user = NamedUser.NamedUser( self.__github, attributes[ "user" ], lazy = True )
self.__user = NamedUser.NamedUser( self.__requester, attributes[ "user" ], lazy = True )
+7 -7
View File
@@ -4,8 +4,8 @@
import NamedUser
class GistComment( object ):
def __init__( self, github, attributes, lazy ):
self.__github = github
def __init__( self, requester, attributes, lazy ):
self.__requester = requester
self.__completed = False
self.__initAttributes()
self.__useAttributes( attributes )
@@ -49,13 +49,13 @@ class GistComment( object ):
post_parameters = {
"body": body,
}
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"PATCH",
"https://api.github.com/user",
None,
post_parameters
)
self.__useAttributes( result )
self.__useAttributes( data )
def __initAttributes( self ):
self.__body = None
@@ -71,13 +71,13 @@ class GistComment( object ):
# @todo Do not generate __complete if type has no url attribute
def __complete( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.__url,
None,
None
)
self.__useAttributes( result )
self.__useAttributes( data )
self.__completed = True
def __useAttributes( self, attributes ):
@@ -93,4 +93,4 @@ class GistComment( object ):
if "url" in attributes:
self.__url = attributes[ "url" ]
if "user" in attributes:
self.__user = NamedUser.NamedUser( self.__github, attributes[ "user" ], lazy = True )
self.__user = NamedUser.NamedUser( self.__requester, attributes[ "user" ], lazy = True )
+4 -4
View File
@@ -3,8 +3,8 @@
class GitBlob( object ):
def __init__( self, github, attributes, lazy ):
self.__github = github
def __init__( self, requester, attributes, lazy ):
self.__requester = requester
self.__completed = False
self.__initAttributes()
self.__useAttributes( attributes )
@@ -49,13 +49,13 @@ class GitBlob( object ):
# @todo Do not generate __complete if type has no url attribute
def __complete( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.__url,
None,
None
)
self.__useAttributes( result )
self.__useAttributes( data )
self.__completed = True
def __useAttributes( self, attributes ):
+5 -5
View File
@@ -4,8 +4,8 @@
import GitTree
class GitCommit( object ):
def __init__( self, github, attributes, lazy ):
self.__github = github
def __init__( self, requester, attributes, lazy ):
self.__requester = requester
self.__completed = False
self.__initAttributes()
self.__useAttributes( attributes )
@@ -62,13 +62,13 @@ class GitCommit( object ):
# @todo Do not generate __complete if type has no url attribute
def __complete( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.__url,
None,
None
)
self.__useAttributes( result )
self.__useAttributes( data )
self.__completed = True
def __useAttributes( self, attributes ):
@@ -84,6 +84,6 @@ class GitCommit( object ):
if "sha" in attributes:
self.__sha = attributes[ "sha" ]
if "tree" in attributes:
self.__tree = GitTree.GitTree( self.__github, attributes[ "tree" ], lazy = True )
self.__tree = GitTree.GitTree( self.__requester, attributes[ "tree" ], lazy = True )
if "url" in attributes:
self.__url = attributes[ "url" ]
+6 -6
View File
@@ -3,8 +3,8 @@
class GitRef( object ):
def __init__( self, github, attributes, lazy ):
self.__github = github
def __init__( self, requester, attributes, lazy ):
self.__requester = requester
self.__completed = False
self.__initAttributes()
self.__useAttributes( attributes )
@@ -35,13 +35,13 @@ class GitRef( object ):
}
if force is not None:
post_parameters[ "force" ] = force
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"PATCH",
"https://api.github.com/user",
None,
post_parameters
)
self.__useAttributes( result )
self.__useAttributes( data )
def __initAttributes( self ):
self.__object = None
@@ -54,13 +54,13 @@ class GitRef( object ):
# @todo Do not generate __complete if type has no url attribute
def __complete( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.__url,
None,
None
)
self.__useAttributes( result )
self.__useAttributes( data )
self.__completed = True
def __useAttributes( self, attributes ):
+4 -4
View File
@@ -3,8 +3,8 @@
class GitTag( object ):
def __init__( self, github, attributes, lazy ):
self.__github = github
def __init__( self, requester, attributes, lazy ):
self.__requester = requester
self.__completed = False
self.__initAttributes()
self.__useAttributes( attributes )
@@ -55,13 +55,13 @@ class GitTag( object ):
# @todo Do not generate __complete if type has no url attribute
def __complete( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.__url,
None,
None
)
self.__useAttributes( result )
self.__useAttributes( data )
self.__completed = True
def __useAttributes( self, attributes ):
+4 -4
View File
@@ -3,8 +3,8 @@
class GitTree( object ):
def __init__( self, github, attributes, lazy ):
self.__github = github
def __init__( self, requester, attributes, lazy ):
self.__requester = requester
self.__completed = False
self.__initAttributes()
self.__useAttributes( attributes )
@@ -43,13 +43,13 @@ class GitTree( object ):
# @todo Do not generate __complete if type has no url attribute
def __complete( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.__url,
None,
None
)
self.__useAttributes( result )
self.__useAttributes( data )
self.__completed = True
def __useAttributes( self, attributes ):
@@ -1,57 +0,0 @@
import itertools
class Parameters:
def __init__( self, mandatoryParameters, optionalParameters ):
self.__mandatoryParameters = mandatoryParameters
self.__optionalParameters = optionalParameters
def check( self, args, kwds ):
data = dict( kwds )
for arg, argumentName in itertools.izip( args, itertools.chain( self.__mandatoryParameters, self.__optionalParameters ) ):
if argumentName in kwds:
raise TypeError()
else:
data[ argumentName ] = arg
for argumentName in data:
if argumentName not in itertools.chain( self.__mandatoryParameters, self.__optionalParameters ):
raise TypeError()
for argumentName in self.__mandatoryParameters:
if argumentName not in data:
raise TypeError()
return data
def documentParameters( self ):
mandatory = ", ".join( self.__mandatoryParameters )
optional = "[" + ", ".join( self.__optionalParameters ) + "]"
if len( self.__mandatoryParameters ) == 0:
if len( self.__optionalParameters ) == 0:
return ""
else:
return " " + optional + " "
else:
if len( self.__optionalParameters ) == 0:
return " " + mandatory + " "
else:
return " " + mandatory + ", " + optional + " "
def NoParameters():
return Parameters( [], [] )
class Alternative:
def __init__( self, *checkers ):
self.__checkers = checkers
def check( self, args, kwds ):
# Try the n - 1 first checkers
for checker in self.__checkers[ : -1 ]:
try:
return checker.check( args, kwds )
except TypeError:
pass
# Use the last checker
# This way, the call stack will point to an actual validation failure
return self.__checkers[ -1 ].check( args, kwds )
def documentParameters( self ):
return " <" + "> or <".join( checker.documentParameters() for checker in self.__checkers ) + "> "
-118
View File
@@ -1,118 +0,0 @@
class AttributeFromCallable:
class AttributeDefinition:
def __init__( self, name, callable ):
self.__name = name
self.__callable = callable
def getValueFromRawValue( self, obj, rawValue ):
return rawValue
def updateAttributes( self, obj ):
obj._updateAttributes( { self.__name: self.__callable( obj ) } )
def isLazy( self ):
return False
def __init__( self, name, callable ):
self.__name = name
self.__callable = callable
def apply( self, cls ):
cls._addAttribute( self.__name, AttributeFromCallable.AttributeDefinition( self.__name, self.__callable ) )
def autoDocument( self ):
return ""
class MethodFromCallable:
def __init__( self, name, parameters, callable, returnTypePolicy ):
self.__argumentsChecker = parameters
self.__name = name
self.__callable = callable
self.__returnTypePolicy = returnTypePolicy
def apply( self, cls ):
cls._addMethod( self.__name, self.__execute )
def __execute( self, obj, *args, **kwds ):
data = self.__argumentsChecker.check( args, kwds )
return self.__callable( obj, **data )
def autoDocument( self ):
if self.__name.startswith( "_" ):
return ""
else:
doc = "* `" + self.__name + "(" + self.__argumentsChecker.documentParameters() + ")`"
if self.__returnTypePolicy.hasMeaningfulDocumentation():
doc += ": " + self.__returnTypePolicy.documentTypeName()
doc += "\n"
return doc
class InternalAttribute:
class AttributeDefinition:
def __init__( self, typePolicy ):
self.__typePolicy = typePolicy
def getValueFromRawValue( self, obj, rawValue ):
if rawValue is None:
return None
else:
return self.__typePolicy.createLazy( obj, rawValue )
def updateAttributes( self, obj ):
attributes = obj._github._dataRequest( "GET", obj._baseUrl(), None, None )
obj._updateAttributes( attributes )
obj._markAsCompleted()
def isLazy( self ):
return True
def __init__( self, attributeName, typePolicy ):
self.__attributeName = attributeName
self.__typePolicy = typePolicy
def apply( self, cls ):
cls._addAttribute( self.__attributeName, InternalAttribute.AttributeDefinition( self.__typePolicy ) )
def autoDocument( self ):
if self.__attributeName.startswith( "_" ):
return ""
doc = "* `" + self.__attributeName + "`"
if self.__typePolicy.hasMeaningfulDocumentation():
doc += ": " + self.__typePolicy.documentTypeName()
doc += "\n"
return doc
class ExternalAttribute:
def __init__( self, attributeName, typePolicy ):
self.__attributeName = attributeName
self.__typePolicy = typePolicy
def apply( self, cls ):
cls._addMethod( "get_" + self.__attributeName, self.__execute )
def __execute( self, obj ):
return self.__typePolicy.createLazy(
obj,
obj._github._dataRequest( "GET", obj._baseUrl() + "/" + self.__attributeName, None, None )
)
def autoDocument( self ):
return "* `get_" + self.__attributeName + "()`: " + self.__typePolicy.documentTypeName() + "\n"
class SeveralAttributePolicies:
def __init__( self, attributePolicies, documentationSection = None ):
self.__attributePolicies = attributePolicies
self.__documentationSection = documentationSection
def apply( self, cls ):
for attributePolicy in self.__attributePolicies:
attributePolicy.apply( cls )
def autoDocument( self ):
doc = ""
if self.__documentationSection is not None:
doc += "\n"
doc += self.__documentationSection + "\n"
doc += "-" * len( self.__documentationSection ) + "\n"
doc += "".join( sorted( attributePolicy.autoDocument() for attributePolicy in self.__attributePolicies ) )
return doc
@@ -1,592 +0,0 @@
import unittest
import MockMockMock
from GithubObject import *
class GithubObjectTestCase( unittest.TestCase ):
def testDuplicatedAttributeInOnePolicy( self ):
with self.assertRaises( BadGithubObjectException ):
GithubObject( "", InternalSimpleAttributes( "a", "a" ) )
def testDuplicatedAttributeInTwoPolicies( self ):
with self.assertRaises( BadGithubObjectException ):
GithubObject( "", InternalSimpleAttributes( "a" ), InternalSimpleAttributes( "a" ) )
class TestCaseWithGithubTestObject( unittest.TestCase ):
def setUp( self ):
unittest.TestCase.setUp( self )
self.g = MockMockMock.Mock( "github" )
self.o = self.GithubTestObject( self.g.object, { "a1": 1, "a2": 2 }, lazy = True )
self.GithubTestObject._autoDocument() # Only for coverage
def tearDown( self ):
self.g.tearDown()
unittest.TestCase.tearDown( self )
def expectDataGet( self, url, arguments = None ):
return self.g.expect._dataRequest( "GET", url, arguments, None )
def expectDataPost( self, url, data ):
return self.g.expect._dataRequest( "POST", url, None, data )
def expectDataPatch( self, url, data ):
return self.g.expect._dataRequest( "PATCH", url, None, data )
def expectStatusGet( self, url ):
return self.g.expect._statusRequest( "GET", url, None, None )
def expectStatusPost( self, url, data ):
return self.g.expect._statusRequest( "POST", url, None, data )
def expectStatusPut( self, url, data = None ):
return self.g.expect._statusRequest( "PUT", url, None, data )
def expectStatusDelete( self, url, data = None ):
return self.g.expect._statusRequest( "DELETE", url, None, data )
class GithubObjectWithDocumentationCoveringSpecialCases( TestCaseWithGithubTestObject ):
GithubTestObject = GithubObject(
"GithubTestObject",
BaseUrl( lambda obj: "/test" ),
InternalSimpleAttributes( "a1", "a2", "_a3" ),
MethodFromCallable( "myMethod", Parameters( [ "mock", "arg" ], [] ), lambda obj: 42, ObjectTypePolicy( GithubObject ) ),
AttributeFromCallable( "myAttr", lambda obj: 42 )
)
def testNothing( self ):
pass
class GithubObjectWithBaseUrlDependingOnAttribute( TestCaseWithGithubTestObject ):
GithubTestObject = GithubObject(
"GithubTestObject",
BaseUrl( lambda obj: "/test/" + str( obj.a1 ) ),
InternalSimpleAttributes( "a1", "a2", "a3", "a4" ),
Editable( Parameters( [ "a1" ], [] ) )
)
def test( self ):
self.expectDataPatch( "/test/1", { "a1": 11 } ).andReturn( { "a1": 110 } )
self.expectDataPatch( "/test/110", { "a1": 111 } ).andReturn( { "a1": 1110 } )
self.o.edit( 11 )
self.o.edit( 111 )
class GithubObjectWithOnlyInternalSimpleAttributes( TestCaseWithGithubTestObject ):
GithubTestObject = GithubObject(
"GithubTestObject",
BaseUrl( lambda obj: "/test" ),
InternalSimpleAttributes( "a1", "a2", "a3", "a4" )
)
def testInterface( self ):
self.assertEqual( [ e for e in dir( self.o ) if not e.startswith( "_" ) ], [ "a1", "a2", "a3", "a4" ] )
def testCompletion( self ):
# A GithubObject:
# - knows the attributes given to its constructor
self.assertEqual( self.o.a1, 1 )
self.assertEqual( self.o.a2, 2 )
# - is completed the first time any unknown attribute is requested
self.expectDataGet( "/test" ).andReturn( { "a2": 22, "a3": 3 } )
self.assertEqual( self.o.a3, 3 )
# - remembers the attributes that were not updated
self.assertEqual( self.o.a1, 1 )
# - acknowledges updates of attributes
self.assertEqual( self.o.a2, 22 )
# - remembers that some attributes are absent even after an update
self.assertEqual( self.o.a4, None )
def testUnknownAttribute( self ):
self.assertRaises( AttributeError, lambda: self.o.foobar )
def testNonLazyConstruction( self ):
self.expectDataGet( "/test" ).andReturn( { "a2": 2, "a3": 3 } )
o = self.GithubTestObject( self.g.object, {}, lazy = False )
self.g.tearDown()
self.assertEqual( o.a1, None )
self.assertEqual( o.a2, 2 )
self.assertEqual( o.a3, 3 )
self.assertEqual( o.a4, None )
class GithubObjectWithOtherBaseUrl( TestCaseWithGithubTestObject ):
GithubTestObject = GithubObject(
"GithubTestObject",
BaseUrl( lambda obj: "/other/" + str( obj.a1 ) ),
InternalSimpleAttributes( "a1", "a2", "a3", "a4" )
)
def testCompletion( self ):
self.expectDataGet( "/other/1" ).andReturn( { "a2": 22, "a3": 3 } )
self.assertEqual( self.o.a3, 3 )
class EditableGithubObject( TestCaseWithGithubTestObject ):
GithubTestObject = GithubObject(
"GithubTestObject",
BaseUrl( lambda obj: "/test" ),
InternalSimpleAttributes( "a1", "a2", "a3", "a4" ),
Editable( Parameters( [ "a1" ], [ "a2", "a4" ] ) ),
)
def testEditWithoutArgument( self ):
with self.assertRaises( TypeError ):
self.o.edit()
def testEditWithoutMandatoryArgument( self ):
with self.assertRaises( TypeError ):
self.o.edit( a2 = 2, a4 = 3 )
def testEditWithSillyArgument( self ):
with self.assertRaises( TypeError ):
self.o.edit( foobar = 42 )
def testEditWithOneKeywordArgument( self ):
self.expectDataPatch( "/test", { "a1": 11 } ).andReturn( {} )
self.o.edit( a1 = 11 )
def testEditWithTwoKeywordArguments( self ):
self.expectDataPatch( "/test", { "a1": 11, "a2": 22 } ).andReturn( {} )
self.o.edit( a1 = 11, a2 = 22 )
def testEditWithTwoKeywordArgumentsSkipingFirstOptionalArgument( self ):
self.expectDataPatch( "/test", { "a1": 11, "a4": 44 } ).andReturn( {} )
self.o.edit( a1 = 11, a4 = 44 )
def testEditWithThreeKeywordArguments( self ):
self.expectDataPatch( "/test", { "a1": 11, "a2": 22, "a4": 44 } ).andReturn( {} )
self.o.edit( a1 = 11, a4 = 44, a2 = 22 )
def testEditWithOnePositionalArgument( self ):
self.expectDataPatch( "/test", { "a1": 11 } ).andReturn( {} )
self.o.edit( 11 )
def testEditWithRepeatedPositionalArgument( self ):
with self.assertRaises( TypeError ):
self.o.edit( 11, a1 = 11 )
def testEditWithTwoPositionalArguments( self ):
self.expectDataPatch( "/test", { "a1": 11, "a2": 22 } ).andReturn( {} )
self.o.edit( 11, 22 )
def testEditWithThreePositionalArguments( self ):
self.expectDataPatch( "/test", { "a1": 11, "a2": 22, "a4": 44 } ).andReturn( {} )
self.o.edit( 11, 22, 44 )
def testEditWithMixedArguments_1( self ):
self.expectDataPatch( "/test", { "a1": 11, "a2": 22 } ).andReturn( {} )
self.o.edit( 11, a2 = 22 )
def testEditWithMixedArguments_2( self ):
self.expectDataPatch( "/test", { "a1": 11, "a2": 22, "a4": 44 } ).andReturn( {} )
self.o.edit( 11, a2 = 22, a4 = 44 )
def testEditWithMixedArguments_3( self ):
self.expectDataPatch( "/test", { "a1": 11, "a2": 22, "a4": 44 } ).andReturn( {} )
self.o.edit( 11, 22, a4 = 44 )
def testAcknoledgeUpdatesOfAttributes( self ):
self.expectDataPatch( "/test", { "a1": 11 } ).andReturn( { "a2": 22, "a3": 3 } )
self.o.edit( a1 = 11 )
self.assertEqual( self.o.a1, 1 )
self.assertEqual( self.o.a2, 22 )
self.assertEqual( self.o.a3, 3 )
self.expectDataGet( "/test" ).andReturn( {} )
self.assertEqual( self.o.a4, None )
class DeletableGithubObject( TestCaseWithGithubTestObject ):
GithubTestObject = GithubObject(
"GithubTestObject",
BaseUrl( lambda obj: "/test" ),
InternalSimpleAttributes( "a1", "a2", "a3", "a4" ),
Deletable(),
)
def testDelete( self ):
self.expectStatusDelete( "/test" ).andReturn( 204 )
self.o.delete()
class GithubObjectWithInternalObjectAttribute( TestCaseWithGithubTestObject ):
ContainedObject = GithubObject(
"ContainedObject",
BaseUrl( lambda obj: "/test/a3s/" + obj.id ),
InternalSimpleAttributes( "id", "name", "desc" )
)
GithubTestObject = GithubObject(
"GithubTestObject",
BaseUrl( lambda obj: "/test" ),
InternalSimpleAttributes( "a1", "a2" ),
InternalObjectAttribute( "a3", ContainedObject )
)
def testCompletion( self ):
self.expectDataGet( "/test" ).andReturn( { "a3": { "id": "id1", "name": "name1" } } )
self.assertEqual( self.o.a3.id, "id1" )
self.assertEqual( self.o.a3.name, "name1" )
self.expectDataGet( "/test/a3s/id1" ).andReturn( { "desc": "desc1" } )
self.assertEqual( self.o.a3.desc, "desc1" )
def testCompletionWithNone( self ):
self.expectDataGet( "/test" ).andReturn( { "a3": None } )
self.assertIsNone( self.o.a3 )
class GithubObjectWithListGetableExternalListOfObjects( TestCaseWithGithubTestObject ):
ContainedObject = GithubObject(
"ContainedObject",
BaseUrl( lambda obj: "/test/a3s/" + obj.id ),
InternalSimpleAttributes( "id", "name" )
)
GithubTestObject = GithubObject(
"GithubTestObject",
BaseUrl( lambda obj: "/test" ),
InternalSimpleAttributes( "a1", "a2" ),
ExternalListOfObjects( "a3s", "a3", ContainedObject, ListGetable( Parameters( [], [ "type" ] ) ) )
)
def testGetList( self ):
self.expectDataGet( "/test/a3s", {} ).andReturn( [ { "id": "id1" }, { "id": "id2" }, { "id": "id3" } ] )
a3s = self.o.get_a3s()
self.assertEqual( len( a3s ), 3 )
self.assertEqual( a3s[ 0 ].id, "id1" )
self.expectDataGet( "/test/a3s/id1" ).andReturn( { "name": "name1" } )
self.assertEqual( a3s[ 0 ].name, "name1" )
def testGetListWithType( self ):
self.expectDataGet( "/test/a3s", { "type": "foobar" } ).andReturn( [ { "id": "id1" }, { "id": "id2" }, { "id": "id3" } ] )
a3s = self.o.get_a3s( "foobar" )
self.assertEqual( len( a3s ), 3 )
class GithubObjectWithListGetableExternalListOfObjectsWithOtherUrl( TestCaseWithGithubTestObject ):
ContainedObject = GithubObject(
"ContainedObject",
BaseUrl( lambda obj: "/other/" + obj.id ),
InternalSimpleAttributes( "id", "name" )
)
GithubTestObject = GithubObject(
"GithubTestObject",
BaseUrl( lambda obj: "/test" ),
InternalSimpleAttributes( "a1", "a2" ),
ExternalListOfObjects( "a3s", "a3", ContainedObject, ListGetable( Parameters( [], [ "type" ] ) ), url = "/other" )
)
def testGetList( self ):
self.expectDataGet( "/other", {} ).andReturn( [ { "id": "id1" }, { "id": "id2" }, { "id": "id3" } ] )
a3s = self.o.get_a3s()
self.assertEqual( len( a3s ), 3 )
self.assertEqual( a3s[ 0 ].id, "id1" )
self.expectDataGet( "/other/id1" ).andReturn( { "name": "name1" } )
self.assertEqual( a3s[ 0 ].name, "name1" )
class GithubObjectWithListGetableExternalListOfObjectsWithAttributeModifier( TestCaseWithGithubTestObject ):
ContainedObject = GithubObject(
"ContainedObject",
BaseUrl( lambda obj: "/test/a3s/" + obj.id ),
InternalSimpleAttributes( "id", "name", "_a" )
)
GithubTestObject = GithubObject(
"GithubTestObject",
BaseUrl( lambda obj: "/test" ),
InternalSimpleAttributes( "a1", "a2" ),
ExternalListOfObjects( "a3s", "a3", ContainedObject, ListGetable( Parameters( [], [ "type" ] ), { "_a": lambda obj: 42 } ) )
)
def testGetList( self ):
self.expectDataGet( "/test/a3s", {} ).andReturn( [ { "id": "id1" }, { "id": "id2" }, { "id": "id3" } ] )
a3s = self.o.get_a3s()
self.assertEqual( len( a3s ), 3 )
self.assertEqual( a3s[ 0 ].id, "id1" )
self.assertEqual( a3s[ 0 ]._a, 42 )
self.expectDataGet( "/test/a3s/id1" ).andReturn( { "name": "name1" } )
self.assertEqual( a3s[ 0 ].name, "name1" )
class GithubObjectWithElementAddableExternalListOfObjects( TestCaseWithGithubTestObject ):
ContainedObject = GithubObject(
"ContainedObject",
BaseUrl( lambda obj: "/test/a3s/" + obj.id ),
Identity( lambda obj: obj.id ),
InternalSimpleAttributes( "id", "name" ),
)
GithubTestObject = GithubObject(
"GithubTestObject",
BaseUrl( lambda obj: "/test" ),
InternalSimpleAttributes( "a1", "a2" ),
ExternalListOfObjects( "a3s", "a3", ContainedObject, ElementAddable() )
)
def testAddToList( self ):
a3ToAdd = self.ContainedObject( self.g.object, { "id": "idAdd", "name": "nameAdd" }, lazy = True )
self.expectStatusPut( "/test/a3s/idAdd" ).andReturn( 204 )
self.o.add_to_a3s( a3ToAdd )
class GithubObjectWithElementRemovableExternalListOfObjects( TestCaseWithGithubTestObject ):
ContainedObject = GithubObject(
"ContainedObject",
BaseUrl( lambda obj: "/test/a3s/" + obj.id ),
Identity( lambda obj: obj.id ),
InternalSimpleAttributes( "id", "name" ),
)
GithubTestObject = GithubObject(
"GithubTestObject",
BaseUrl( lambda obj: "/test" ),
InternalSimpleAttributes( "a1", "a2" ),
ExternalListOfObjects( "a3s", "a3", ContainedObject, ElementRemovable() )
)
def testRemoveFromList( self ):
a3ToRemove = self.ContainedObject( self.g.object, { "id": "idRemove", "name": "nameRemove" }, lazy = True )
self.expectStatusDelete( "/test/a3s/idRemove" ).andReturn( 204 )
self.o.remove_from_a3s( a3ToRemove )
class GithubObjectWithElementHasableExternalListOfObjects( TestCaseWithGithubTestObject ):
ContainedObject = GithubObject(
"ContainedObject",
BaseUrl( lambda obj: "/test/a3s/" + obj.id ),
Identity( lambda obj: obj.id ),
InternalSimpleAttributes( "id", "name" ),
)
GithubTestObject = GithubObject(
"GithubTestObject",
BaseUrl( lambda obj: "/test" ),
InternalSimpleAttributes( "a1", "a2" ),
ExternalListOfObjects( "a3s", "a3", ContainedObject, ElementHasable() )
)
def testHasInList( self ):
a3ToQuery = self.ContainedObject( self.g.object, { "id": "idQuery", "name": "nameQuery" }, lazy = True )
self.expectStatusGet( "/test/a3s/idQuery" ).andReturn( 204 )
self.assertTrue( self.o.has_in_a3s( a3ToQuery ) )
self.expectStatusGet( "/test/a3s/idQuery" ).andReturn( 404 )
self.assertFalse( self.o.has_in_a3s( a3ToQuery ) )
class GithubObjectWithElementCreatableExternalListOfObjects( TestCaseWithGithubTestObject ):
ContainedObject = GithubObject(
"ContainedObject",
BaseUrl( lambda obj: "/test/a3s/" + obj.id ),
Identity( lambda obj: obj.id ),
InternalSimpleAttributes( "id", "name" ),
)
GithubTestObject = GithubObject(
"GithubTestObject",
BaseUrl( lambda obj: "/test" ),
InternalSimpleAttributes( "a1", "a2" ),
ExternalListOfObjects( "a3s", "a3", ContainedObject, ElementCreatable( Parameters( [ "name" ], [ "p1", "p2" ] ) ) )
)
def testCreate( self ):
self.expectDataPost( "/test/a3s", { "name": "nameCreate" } ).andReturn( { "id": "idCreate" } )
self.assertEqual( self.o.create_a3( name = "nameCreate" ).id, "idCreate" )
def testCreateWithOptionalArguments( self ):
self.expectDataPost( "/test/a3s", { "name": "nameCreate", "p1": 1 } ).andReturn( { "id": "idCreate" } )
self.assertEqual( self.o.create_a3( name = "nameCreate", p1 = 1 ).id, "idCreate" )
self.expectDataPost( "/test/a3s", { "name": "nameCreate", "p2": 2 } ).andReturn( { "id": "idCreate" } )
self.assertEqual( self.o.create_a3( name = "nameCreate", p2 = 2 ).id, "idCreate" )
self.expectDataPost( "/test/a3s", { "name": "nameCreate", "p1": 1, "p2": 2 } ).andReturn( { "id": "idCreate" } )
self.assertEqual( self.o.create_a3( name = "nameCreate", p2 = 2, p1 = 1 ).id, "idCreate" )
def testCreateWithPositionalArguments( self ):
self.expectDataPost( "/test/a3s", { "name": "nameCreate", "p1": 1 } ).andReturn( { "id": "idCreate" } )
self.assertEqual( self.o.create_a3( "nameCreate", 1 ).id, "idCreate" )
self.expectDataPost( "/test/a3s", { "name": "nameCreate", "p2": 2 } ).andReturn( { "id": "idCreate" } )
self.assertEqual( self.o.create_a3( "nameCreate", p2 = 2 ).id, "idCreate" )
self.expectDataPost( "/test/a3s", { "name": "nameCreate", "p1": 1, "p2": 2 } ).andReturn( { "id": "idCreate" } )
self.assertEqual( self.o.create_a3( "nameCreate", 1, 2 ).id, "idCreate" )
def testCreateWithSillyArgument( self ):
self.g.expect._dataRequest.andReturn( None )
with self.assertRaises( TypeError ):
self.o.create_a3( foobar = 42 )
class GithubObjectWithSeveralElementsAddableExternalListOfObjects( TestCaseWithGithubTestObject ):
ContainedObject = GithubObject(
"ContainedObject",
BaseUrl( lambda obj: "/test/a3s/" + obj.id ),
Identity( lambda obj: obj.id ),
InternalSimpleAttributes( "id", "name" )
)
GithubTestObject = GithubObject(
"GithubTestObject",
BaseUrl( lambda obj: "/test" ),
InternalSimpleAttributes( "a1", "a2" ),
ExternalListOfObjects( "a3s", "a3", ContainedObject, SeveralElementsAddable() )
)
def testAddToList( self ):
self.expectStatusPost( "/test/a3s", [ "id1", "id2" ] )
self.o.add_to_a3s( self.ContainedObject( self.g, { "id": "id1" }, lazy = True ), self.ContainedObject( self.g, { "id": "id2" }, lazy = True ) )
class GithubObjectWithListSetableExternalListOfObjects( TestCaseWithGithubTestObject ):
ContainedObject = GithubObject(
"ContainedObject",
BaseUrl( lambda obj: "/test/a3s/" + obj.id ),
Identity( lambda obj: obj.id ),
InternalSimpleAttributes( "id", "name" )
)
GithubTestObject = GithubObject(
"GithubTestObject",
BaseUrl( lambda obj: "/test" ),
InternalSimpleAttributes( "a1", "a2" ),
ExternalListOfObjects( "a3s", "a3", ContainedObject, ListSetable() )
)
def testSetList( self ):
self.expectStatusPut( "/test/a3s", [ "id1", "id2" ] )
self.o.set_a3s( self.ContainedObject( self.g, { "id": "id1" }, lazy = True ), self.ContainedObject( self.g, { "id": "id2" }, lazy = True ) )
class GithubObjectWithListDeletableExternalListOfObjects( TestCaseWithGithubTestObject ):
ContainedObject = GithubObject(
"ContainedObject",
BaseUrl( lambda obj: "/test/a3s/" + obj.id ),
InternalSimpleAttributes( "id", "name" )
)
GithubTestObject = GithubObject(
"GithubTestObject",
BaseUrl( lambda obj: "/test" ),
InternalSimpleAttributes( "a1", "a2" ),
ExternalListOfObjects( "a3s", "a3", ContainedObject, ListDeletable() )
)
def testGetList( self ):
self.expectStatusDelete( "/test/a3s" )
self.o.delete_a3s()
class GithubObjectWithElementGetableExternalListOfObjects( TestCaseWithGithubTestObject ):
ContainedObject = GithubObject(
"ContainedObject",
BaseUrl( lambda obj: "/test/a3s/" + obj.id ),
InternalSimpleAttributes( "id", "name" )
)
GithubTestObject = GithubObject(
"GithubTestObject",
BaseUrl( lambda obj: "/test" ),
InternalSimpleAttributes( "a1", "a2" ),
ExternalListOfObjects( "a3s", "a3", ContainedObject, ElementGetable( Parameters( [ "id" ], [] ) ) )
)
def testGetList( self ):
self.expectDataGet( "/test/a3s/idGet" ).andReturn( { "id": "idGet" } )
self.assertEqual( self.o.get_a3( "idGet" ).id, "idGet" )
class GithubObjectWithMultiCapacityExternalListOfSimpleTypes( TestCaseWithGithubTestObject ):
GithubTestObject = GithubObject(
"GithubTestObject",
BaseUrl( lambda obj: "/test" ),
InternalSimpleAttributes( "a1", "a2" ),
ExternalListOfSimpleTypes( "a3s", "a3", "",
ListGetable( Parameters( [], [] ) ),
SeveralElementsAddable(),
SeveralElementsRemovable(),
)
)
def testGetList( self ):
self.expectDataGet( "/test/a3s", {} ).andReturn( [ "a", "b", "c" ] )
a3s = self.o.get_a3s()
self.assertEqual( len( a3s ), 3 )
self.assertEqual( a3s[ 0 ], "a" )
def testAddToList( self ):
self.expectStatusPost( "/test/a3s", [ "a", "b", "c" ] ).andReturn( 204 )
a3s = self.o.add_to_a3s( "a", "b", "c" )
def testDeleteFromList( self ):
self.expectStatusDelete( "/test/a3s", [ "a", "b", "c" ] ).andReturn( 204 )
a3s = self.o.remove_from_a3s( "a", "b", "c" )
class GithubObjectWithExternalSimpleAttribute( TestCaseWithGithubTestObject ):
GithubTestObject = GithubObject(
"GithubTestObject",
BaseUrl( lambda obj: "/test" ),
InternalSimpleAttributes( "a1", "a2" ),
ExternalSimpleAttribute( "a3", "" )
)
def testGetAttribute( self ):
self.expectDataGet( "/test/a3" ).andReturn( 72 )
self.assertEqual( self.o.get_a3(), 72 )
def myCallable( obj, mock, arg ):
return mock.call( arg )
class GithubObjectWithMethodFromCallable( TestCaseWithGithubTestObject ):
GithubTestObject = GithubObject(
"GithubTestObject",
BaseUrl( lambda obj: "/test" ),
InternalSimpleAttributes( "a1", "a2" ),
MethodFromCallable( "myMethod", Parameters( [ "mock", "arg" ], [] ), myCallable, SimpleTypePolicy( None ) )
)
def testCallMethod( self ):
mock = MockMockMock.Mock( "myCallable" )
mock.expect.call( 42 ).andReturn( 72 )
self.assertEqual( self.o.myMethod( mock.object, 42 ), 72 )
mock.tearDown()
def myOtherCallable( obj, mock, **kwds ):
return mock.call( **kwds )
class GithubObjectWithMethodFromCallableWithAlternative( TestCaseWithGithubTestObject ):
GithubTestObject = GithubObject(
"GithubTestObject",
BaseUrl( lambda obj: "/test" ),
InternalSimpleAttributes( "a1", "a2" ),
MethodFromCallable( "myMethod", Alternative( Parameters( [ "mock", "x1", "x2" ], [ "x3" ] ), Parameters( [ "mock", "y1" ], [ "y2" ] ) ), myOtherCallable, SimpleTypePolicy( None ) )
)
def testCallMethod( self ):
mock = MockMockMock.Mock( "myOtherCallable" )
mock.expect.call( x1 = 1, x2 = 2, x3 = 3 ).andReturn( 72 )
self.assertEqual( self.o.myMethod( mock.object, 1, 2, 3 ), 72 )
mock.expect.call( x1 = 1, x2 = 2 ).andReturn( 73 )
self.assertEqual( self.o.myMethod( mock.object, 1, 2 ), 73 )
mock.expect.call( y1 = 1 ).andReturn( 42 )
self.assertEqual( self.o.myMethod( mock.object, 1 ), 42 )
mock.tearDown()
class GithubObjectWithSeveralInternalSimpleAttributesAndInternalObjectAttributes( TestCaseWithGithubTestObject ):
ContainedObject = GithubObject(
"ContainedObject",
BaseUrl( lambda obj: "/test/a3s/" + obj.id ),
InternalSimpleAttributes( "id", "name" )
)
GithubTestObject = GithubObject(
"GithubTestObject",
BaseUrl( lambda obj: "/test" ),
InternalSimpleAttributes( "a2", "a4" ),
InternalSimpleAttributes( "a1", "a3" ),
InternalObjectAttribute( "a5", ContainedObject ),
)
def testCompletionInOneCall_1( self ):
self.expectDataGet( "/test" ).andReturn( {} )
self.assertIsNone( self.o.a3 )
self.assertIsNone( self.o.a4 )
self.assertIsNone( self.o.a5 )
def testCompletionInOneCall_2( self ):
self.expectDataGet( "/test" ).andReturn( {} )
self.assertIsNone( self.o.a4 )
self.assertIsNone( self.o.a3 )
self.assertIsNone( self.o.a5 )
def testCompletionInOneCall_3( self ):
self.expectDataGet( "/test" ).andReturn( {} )
self.assertIsNone( self.o.a5 )
self.assertIsNone( self.o.a3 )
self.assertIsNone( self.o.a4 )
def testCompletionInOneCall_4( self ):
self.expectDataGet( "/test" ).andReturn( {} )
self.assertIsNone( self.o.a5 )
self.assertIsNone( self.o.a4 )
self.assertIsNone( self.o.a3 )
unittest.main()
@@ -1,117 +0,0 @@
import itertools
from ArgumentsChecker import *
from Basic import *
from List import *
from TypePolicies import *
class BadGithubObjectException( Exception ):
pass
def InternalSimpleAttribute( attributeName ):
return InternalAttribute( attributeName, SimpleTypePolicy( None ) )
def InternalSimpleAttributes( *attributeNames ):
return SeveralAttributePolicies( [ InternalSimpleAttribute( attributeName ) for attributeName in attributeNames ], "Attributes" )
def InternalObjectAttribute( attributeName, type ):
return InternalAttribute( attributeName, ObjectTypePolicy( type ) )
def ExternalSimpleAttribute( attributeName, type ):
return ExternalAttribute( attributeName, SimpleTypePolicy( type ) )
def BaseUrl( baseUrl ):
return MethodFromCallable( "_baseUrl", NoParameters(), baseUrl, SimpleTypePolicy( None ) )
def Identity( identity ):
return AttributeFromCallable( "_identity", identity )
def Editable( parameters ):
def __execute( obj, **data ):
attributes = obj._github._dataRequest( "PATCH", obj._baseUrl(), None, data )
obj._updateAttributes( attributes )
return SeveralAttributePolicies( [ MethodFromCallable( "edit", parameters, __execute, SimpleTypePolicy( None ) ) ], "Modification" )
def Deletable():
def __execute( obj ):
obj._github._statusRequest( "DELETE", obj._baseUrl(), None, None )
return SeveralAttributePolicies( [ MethodFromCallable( "delete", NoParameters(), __execute, SimpleTypePolicy( None ) ) ], "Deletion" )
def GithubObject( className, *attributePolicies ):
class GithubObject:
__attributeDefinitions = dict()
__methodDefinitions = dict()
__attributePolicies = list()
@staticmethod
def _addAttributePolicy( attributePolicy ):
GithubObject.__attributePolicies.append( attributePolicy )
attributePolicy.apply( GithubObject )
@staticmethod
def _addAttribute( attributeName, attributeDefinition ):
GithubObject.__checkAttributeName( attributeName )
GithubObject.__attributeDefinitions[ attributeName ] = attributeDefinition
@staticmethod
def _addMethod( methodName, methodDefinition ):
GithubObject.__checkAttributeName( methodName )
GithubObject.__methodDefinitions[ methodName ] = methodDefinition
@staticmethod
def __checkAttributeName( attributeName ):
if attributeName in GithubObject.__attributeDefinitions or attributeName in GithubObject.__methodDefinitions:
raise BadGithubObjectException( "Same attribute defined by two policies" )
def __init__( self, github, attributes, lazy ):
self._github = github
self.__attributes = dict()
self._updateAttributes( attributes )
if not lazy:
for attributeName in GithubObject.__attributeDefinitions:
if attributeName not in self.__attributes:
self.__fetchAttribute( attributeName )
def __getattr__( self, attributeName ):
if attributeName in GithubObject.__methodDefinitions:
return lambda *args, **kwds: GithubObject.__methodDefinitions[ attributeName ]( self, *args, **kwds )
elif attributeName in GithubObject.__attributeDefinitions:
if attributeName not in self.__attributes:
self.__fetchAttribute( attributeName )
return self.__attributes[ attributeName ]
else:
raise AttributeError( attributeName )
def _updateAttributes( self, attributes ):
for attributeName, attributeValue in attributes.iteritems():
try:
attributeDefinition = GithubObject.__attributeDefinitions[ attributeName ]
self.__attributes[ attributeName ] = attributeDefinition.getValueFromRawValue( self, attributeValue )
except KeyError:
self._github._printDebug( "Missing definition of attribute", attributeName, "in class", className )
def _markAsCompleted( self ):
for attributeName, attributeDefinition in GithubObject.__attributeDefinitions.iteritems():
if attributeDefinition.isLazy() and attributeName not in self.__attributes:
self.__attributes[ attributeName ] = None
def __dir__( self ):
return GithubObject.__attributeDefinitions.keys()
def __fetchAttribute( self, attributeName ):
attributeDefinition = GithubObject.__attributeDefinitions[ attributeName ]
attributeDefinition.updateAttributes( self )
@classmethod
def _autoDocument( cls ):
doc = "Class `" + cls.__name__ + "`\n"
doc += "=" * ( len( cls.__name__ ) + 8 ) + "\n"
for attributePolicy in cls.__attributePolicies:
doc += attributePolicy.autoDocument()
doc += "\n"
return doc
GithubObject.__name__ = className
GithubObject._addAttributePolicy( SeveralAttributePolicies( attributePolicies ) )
return GithubObject
-224
View File
@@ -1,224 +0,0 @@
import itertools
from Basic import *
from TypePolicies import *
from ArgumentsChecker import *
class ListCapacity:
def setList( self, attributeName, singularName, typePolicy, url = None ):
self.attributeName = attributeName
self.singularName = singularName
self.safeAttributeName = attributeName.replace( "/", "_" )
self.safeSingularName = singularName.replace( "/", "_" )
self.typePolicy = typePolicy
self.__url = url
def baseUrl( self, obj ):
if self.__url is None:
return obj._baseUrl() + "/" + self.attributeName
else:
return self.__url
class ElementAddable( ListCapacity ):
def apply( self, cls ):
cls._addMethod( "add_to_" + self.safeAttributeName, self.__execute )
def __execute( self, obj, toBeAdded ):
obj._github._statusRequest(
"PUT",
self.baseUrl( obj ) + "/" + self.typePolicy.getIdentity( toBeAdded ),
None,
None
)
def autoDocument( self ):
return "* `add_to_" + self.safeAttributeName + "( " + self.singularName + " )`\n * `" + self.singularName + "`: " + self.typePolicy.documentTypeName() + "\n"
class ElementRemovable( ListCapacity ):
def apply( self, cls ):
cls._addMethod( "remove_from_" + self.safeAttributeName, self.__execute )
def __execute( self, obj, toBeDeleted ):
obj._github._statusRequest(
"DELETE",
self.baseUrl( obj ) + "/" + self.typePolicy.getIdentity( toBeDeleted ),
None,
None
)
def autoDocument( self ):
return "* `remove_from_" + self.safeAttributeName + "( " + self.singularName + " )`\n * `" + self.singularName + "`: " + self.typePolicy.documentTypeName() + "\n"
class ElementHasable( ListCapacity ):
def apply( self, cls ):
cls._addMethod( "has_in_" + self.safeAttributeName, self.__execute )
def __execute( self, obj, toBeQueried ):
return obj._github._statusRequest(
"GET",
self.baseUrl( obj ) + "/" + self.typePolicy.getIdentity( toBeQueried ),
None,
None
) == 204
def autoDocument( self ):
return "* `has_in_" + self.safeAttributeName + "( " + self.singularName + " )`: bool\n * `" + self.singularName + "`: " + self.typePolicy.documentTypeName() + "\n"
class ListCapacityWithModifier( ListCapacity ):
def __init__( self, attributeModifiers ):
self.__attributeModifiers = attributeModifiers
def _modifyAttributes( self, obj, attributes ):
for attributeName, attributeModifier in self.__attributeModifiers.iteritems():
attributes[ attributeName ] = attributeModifier( obj )
return attributes
class ElementCreatable( ListCapacityWithModifier ):
def __init__( self, parameters = NoParameters(), attributeModifiers = {} ):
ListCapacityWithModifier.__init__( self, attributeModifiers )
self.__argumentsChecker = parameters
def apply( self, cls ):
cls._addMethod( "create_" + self.singularName, self.__execute )
def __execute( self, obj, *args, **kwds ):
return self.typePolicy.createLazy(
obj,
self._modifyAttributes(
obj,
obj._github._dataRequest(
"POST",
self.baseUrl( obj ),
None,
self.__argumentsChecker.check( args, kwds )
)
)
)
def autoDocument( self ):
return "* `create_" + self.singularName + "(" + self.__argumentsChecker.documentParameters() + ")`: " + self.typePolicy.documentTypeName() + "\n"
class ElementGetable( ListCapacityWithModifier ):
def __init__( self, parameters = NoParameters(), attributeModifiers = {} ):
ListCapacityWithModifier.__init__( self, attributeModifiers )
self.__argumentsChecker = parameters
def apply( self, cls ):
cls._addMethod( "get_" + self.singularName, self.__execute )
def __execute( self, obj, *args, **kwds ):
return self.typePolicy.createNonLazy(
obj,
self._modifyAttributes(
obj,
self.__argumentsChecker.check( args, kwds )
)
)
def autoDocument( self ):
return "* `get_" + self.singularName + "(" + self.__argumentsChecker.documentParameters() + ")`: " + self.typePolicy.documentTypeName() + "\n"
class SeveralElementsAddable( ListCapacity ):
def apply( self, cls ):
cls._addMethod( "add_to_" + self.safeAttributeName, self.__execute )
def __execute( self, obj, *toBeAddeds ):
obj._github._statusRequest(
"POST",
self.baseUrl( obj ),
None,
[
self.typePolicy.getIdentity( toBeAdded )
for toBeAdded in toBeAddeds
]
)
def autoDocument( self ):
return "* `add_to_" + self.safeAttributeName + "( " + self.singularName + ", ... )`\n * `" + self.singularName + "`: " + self.typePolicy.documentTypeName() + "\n"
class SeveralElementsRemovable( ListCapacity ):
def apply( self, cls ):
cls._addMethod( "remove_from_" + self.safeAttributeName, self.__execute )
def __execute( self, obj, *toBeDeleteds ):
obj._github._statusRequest(
"DELETE",
self.baseUrl( obj ),
None,
[
self.typePolicy.getIdentity( toBeDeleted )
for toBeDeleted in toBeDeleteds
]
)
def autoDocument( self ):
return "* `remove_from_" + self.safeAttributeName + "( " + self.singularName + ", ... )`\n * `" + self.singularName + "`: " + self.typePolicy.documentTypeName() + "\n"
class ListGetable( ListCapacityWithModifier ):
def __init__( self, parameters = NoParameters(), attributeModifiers = {} ):
ListCapacityWithModifier.__init__( self, attributeModifiers )
self.__argumentsChecker = parameters
def apply( self, cls ):
cls._addMethod( "get_" + self.safeAttributeName, self.__execute )
def __execute( self, obj, *args, **kwds ):
params = self.__argumentsChecker.check( args, kwds )
return [
self.typePolicy.createLazy(
obj,
self._modifyAttributes( obj, attributes )
)
for attributes in obj._github._dataRequest(
"GET",
self.baseUrl( obj ),
params,
None
)
]
def autoDocument( self ):
return "* `get_" + self.safeAttributeName + "(" + self.__argumentsChecker.documentParameters() + ")`: list of " + self.typePolicy.documentTypeName() + "\n"
class ListSetable( ListCapacity ):
def apply( self, cls ):
cls._addMethod( "set_" + self.safeAttributeName, self.__execute )
def __execute( self, obj, *toBeSets ):
obj._github._statusRequest(
"PUT",
self.baseUrl( obj ),
None,
[
self.typePolicy.getIdentity( toBeSet )
for toBeSet in toBeSets
]
)
def autoDocument( self ):
return "* `set_" + self.safeAttributeName + "( " + self.singularName + ", ... )`\n * `" + self.singularName + "`: " + self.typePolicy.documentTypeName() + "\n"
class ListDeletable( ListCapacity ):
def apply( self, cls ):
cls._addMethod( "delete_" + self.safeAttributeName, self.__execute )
def __execute( self, obj ):
obj._github._statusRequest(
"DELETE",
self.baseUrl( obj ),
None,
None
)
def autoDocument( self ):
return "* `delete_" + self.safeAttributeName + "()`\n"
def ExternalListOfObjects( attributeName, singularName, type, *capacities, **kwds ):
for capacity in capacities:
capacity.setList( attributeName, singularName, ObjectTypePolicy( type ), **kwds )
return SeveralAttributePolicies( capacities, attributeName.capitalize().replace( "_", " " ).replace( "/", " " ) )
def ExternalListOfSimpleTypes( attributeName, singularName, type, *capacities ):
for capacity in capacities:
capacity.setList( attributeName, singularName, SimpleTypePolicy( type ) )
return SeveralAttributePolicies( capacities, attributeName.capitalize().replace( "_", " " ).replace( "/", " " ) )
@@ -1,35 +0,0 @@
class SimpleTypePolicy:
def __init__( self, type ):
self.__type = type
def createLazy( self, obj, value ):
return value
def getIdentity( self, value ):
return value
def hasMeaningfulDocumentation( self ):
return self.__type is not None
def documentTypeName( self ):
return self.__type
class ObjectTypePolicy:
def __init__( self, type ):
self.__type = type
def createLazy( self, obj, attributes ):
return self.__type( obj._github, attributes, lazy = True )
def createNonLazy( self, obj, attributes ):
return self.__type( obj._github, attributes, lazy = False )
def getIdentity( self, obj ):
assert isinstance( obj, self.__type )
return obj._identity
def hasMeaningfulDocumentation( self ):
return True
def documentTypeName( self ):
return "`" + self.__type.__name__ + "`"
@@ -1 +0,0 @@
from GithubObject import *
+6 -6
View File
@@ -3,8 +3,8 @@
class Hook( object ):
def __init__( self, github, attributes, lazy ):
self.__github = github
def __init__( self, requester, attributes, lazy ):
self.__requester = requester
self.__completed = False
self.__initAttributes()
self.__useAttributes( attributes )
@@ -72,13 +72,13 @@ class Hook( object ):
post_parameters[ "remove_events" ] = remove_events
if active is not None:
post_parameters[ "active" ] = active
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"PATCH",
"https://api.github.com/user",
None,
post_parameters
)
self.__useAttributes( result )
self.__useAttributes( data )
def test( self ):
pass
@@ -100,13 +100,13 @@ class Hook( object ):
# @todo Do not generate __complete if type has no url attribute
def __complete( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.__url,
None,
None
)
self.__useAttributes( result )
self.__useAttributes( data )
self.__completed = True
def __useAttributes( self, attributes ):
+19 -19
View File
@@ -8,8 +8,8 @@ import Milestone
import Label
class Issue( object ):
def __init__( self, github, attributes, lazy ):
self.__github = github
def __init__( self, requester, attributes, lazy ):
self.__requester = requester
self.__completed = False
self.__initAttributes()
self.__useAttributes( attributes )
@@ -125,55 +125,55 @@ class Issue( object ):
post_parameters[ "milestone" ] = milestone
if labels is not None:
post_parameters[ "labels" ] = labels
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"PATCH",
"https://api.github.com/user",
None,
post_parameters
)
self.__useAttributes( result )
self.__useAttributes( data )
def get_comment( self, id ):
pass
def get_comments( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/comments",
None,
None
)
return [
IssueComment.IssueComment( self.__github, element, lazy = True )
for element in result
IssueComment.IssueComment( self.__requester, element, lazy = True )
for element in data
]
def get_events( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/events",
None,
None
)
return [
IssueEvent.IssueEvent( self.__github, element, lazy = True )
for element in result
IssueEvent.IssueEvent( self.__requester, element, lazy = True )
for element in data
]
def get_labels( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/labels",
None,
None
)
return [
Label.Label( self.__github, element, lazy = True )
for element in result
Label.Label( self.__requester, element, lazy = True )
for element in data
]
def remove_from_labels( self, label ):
result = self.__github._statusRequest(
status, headers, data = self.__requester.request(
"DELETE",
self.url + "/labels/" + label.login,
None,
@@ -208,19 +208,19 @@ class Issue( object ):
# @todo Do not generate __complete if type has no url attribute
def __complete( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.__url,
None,
None
)
self.__useAttributes( result )
self.__useAttributes( data )
self.__completed = True
def __useAttributes( self, attributes ):
#@todo No need to check if attribute is in attributes when attribute is mandatory
if "assignee" in attributes:
self.__assignee = NamedUser.NamedUser( self.__github, attributes[ "assignee" ], lazy = True )
self.__assignee = NamedUser.NamedUser( self.__requester, attributes[ "assignee" ], lazy = True )
if "body" in attributes:
self.__body = attributes[ "body" ]
if "closed_at" in attributes:
@@ -238,7 +238,7 @@ class Issue( object ):
if "labels" in attributes:
self.__labels = attributes[ "labels" ]
if "milestone" in attributes:
self.__milestone = Milestone.Milestone( self.__github, attributes[ "milestone" ], lazy = True )
self.__milestone = Milestone.Milestone( self.__requester, attributes[ "milestone" ], lazy = True )
if "number" in attributes:
self.__number = attributes[ "number" ]
if "pull_request" in attributes:
@@ -252,4 +252,4 @@ class Issue( object ):
if "url" in attributes:
self.__url = attributes[ "url" ]
if "user" in attributes:
self.__user = NamedUser.NamedUser( self.__github, attributes[ "user" ], lazy = True )
self.__user = NamedUser.NamedUser( self.__requester, attributes[ "user" ], lazy = True )
+7 -7
View File
@@ -4,8 +4,8 @@
import NamedUser
class IssueComment( object ):
def __init__( self, github, attributes, lazy ):
self.__github = github
def __init__( self, requester, attributes, lazy ):
self.__requester = requester
self.__completed = False
self.__initAttributes()
self.__useAttributes( attributes )
@@ -49,13 +49,13 @@ class IssueComment( object ):
post_parameters = {
"body": body,
}
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"PATCH",
"https://api.github.com/user",
None,
post_parameters
)
self.__useAttributes( result )
self.__useAttributes( data )
def __initAttributes( self ):
self.__body = None
@@ -71,13 +71,13 @@ class IssueComment( object ):
# @todo Do not generate __complete if type has no url attribute
def __complete( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.__url,
None,
None
)
self.__useAttributes( result )
self.__useAttributes( data )
self.__completed = True
def __useAttributes( self, attributes ):
@@ -93,4 +93,4 @@ class IssueComment( object ):
if "url" in attributes:
self.__url = attributes[ "url" ]
if "user" in attributes:
self.__user = NamedUser.NamedUser( self.__github, attributes[ "user" ], lazy = True )
self.__user = NamedUser.NamedUser( self.__requester, attributes[ "user" ], lazy = True )
+5 -5
View File
@@ -4,8 +4,8 @@
import NamedUser
class IssueEvent( object ):
def __init__( self, github, attributes, lazy ):
self.__github = github
def __init__( self, requester, attributes, lazy ):
self.__requester = requester
self.__completed = False
self.__initAttributes()
self.__useAttributes( attributes )
@@ -62,19 +62,19 @@ class IssueEvent( object ):
# @todo Do not generate __complete if type has no url attribute
def __complete( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.__url,
None,
None
)
self.__useAttributes( result )
self.__useAttributes( data )
self.__completed = True
def __useAttributes( self, attributes ):
#@todo No need to check if attribute is in attributes when attribute is mandatory
if "actor" in attributes:
self.__actor = NamedUser.NamedUser( self.__github, attributes[ "actor" ], lazy = True )
self.__actor = NamedUser.NamedUser( self.__requester, attributes[ "actor" ], lazy = True )
if "commit_id" in attributes:
self.__commit_id = attributes[ "commit_id" ]
if "created_at" in attributes:
+6 -6
View File
@@ -3,8 +3,8 @@
class Label( object ):
def __init__( self, github, attributes, lazy ):
self.__github = github
def __init__( self, requester, attributes, lazy ):
self.__requester = requester
self.__completed = False
self.__initAttributes()
self.__useAttributes( attributes )
@@ -34,13 +34,13 @@ class Label( object ):
"name": name,
"color": color,
}
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"PATCH",
"https://api.github.com/user",
None,
post_parameters
)
self.__useAttributes( result )
self.__useAttributes( data )
def __initAttributes( self ):
self.__color = None
@@ -53,13 +53,13 @@ class Label( object ):
# @todo Do not generate __complete if type has no url attribute
def __complete( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.__url,
None,
None
)
self.__useAttributes( result )
self.__useAttributes( data )
self.__completed = True
def __useAttributes( self, attributes ):
+10 -10
View File
@@ -5,8 +5,8 @@ import NamedUser
import Label
class Milestone( object ):
def __init__( self, github, attributes, lazy ):
self.__github = github
def __init__( self, requester, attributes, lazy ):
self.__requester = requester
self.__completed = False
self.__initAttributes()
self.__useAttributes( attributes )
@@ -76,24 +76,24 @@ class Milestone( object ):
post_parameters[ "description" ] = description
if due_on is not None:
post_parameters[ "due_on" ] = due_on
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"PATCH",
"https://api.github.com/user",
None,
post_parameters
)
self.__useAttributes( result )
self.__useAttributes( data )
def get_labels( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/labels",
None,
None
)
return [
Label.Label( self.__github, element, lazy = True )
for element in result
Label.Label( self.__requester, element, lazy = True )
for element in data
]
def __initAttributes( self ):
@@ -114,13 +114,13 @@ class Milestone( object ):
# @todo Do not generate __complete if type has no url attribute
def __complete( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.__url,
None,
None
)
self.__useAttributes( result )
self.__useAttributes( data )
self.__completed = True
def __useAttributes( self, attributes ):
@@ -130,7 +130,7 @@ class Milestone( object ):
if "created_at" in attributes:
self.__created_at = attributes[ "created_at" ]
if "creator" in attributes:
self.__creator = NamedUser.NamedUser( self.__github, attributes[ "creator" ], lazy = True )
self.__creator = NamedUser.NamedUser( self.__requester, attributes[ "creator" ], lazy = True )
if "description" in attributes:
self.__description = attributes[ "description" ]
if "due_on" in attributes:
+27 -27
View File
@@ -8,8 +8,8 @@ import Repository
import NamedUser
class NamedUser( object ):
def __init__( self, github, attributes, lazy ):
self.__github = github
def __init__( self, requester, attributes, lazy ):
self.__requester = requester
self.__completed = False
self.__initAttributes()
self.__useAttributes( attributes )
@@ -150,63 +150,63 @@ class NamedUser( object ):
pass
def get_events( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/events",
None,
None
)
return [
Event.Event( self.__github, element, lazy = True )
for element in result
Event.Event( self.__requester, element, lazy = True )
for element in data
]
def get_followers( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/followers",
None,
None
)
return [
NamedUser( self.__github, element, lazy = True )
for element in result
NamedUser( self.__requester, element, lazy = True )
for element in data
]
def get_following( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/following",
None,
None
)
return [
NamedUser( self.__github, element, lazy = True )
for element in result
NamedUser( self.__requester, element, lazy = True )
for element in data
]
def get_gists( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/gists",
None,
None
)
return [
Gist.Gist( self.__github, element, lazy = True )
for element in result
Gist.Gist( self.__requester, element, lazy = True )
for element in data
]
def get_orgs( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/orgs",
None,
None
)
return [
Organization.Organization( self.__github, element, lazy = True )
for element in result
Organization.Organization( self.__requester, element, lazy = True )
for element in data
]
def get_public_events( self ):
@@ -219,36 +219,36 @@ class NamedUser( object ):
pass
def get_repo( self, name ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
"https://api.github.com/repos/" + self.login + "/" + name,
None,
None
)
return Repository.Repository( self.__github, result, lazy = True )
return Repository.Repository( self.__requester, data, lazy = True )
def get_repos( self, type = None ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/repos",
None,
None
)
return [
Repository.Repository( self.__github, element, lazy = True )
for element in result
Repository.Repository( self.__requester, element, lazy = True )
for element in data
]
def get_watched( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/watched",
None,
None
)
return [
Repository.Repository( self.__github, element, lazy = True )
for element in result
Repository.Repository( self.__requester, element, lazy = True )
for element in data
]
def __initAttributes( self ):
@@ -285,13 +285,13 @@ class NamedUser( object ):
# @todo Do not generate __complete if type has no url attribute
def __complete( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.__url,
None,
None
)
self.__useAttributes( result )
self.__useAttributes( data )
self.__completed = True
def __useAttributes( self, attributes ):
+30 -30
View File
@@ -7,8 +7,8 @@ import Repository
import NamedUser
class Organization( object ):
def __init__( self, github, attributes, lazy ):
self.__github = github
def __init__( self, requester, attributes, lazy ):
self.__requester = requester
self.__completed = False
self.__initAttributes()
self.__useAttributes( attributes )
@@ -136,7 +136,7 @@ class Organization( object ):
return self.__url
def add_to_public_members( self, public_member ):
result = self.__github._statusRequest(
status, headers, data = self.__requester.request(
"PUT",
self.url + "/public_members/" + public_member.login,
None,
@@ -167,103 +167,103 @@ class Organization( object ):
post_parameters[ "location" ] = location
if name is not None:
post_parameters[ "name" ] = name
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"PATCH",
"https://api.github.com/user",
None,
post_parameters
)
self.__useAttributes( result )
self.__useAttributes( data )
def get_events( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/events",
None,
None
)
return [
Event.Event( self.__github, element, lazy = True )
for element in result
Event.Event( self.__requester, element, lazy = True )
for element in data
]
def get_members( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/members",
None,
None
)
return [
NamedUser.NamedUser( self.__github, element, lazy = True )
for element in result
NamedUser.NamedUser( self.__requester, element, lazy = True )
for element in data
]
def get_public_members( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/public_members",
None,
None
)
return [
NamedUser.NamedUser( self.__github, element, lazy = True )
for element in result
NamedUser.NamedUser( self.__requester, element, lazy = True )
for element in data
]
def get_repo( self, name ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
"https://api.github.com/repos/" + self.login + "/" + name,
None,
None
)
return Repository.Repository( self.__github, result, lazy = True )
return Repository.Repository( self.__requester, data, lazy = True )
def get_repos( self, type = None ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/repos",
None,
None
)
return [
Repository.Repository( self.__github, element, lazy = True )
for element in result
Repository.Repository( self.__requester, element, lazy = True )
for element in data
]
def get_teams( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/teams",
None,
None
)
return [
Team.Team( self.__github, element, lazy = True )
for element in result
Team.Team( self.__requester, element, lazy = True )
for element in data
]
def has_in_members( self, member ):
result = self.__github._statusRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/members/" + member.login,
None,
None
)
return result == 204
return status == 204
def has_in_public_members( self, public_member ):
result = self.__github._statusRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/public_members/" + public_member.login,
None,
None
)
return result == 204
return status == 204
def remove_from_members( self, member ):
result = self.__github._statusRequest(
status, headers, data = self.__requester.request(
"DELETE",
self.url + "/members/" + member.login,
None,
@@ -271,7 +271,7 @@ class Organization( object ):
)
def remove_from_public_members( self, public_member ):
result = self.__github._statusRequest(
status, headers, data = self.__requester.request(
"DELETE",
self.url + "/public_members/" + public_member.login,
None,
@@ -310,13 +310,13 @@ class Organization( object ):
# @todo Do not generate __complete if type has no url attribute
def __complete( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.__url,
None,
None
)
self.__useAttributes( result )
self.__useAttributes( data )
self.__completed = True
def __useAttributes( self, attributes ):
+16 -16
View File
@@ -7,8 +7,8 @@ import PullRequestComment
import PullRequestFile
class PullRequest( object ):
def __init__( self, github, attributes, lazy ):
self.__github = github
def __init__( self, requester, attributes, lazy ):
self.__requester = requester
self.__completed = False
self.__initAttributes()
self.__useAttributes( attributes )
@@ -154,51 +154,51 @@ class PullRequest( object ):
post_parameters[ "body" ] = body
if state is not None:
post_parameters[ "state" ] = state
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"PATCH",
"https://api.github.com/user",
None,
post_parameters
)
self.__useAttributes( result )
self.__useAttributes( data )
def get_comment( self, id ):
pass
def get_comments( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/comments",
None,
None
)
return [
PullRequestComment.PullRequestComment( self.__github, element, lazy = True )
for element in result
PullRequestComment.PullRequestComment( self.__requester, element, lazy = True )
for element in data
]
def get_commits( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/commits",
None,
None
)
return [
Commit.Commit( self.__github, element, lazy = True )
for element in result
Commit.Commit( self.__requester, element, lazy = True )
for element in data
]
def get_files( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/files",
None,
None
)
return [
PullRequestFile.PullRequestFile( self.__github, element, lazy = True )
for element in result
PullRequestFile.PullRequestFile( self.__requester, element, lazy = True )
for element in data
]
def is_merged( self ):
@@ -241,13 +241,13 @@ class PullRequest( object ):
# @todo Do not generate __complete if type has no url attribute
def __complete( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.__url,
None,
None
)
self.__useAttributes( result )
self.__useAttributes( data )
self.__completed = True
def __useAttributes( self, attributes ):
@@ -303,4 +303,4 @@ class PullRequest( object ):
if "url" in attributes:
self.__url = attributes[ "url" ]
if "user" in attributes:
self.__user = NamedUser.NamedUser( self.__github, attributes[ "user" ], lazy = True )
self.__user = NamedUser.NamedUser( self.__requester, attributes[ "user" ], lazy = True )
+7 -7
View File
@@ -4,8 +4,8 @@
import NamedUser
class PullRequestComment( object ):
def __init__( self, github, attributes, lazy ):
self.__github = github
def __init__( self, requester, attributes, lazy ):
self.__requester = requester
self.__completed = False
self.__initAttributes()
self.__useAttributes( attributes )
@@ -74,13 +74,13 @@ class PullRequestComment( object ):
post_parameters = {
"body": body,
}
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"PATCH",
"https://api.github.com/user",
None,
post_parameters
)
self.__useAttributes( result )
self.__useAttributes( data )
def __initAttributes( self ):
self.__body = None
@@ -101,13 +101,13 @@ class PullRequestComment( object ):
# @todo Do not generate __complete if type has no url attribute
def __complete( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.__url,
None,
None
)
self.__useAttributes( result )
self.__useAttributes( data )
self.__completed = True
def __useAttributes( self, attributes ):
@@ -133,4 +133,4 @@ class PullRequestComment( object ):
if "url" in attributes:
self.__url = attributes[ "url" ]
if "user" in attributes:
self.__user = NamedUser.NamedUser( self.__github, attributes[ "user" ], lazy = True )
self.__user = NamedUser.NamedUser( self.__requester, attributes[ "user" ], lazy = True )
+4 -4
View File
@@ -3,8 +3,8 @@
class PullRequestFile( object ):
def __init__( self, github, attributes, lazy ):
self.__github = github
def __init__( self, requester, attributes, lazy ):
self.__requester = requester
self.__completed = False
self.__initAttributes()
self.__useAttributes( attributes )
@@ -73,13 +73,13 @@ class PullRequestFile( object ):
# @todo Do not generate __complete if type has no url attribute
def __complete( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.__url,
None,
None
)
self.__useAttributes( result )
self.__useAttributes( data )
self.__completed = True
def __useAttributes( self, attributes ):
+70 -70
View File
@@ -24,8 +24,8 @@ import GitTree
import Label
class Repository( object ):
def __init__( self, github, attributes, lazy ):
self.__github = github
def __init__( self, requester, attributes, lazy ):
self.__requester = requester
self.__completed = False
self.__initAttributes()
self.__useAttributes( attributes )
@@ -183,7 +183,7 @@ class Repository( object ):
return self.__watchers
def add_to_collaborators( self, collaborator ):
result = self.__github._statusRequest(
status, headers, data = self.__requester.request(
"PUT",
self.url + "/collaborators/" + collaborator.login,
None,
@@ -242,117 +242,117 @@ class Repository( object ):
post_parameters[ "has_wiki" ] = has_wiki
if has_downloads is not None:
post_parameters[ "has_downloads" ] = has_downloads
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"PATCH",
"https://api.github.com/user",
None,
post_parameters
)
self.__useAttributes( result )
self.__useAttributes( data )
def get_branches( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/branches",
None,
None
)
return [
Branch.Branch( self.__github, element, lazy = True )
for element in result
Branch.Branch( self.__requester, element, lazy = True )
for element in data
]
def get_collaborators( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/collaborators",
None,
None
)
return [
NamedUser.NamedUser( self.__github, element, lazy = True )
for element in result
NamedUser.NamedUser( self.__requester, element, lazy = True )
for element in data
]
def get_comment( self, id ):
pass
def get_comments( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/comments",
None,
None
)
return [
CommitComment.CommitComment( self.__github, element, lazy = True )
for element in result
CommitComment.CommitComment( self.__requester, element, lazy = True )
for element in data
]
def get_commit( self, sha ):
pass
def get_commits( self, sha = None, path = None ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/commits",
None,
None
)
return [
Commit.Commit( self.__github, element, lazy = True )
for element in result
Commit.Commit( self.__requester, element, lazy = True )
for element in data
]
def get_contributors( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/contributors",
None,
None
)
return [
NamedUser.NamedUser( self.__github, element, lazy = True )
for element in result
NamedUser.NamedUser( self.__requester, element, lazy = True )
for element in data
]
def get_download( self, id ):
pass
def get_downloads( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/downloads",
None,
None
)
return [
Download.Download( self.__github, element, lazy = True )
for element in result
Download.Download( self.__requester, element, lazy = True )
for element in data
]
def get_events( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/events",
None,
None
)
return [
Event.Event( self.__github, element, lazy = True )
for element in result
Event.Event( self.__requester, element, lazy = True )
for element in data
]
def get_forks( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/forks",
None,
None
)
return [
Repository( self.__github, element, lazy = True )
for element in result
Repository( self.__requester, element, lazy = True )
for element in data
]
def get_git_blob( self, sha ):
@@ -365,15 +365,15 @@ class Repository( object ):
pass
def get_git_refs( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/git_refs",
None,
None
)
return [
GitRef.GitRef( self.__github, element, lazy = True )
for element in result
GitRef.GitRef( self.__requester, element, lazy = True )
for element in data
]
def get_git_tag( self, sha ):
@@ -386,75 +386,75 @@ class Repository( object ):
pass
def get_hooks( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/hooks",
None,
None
)
return [
Hook.Hook( self.__github, element, lazy = True )
for element in result
Hook.Hook( self.__requester, element, lazy = True )
for element in data
]
def get_issue( self, number ):
pass
def get_issues( self, milestone = None, state = None, assignee = None, mentioned = None, labels = None, sort = None, direction = None, since = None ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/issues",
None,
None
)
return [
Issue.Issue( self.__github, element, lazy = True )
for element in result
Issue.Issue( self.__requester, element, lazy = True )
for element in data
]
def get_issues_event( self, id ):
pass
def get_issues_events( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/issues_events",
None,
None
)
return [
IssueEvent.IssueEvent( self.__github, element, lazy = True )
for element in result
IssueEvent.IssueEvent( self.__requester, element, lazy = True )
for element in data
]
def get_key( self, id ):
pass
def get_keys( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/keys",
None,
None
)
return [
RepositoryKey.RepositoryKey( self.__github, element, lazy = True )
for element in result
RepositoryKey.RepositoryKey( self.__requester, element, lazy = True )
for element in data
]
def get_label( self, name ):
pass
def get_labels( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/labels",
None,
None
)
return [
Label.Label( self.__github, element, lazy = True )
for element in result
Label.Label( self.__requester, element, lazy = True )
for element in data
]
def get_languages( self ):
@@ -464,15 +464,15 @@ class Repository( object ):
pass
def get_milestones( self, state = None, sort = None, direction = None ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/milestones",
None,
None
)
return [
Milestone.Milestone( self.__github, element, lazy = True )
for element in result
Milestone.Milestone( self.__requester, element, lazy = True )
for element in data
]
def get_network_events( self ):
@@ -482,64 +482,64 @@ class Repository( object ):
pass
def get_pulls( self, state = None ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/pulls",
None,
None
)
return [
PullRequest.PullRequest( self.__github, element, lazy = True )
for element in result
PullRequest.PullRequest( self.__requester, element, lazy = True )
for element in data
]
def get_tags( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/tags",
None,
None
)
return [
Tag.Tag( self.__github, element, lazy = True )
for element in result
Tag.Tag( self.__requester, element, lazy = True )
for element in data
]
def get_teams( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/teams",
None,
None
)
return [
Team.Team( self.__github, element, lazy = True )
for element in result
Team.Team( self.__requester, element, lazy = True )
for element in data
]
def get_watchers( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/watchers",
None,
None
)
return [
NamedUser.NamedUser( self.__github, element, lazy = True )
for element in result
NamedUser.NamedUser( self.__requester, element, lazy = True )
for element in data
]
def has_in_collaborators( self, collaborator ):
result = self.__github._statusRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/collaborators/" + collaborator.login,
None,
None
)
return result == 204
return status == 204
def remove_from_collaborators( self, collaborator ):
result = self.__github._statusRequest(
status, headers, data = self.__requester.request(
"DELETE",
self.url + "/collaborators/" + collaborator.login,
None,
@@ -584,13 +584,13 @@ class Repository( object ):
# @todo Do not generate __complete if type has no url attribute
def __complete( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.__url,
None,
None
)
self.__useAttributes( result )
self.__useAttributes( data )
self.__completed = True
def __useAttributes( self, attributes ):
@@ -632,9 +632,9 @@ class Repository( object ):
if "organization" in attributes:
self.__organization = attributes[ "organization" ]
if "owner" in attributes:
self.__owner = NamedUser.NamedUser( self.__github, attributes[ "owner" ], lazy = True )
self.__owner = NamedUser.NamedUser( self.__requester, attributes[ "owner" ], lazy = True )
if "parent" in attributes:
self.__parent = Repository( self.__github, attributes[ "parent" ], lazy = True )
self.__parent = Repository( self.__requester, attributes[ "parent" ], lazy = True )
if "permissions" in attributes:
self.__permissions = attributes[ "permissions" ]
if "private" in attributes:
@@ -644,7 +644,7 @@ class Repository( object ):
if "size" in attributes:
self.__size = attributes[ "size" ]
if "source" in attributes:
self.__source = Repository( self.__github, attributes[ "source" ], lazy = True )
self.__source = Repository( self.__requester, attributes[ "source" ], lazy = True )
if "ssh_url" in attributes:
self.__ssh_url = attributes[ "ssh_url" ]
if "svn_url" in attributes:
+6 -6
View File
@@ -3,8 +3,8 @@
class RepositoryKey( object ):
def __init__( self, github, attributes, lazy ):
self.__github = github
def __init__( self, requester, attributes, lazy ):
self.__requester = requester
self.__completed = False
self.__initAttributes()
self.__useAttributes( attributes )
@@ -39,13 +39,13 @@ class RepositoryKey( object ):
"title": title,
"key": key,
}
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"PATCH",
"https://api.github.com/user",
None,
post_parameters
)
self.__useAttributes( result )
self.__useAttributes( data )
def __initAttributes( self ):
self.__id = None
@@ -59,13 +59,13 @@ class RepositoryKey( object ):
# @todo Do not generate __complete if type has no url attribute
def __complete( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.__url,
None,
None
)
self.__useAttributes( result )
self.__useAttributes( data )
self.__completed = True
def __useAttributes( self, attributes ):
+5 -5
View File
@@ -4,8 +4,8 @@
import Commit
class Tag( object ):
def __init__( self, github, attributes, lazy ):
self.__github = github
def __init__( self, requester, attributes, lazy ):
self.__requester = requester
self.__completed = False
self.__initAttributes()
self.__useAttributes( attributes )
@@ -44,19 +44,19 @@ class Tag( object ):
# @todo Do not generate __complete if type has no url attribute
def __complete( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.__url,
None,
None
)
self.__useAttributes( result )
self.__useAttributes( data )
self.__completed = True
def __useAttributes( self, attributes ):
#@todo No need to check if attribute is in attributes when attribute is mandatory
if "commit" in attributes:
self.__commit = Commit.Commit( self.__github, attributes[ "commit" ], lazy = True )
self.__commit = Commit.Commit( self.__requester, attributes[ "commit" ], lazy = True )
if "name" in attributes:
self.__name = attributes[ "name" ]
if "tarball_url" in attributes:
+20 -20
View File
@@ -5,8 +5,8 @@ import Repository
import NamedUser
class Team( object ):
def __init__( self, github, attributes, lazy ):
self.__github = github
def __init__( self, requester, attributes, lazy ):
self.__requester = requester
self.__completed = False
self.__initAttributes()
self.__useAttributes( attributes )
@@ -44,7 +44,7 @@ class Team( object ):
return self.__url
def add_to_members( self, member ):
result = self.__github._statusRequest(
status, headers, data = self.__requester.request(
"PUT",
self.url + "/members/" + member.login,
None,
@@ -52,7 +52,7 @@ class Team( object ):
)
def add_to_repos( self, repo ):
result = self.__github._statusRequest(
status, headers, data = self.__requester.request(
"PUT",
self.url + "/repos/" + repo.login,
None,
@@ -68,58 +68,58 @@ class Team( object ):
}
if permission is not None:
post_parameters[ "permission" ] = permission
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"PATCH",
"https://api.github.com/user",
None,
post_parameters
)
self.__useAttributes( result )
self.__useAttributes( data )
def get_members( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/members",
None,
None
)
return [
NamedUser.NamedUser( self.__github, element, lazy = True )
for element in result
NamedUser.NamedUser( self.__requester, element, lazy = True )
for element in data
]
def get_repos( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/repos",
None,
None
)
return [
Repository.Repository( self.__github, element, lazy = True )
for element in result
Repository.Repository( self.__requester, element, lazy = True )
for element in data
]
def has_in_members( self, member ):
result = self.__github._statusRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/members/" + member.login,
None,
None
)
return result == 204
return status == 204
def has_in_repos( self, repo ):
result = self.__github._statusRequest(
status, headers, data = self.__requester.request(
"GET",
self.url + "/repos/" + repo.login,
None,
None
)
return result == 204
return status == 204
def remove_from_members( self, member ):
result = self.__github._statusRequest(
status, headers, data = self.__requester.request(
"DELETE",
self.url + "/members/" + member.login,
None,
@@ -127,7 +127,7 @@ class Team( object ):
)
def remove_from_repos( self, repo ):
result = self.__github._statusRequest(
status, headers, data = self.__requester.request(
"DELETE",
self.url + "/repos/" + repo.login,
None,
@@ -148,13 +148,13 @@ class Team( object ):
# @todo Do not generate __complete if type has no url attribute
def __complete( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.__url,
None,
None
)
self.__useAttributes( result )
self.__useAttributes( data )
self.__completed = True
def __useAttributes( self, attributes ):
+6 -6
View File
@@ -3,8 +3,8 @@
class UserKey( object ):
def __init__( self, github, attributes, lazy ):
self.__github = github
def __init__( self, requester, attributes, lazy ):
self.__requester = requester
self.__completed = False
self.__initAttributes()
self.__useAttributes( attributes )
@@ -41,13 +41,13 @@ class UserKey( object ):
post_parameters[ "title" ] = title
if key is not None:
post_parameters[ "key" ] = key
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"PATCH",
"https://api.github.com/user",
None,
post_parameters
)
self.__useAttributes( result )
self.__useAttributes( data )
def __initAttributes( self ):
self.__id = None
@@ -61,13 +61,13 @@ class UserKey( object ):
# @todo Do not generate __complete if type has no url attribute
def __complete( self ):
result = self.__github._dataRequest(
status, headers, data = self.__requester.request(
"GET",
self.__url,
None,
None
)
self.__useAttributes( result )
self.__useAttributes( data )
self.__completed = True
def __useAttributes( self, attributes ):
+3 -36
View File
@@ -10,40 +10,7 @@ class Requester:
def __init__( self, login, password ):
self.__authorizationHeader = "Basic " + base64.b64encode( login + ":" + password ).replace( '\n', '' )
def dataRequest( self, verb, url, parameters, input ):
if parameters is None:
parameters = dict()
headers, output = self.__statusCheckedRequest( verb, url, parameters, input )
obviouslyFinished = False
pageCount = 1
while "link" in headers and "next" in headers[ "link" ] and not obviouslyFinished and pageCount < 10:
for link in headers[ "link" ].split( "," ):
if "next" in link:
linkUrl = link.split( ";" )[ 0 ][ : -1 ]
params = linkUrl.split( "?" )[ 1 ]
parameters.update( dict( p.split( "=" ) for p in params.split( "&" ) ) )
break
headers, newOutput = self.__statusCheckedRequest( verb, url, parameters, input )
pageCount += 1
if len( newOutput ) == 0:
obviouslyFinished = True
output += newOutput
return output
def __statusCheckedRequest( self, verb, url, parameters, input ):
status, headers, output = self.__rawRequest( verb, url, parameters, input )
if status < 200 or status >= 300:
raise UnknownGithubObject()
return headers, output
def statusRequest( self, verb, url, parameters, input ):
status, headers, output = self.__rawRequest( verb, url, parameters, input )
return status
def __rawRequest( self, verb, url, parameters, input ):
def request( self, verb, url, parameters, input ):
assert verb in [ "HEAD", "GET", "POST", "PATCH", "PUT", "DELETE" ]
assert url.startswith( "https://api.github.com" )
url = url[ len( "https://api.github.com" ) : ]
@@ -59,7 +26,7 @@ class Requester:
status = response.status
headers = dict( response.getheaders() )
output = self.__strucutredFromJson( response.read() )
output = self.__structuredFromJson( response.read() )
cnx.close()
@@ -72,7 +39,7 @@ class Requester:
else:
return url + "?" + urllib.urlencode( parameters )
def __strucutredFromJson( self, data ):
def __structuredFromJson( self, data ):
if len( data ) == 0:
return None
else: