diff --git a/README.rst b/README.rst index f072c3b7..f9384deb 100644 --- a/README.rst +++ b/README.rst @@ -10,6 +10,11 @@ PyGithub is stable. I will maintain it up to date with the API, and fix bugs if What's new? =========== +Version 1.12.2 (March 3rd, 2013) +-------------------------------- + +* `Fix `_ major issue with Python 3: Json decoding was broken. Thank you `bilderbuchi `_ for reporting + Version 1.12.1 (February 20th, 2013) ------------------------------------ diff --git a/doc/changes.rst b/doc/changes.rst index bf96964f..1191777e 100644 --- a/doc/changes.rst +++ b/doc/changes.rst @@ -4,6 +4,11 @@ Change log Stable versions ~~~~~~~~~~~~~~~ +Version 1.12.2 (March 3rd, 2013) +-------------------------------- + +* `Fix `_ major issue with Python 3: Json decoding was broken. Thank you `bilderbuchi `_ for reporting + Version 1.12.1 (February 20th, 2013) ------------------------------------ diff --git a/github/Requester.py b/github/Requester.py index 76ffc65b..59c6c37c 100644 --- a/github/Requester.py +++ b/github/Requester.py @@ -40,6 +40,11 @@ class Requester: cls.__httpConnectionClass = httpConnectionClass cls.__httpsConnectionClass = httpsConnectionClass + @classmethod + def resetConnectionClasses(cls): + cls.__httpConnectionClass = httplib.HTTPConnection + cls.__httpsConnectionClass = httplib.HTTPSConnection + def __init__(self, login_or_token, password, base_url, timeout, client_id, client_secret, user_agent): if password is not None: login = login_or_token @@ -91,6 +96,8 @@ class Requester: if len(data) == 0: return None else: + if atLeastPython3 and isinstance(data, bytes): # pragma no branch + data = data.decode("utf-8") # pragma no cover return json.loads(data) def requestJson(self, verb, url, parameters, input): @@ -192,10 +199,12 @@ class Requester: return url + "?" + urllib.urlencode(parameters) def __createConnection(self): - if atLeastPython26: - return self.__connectionClass(host=self.__hostname, port=self.__port, strict=True, timeout=self.__timeout) - else: # pragma no cover - return self.__connectionClass(host=self.__hostname, port=self.__port, strict=True) # pragma no cover + kwds = {} + if not atLeastPython3: # pragma no branch + kwds["strict"] = True # Useless in Python3, would generate a deprecation warning + if atLeastPython26: # pragma no branch + kwds["timeout"] = self.__timeout # Did not exist before Python2.6 + return self.__connectionClass(host=self.__hostname, port=self.__port, **kwds) def __log(self, verb, url, requestHeaders, input, status, responseHeaders, output): logger = logging.getLogger(__name__) diff --git a/github/tests/AllTests.py b/github/tests/AllTests.py index b9c8ae87..c72489f8 100644 --- a/github/tests/AllTests.py +++ b/github/tests/AllTests.py @@ -65,3 +65,4 @@ from Issue133 import * from Issue134 import * from Issue139 import * from Issue140 import * +from Issue142 import * diff --git a/github/tests/Framework.py b/github/tests/Framework.py index 4eca1925..9cd5b4df 100644 --- a/github/tests/Framework.py +++ b/github/tests/Framework.py @@ -157,6 +157,7 @@ class BasicTestCase(unittest.TestCase): def tearDown(self): unittest.TestCase.tearDown(self) self.__closeReplayFileIfNeeded() + github.Requester.Requester.resetConnectionClasses() def __openFile(self, mode): for (_, _, functionName, _) in traceback.extract_stack(): diff --git a/github/tests/Issue142.py b/github/tests/Issue142.py new file mode 100644 index 00000000..66d7439f --- /dev/null +++ b/github/tests/Issue142.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- + +# Copyright 2012 Vincent Jacques +# vincent@vincent-jacques.net + +# This file is part of PyGithub. http://jacquev6.github.com/PyGithub/ + +# PyGithub is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + +# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + +# You should have received a copy of the GNU Lesser General Public License along with PyGithub. If not, see . + +import unittest +import github + + +class Issue142(unittest.TestCase): # https://github.com/jacquev6/PyGithub/issues/140 + def testDecodeJson(self): + # This test has to hit GitHub for real, because the record-replay framework looses types + # and python3 does not behave like python3 for strings and bytes + self.assertEqual(github.Github().get_user("jacquev6").name, "Vincent Jacques") diff --git a/setup.py b/setup.py index 42387a67..bd887634 100755 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ import subprocess import shutil import os.path -version = "1.12.1" +version = "1.12.2" def execute(*args):