From 590798d349cba7de6e83b43aa5d4f8b0a38e685d Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Tue, 17 Apr 2012 18:18:09 +0100 Subject: [PATCH 1/3] Do not fail if Github adds an attribute in an object --- github/GithubObjects/GithubObject/GithubObject.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/github/GithubObjects/GithubObject/GithubObject.py b/github/GithubObjects/GithubObject/GithubObject.py index 30d515e9..f8b56fb8 100644 --- a/github/GithubObjects/GithubObject/GithubObject.py +++ b/github/GithubObjects/GithubObject/GithubObject.py @@ -84,8 +84,11 @@ def GithubObject( className, *attributePolicies ): def _updateAttributes( self, attributes ): for attributeName, attributeValue in attributes.iteritems(): - attributeDefinition = GithubObject.__attributeDefinitions[ attributeName ] - self.__attributes[ attributeName ] = attributeDefinition.getValueFromRawValue( self, attributeValue ) + try: + attributeDefinition = GithubObject.__attributeDefinitions[ attributeName ] + self.__attributes[ attributeName ] = attributeDefinition.getValueFromRawValue( self, attributeValue ) + except KeyError: + pass def _markAsCompleted( self ): for attributeName, attributeDefinition in GithubObject.__attributeDefinitions.iteritems(): From 2f64b625f7e2afc9bef61d0decb459e2ef65c550 Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Tue, 17 Apr 2012 18:21:36 +0100 Subject: [PATCH 2/3] Repository.permissions --- github/GithubObjects/Repository.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/GithubObjects/Repository.py b/github/GithubObjects/Repository.py index 8dcb824c..81ce8111 100644 --- a/github/GithubObjects/Repository.py +++ b/github/GithubObjects/Repository.py @@ -34,7 +34,7 @@ Repository = GithubObject( "pushed_at", "created_at", "organization", "has_issues", "has_wiki", "has_downloads", # Not documented - "mirror_url", "updated_at", "id", + "mirror_url", "updated_at", "id", "permissions", ), InternalObjectAttribute( "owner", NamedUser ), ) From e5ae923a68a9ae295ce5aa20b1227253de60e918 Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Tue, 17 Apr 2012 18:47:11 +0100 Subject: [PATCH 3/3] Add facilities for uniform debug printing --- github/Github.UnitTest.py | 10 ++++++++-- github/Github.py | 7 ++++++- github/GithubObjects/GithubObject/GithubObject.py | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/github/Github.UnitTest.py b/github/Github.UnitTest.py index b36664f1..73d75064 100644 --- a/github/Github.UnitTest.py +++ b/github/Github.UnitTest.py @@ -7,9 +7,10 @@ class TestCase( unittest.TestCase ): def setUp( self ): unittest.TestCase.setUp( self ) - self.g = Github( "login", "password" ) - self.requester = MockMockMock.Mock( "requester" ) + self.debugFile = MockMockMock.Mock( "debugFile", self.requester ) + + self.g = Github( "login", "password", self.debugFile.object ) self.g._Github__requester = self.requester.object def tearDown( self ): @@ -109,4 +110,9 @@ class TestCase( unittest.TestCase ): self.requester.expect.dataRequest( "GET", "/repos/xxx/yyy/compare/foo...bar", None, None ).andReturn( { "gabu": "zomeuh" } ) self.assertEqual( self.g.get_user().get_repo( "yyy" ).compare( "foo", "bar" ), { "gabu": "zomeuh" } ) + def testDebugPrint( self ): + self.requester.expect.dataRequest( "GET", "/user", None, None ).andReturn( { "login": "xxx", "unknownAttribute": 42 } ) + self.debugFile.expect.write( "Missing definition of attribute unknownAttribute in class AuthenticatedUser\n" ) + self.g.get_user().location + unittest.main() diff --git a/github/Github.py b/github/Github.py index db5f6e57..e6373d6e 100644 --- a/github/Github.py +++ b/github/Github.py @@ -2,8 +2,9 @@ from Requester import Requester from GithubObjects import * class Github: - def __init__( self, login, password ): + def __init__( self, login, password, debugFile = None ): self.__requester = Requester( login, password ) + self.__debugFile = debugFile def _dataRequest( self, verb, url, parameters, data ): return self.__requester.dataRequest( verb, url, parameters, data ) @@ -29,3 +30,7 @@ class Github: 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" ) diff --git a/github/GithubObjects/GithubObject/GithubObject.py b/github/GithubObjects/GithubObject/GithubObject.py index f8b56fb8..72464749 100644 --- a/github/GithubObjects/GithubObject/GithubObject.py +++ b/github/GithubObjects/GithubObject/GithubObject.py @@ -88,7 +88,7 @@ def GithubObject( className, *attributePolicies ): attributeDefinition = GithubObject.__attributeDefinitions[ attributeName ] self.__attributes[ attributeName ] = attributeDefinition.getValueFromRawValue( self, attributeValue ) except KeyError: - pass + self._github._printDebug( "Missing definition of attribute", attributeName, "in class", className ) def _markAsCompleted( self ): for attributeName, attributeDefinition in GithubObject.__attributeDefinitions.iteritems():