From 6735be4933780c56eca29a7f5a01b35b40ab0c13 Mon Sep 17 00:00:00 2001 From: Hugo Date: Thu, 21 Dec 2017 08:52:00 +0200 Subject: [PATCH] Drop support for EOL Python 2.5-2.6 and 3.2-3.3 (#674) --- .travis.yml | 3 --- github/Repository.py | 1 - github/Requester.py | 27 +++++++++++---------------- github/tests/BadAttributes.py | 5 +---- github/tests/Exceptions.py | 7 +++---- github/tests/Framework.py | 16 ++++++---------- github/tests/Logging_.py | 12 ++++++------ github/tests/Persistence.py | 5 +---- python25-requirements.txt | 1 - setup.py | 5 +---- 10 files changed, 29 insertions(+), 53 deletions(-) delete mode 100644 python25-requirements.txt diff --git a/.travis.yml b/.travis.yml index db6c6d1f..82072d9d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,6 @@ language: python python: -- '2.6' - '2.7' -- '3.2' -- '3.3' - '3.4' - '3.5' - '3.6' diff --git a/github/Repository.py b/github/Repository.py index b9f8c71b..66f6065d 100644 --- a/github/Repository.py +++ b/github/Repository.py @@ -73,7 +73,6 @@ import github.StatsParticipation import github.StatsPunchCard import github.Stargazer -atLeastPython26 = sys.hexversion >= 0x02060000 atLeastPython3 = sys.hexversion >= 0x03000000 diff --git a/github/Requester.py b/github/Requester.py index 5903b7d6..3fda707b 100644 --- a/github/Requester.py +++ b/github/Requester.py @@ -33,27 +33,23 @@ # # # ############################################################################## -import logging -import httplib import base64 +import httplib +import json +import logging +import mimetypes +import os +import re +import sys import urllib import urlparse -import sys -import Consts -import re -import os -import mimetypes from io import IOBase -atLeastPython26 = sys.hexversion >= 0x02060000 +import Consts +import GithubException + atLeastPython3 = sys.hexversion >= 0x03000000 -if atLeastPython26: - import json -else: # pragma no cover (Covered by all tests with Python 2.5) - import simplejson as json # pragma no cover (Covered by all tests with Python 2.5) - -import GithubException class Requester: @@ -347,8 +343,7 @@ class Requester: kwds = {} if not atLeastPython3: # pragma no branch (Branch useful only with Python 3) kwds["strict"] = True # Useless in Python3, would generate a deprecation warning - if atLeastPython26: # pragma no branch (Branch useful only with Python 2.5) - kwds["timeout"] = self.__timeout # Did not exist before Python2.6 + kwds["timeout"] = self.__timeout ## ## Connect through a proxy server with authentication, if http_proxy diff --git a/github/tests/BadAttributes.py b/github/tests/BadAttributes.py index 2b84cab8..d267bb10 100755 --- a/github/tests/BadAttributes.py +++ b/github/tests/BadAttributes.py @@ -56,10 +56,7 @@ class BadAttributes(Framework.TestCase): self.assertEqual(e.actual_value, "foobar") self.assertEqual(e.expected_type, (str, unicode)) self.assertEqual(e.transformation_exception.__class__, ValueError) - if Framework.atLeastPython26: - self.assertEqual(e.transformation_exception.args, ("time data 'foobar' does not match format '%Y-%m-%dT%H:%M:%SZ'",)) - else: - self.assertEqual(e.transformation_exception.args, ('time data did not match format: data=foobar fmt=%Y-%m-%dT%H:%M:%SZ',)) + self.assertEqual(e.transformation_exception.args, ("time data 'foobar' does not match format '%Y-%m-%dT%H:%M:%SZ'",)) self.assertTrue(raised) def testBadTransformedAttribute(self): diff --git a/github/tests/Exceptions.py b/github/tests/Exceptions.py index 23265c11..4d8dece3 100644 --- a/github/tests/Exceptions.py +++ b/github/tests/Exceptions.py @@ -30,7 +30,6 @@ import pickle import Framework -atLeastPython26 = sys.hexversion >= 0x02060000 atMostPython2 = sys.hexversion < 0x03000000 @@ -82,7 +81,7 @@ class Exceptions(Framework.TestCase): # To stay compatible with Python 2.6, we raised = True self.assertEqual(exception.status, 404) self.assertEqual(exception.data, {"message": "Not Found"}) - if atLeastPython26 and atMostPython2: + if atMostPython2: self.assertEqual(str(exception), "404 {u'message': u'Not Found'}") else: self.assertEqual(str(exception), "404 {'message': 'Not Found'}") # pragma no cover (Covered with Python 3) @@ -96,7 +95,7 @@ class Exceptions(Framework.TestCase): # To stay compatible with Python 2.6, we raised = True self.assertEqual(exception.status, 404) self.assertEqual(exception.data, {"message": "Not Found"}) - if atLeastPython26 and atMostPython2: + if atMostPython2: self.assertEqual(str(exception), "404 {u'message': u'Not Found'}") else: self.assertEqual(str(exception), "404 {'message': 'Not Found'}") # pragma no cover (Covered with Python 3) @@ -110,7 +109,7 @@ class Exceptions(Framework.TestCase): # To stay compatible with Python 2.6, we raised = True self.assertEqual(exception.status, 401) self.assertEqual(exception.data, {"message": "Bad credentials"}) - if atLeastPython26 and atMostPython2: + if atMostPython2: self.assertEqual(str(exception), "401 {u'message': u'Bad credentials'}") else: self.assertEqual(str(exception), "401 {'message': 'Bad credentials'}") # pragma no cover (Covered with Python 3) diff --git a/github/tests/Framework.py b/github/tests/Framework.py index 5557c054..8cd8fbce 100644 --- a/github/tests/Framework.py +++ b/github/tests/Framework.py @@ -25,22 +25,18 @@ # # # ############################################################################## +import httplib +import json import os import sys -import unittest -import httplib import traceback +import unittest import github -atLeastPython26 = sys.hexversion >= 0x02060000 +python2 = sys.hexversion < 0x03000000 atLeastPython3 = sys.hexversion >= 0x03000000 -atMostPython32 = sys.hexversion < 0x03030000 -if atLeastPython26: - import json -else: # pragma no cover (Covered by all tests with Python 2.5) - import simplejson as json # pragma no cover (Covered by all tests with Python 2.5) def readLine(file): @@ -153,8 +149,8 @@ class ReplayingConnection: if isinstance(input, (str, unicode)): if input.startswith("{"): self.__testCase.assertEqual(json.loads(input.replace('\n', '').replace('\r', '')), json.loads(expectedInput)) - elif atMostPython32: # @todo Test in all cases, including Python 3.3 - # In Python 3.3, dicts are not output in the same order as in Python 2.5 -> 3.2. + elif python2: # @todo Test in all cases, including Python 3.4+ + # In Python 3.4+, dicts are not output in the same order as in Python 2.7. # So, form-data encoding is not deterministic and is difficult to test. self.__testCase.assertEqual(input.replace('\n', '').replace('\r', ''), expectedInput) else: diff --git a/github/tests/Logging_.py b/github/tests/Logging_.py index 769fdc7d..4ce93d41 100644 --- a/github/tests/Logging_.py +++ b/github/tests/Logging_.py @@ -31,7 +31,7 @@ import github import Framework -atMostPython32 = sys.hexversion < 0x03030000 +python2 = sys.hexversion < 0x03000000 class Logging(Framework.BasicTestCase): @@ -52,23 +52,23 @@ class Logging(Framework.BasicTestCase): def testLoggingWithBasicAuthentication(self): self.assertEqual(github.Github(self.login, self.password).get_user().name, "Vincent Jacques") - # In Python 3.3, dicts are not output in the same order as in Python 2.5 -> 3.2. + # In Python 3.4+, dicts are not output in the same order as in Python 2.7. # So, logging is not deterministic and we cannot test it. - if atMostPython32: + if python2: self.assertEqual(self.__handler.handled, 'GET https://api.github.com/user {\'Authorization\': \'Basic (login and password removed)\', \'User-Agent\': \'PyGithub/Python\'} null ==> 200 {\'status\': \'200 OK\', \'content-length\': \'806\', \'x-github-media-type\': \'github.beta; format=json\', \'x-content-type-options\': \'nosniff\', \'vary\': \'Accept, Authorization, Cookie\', \'x-ratelimit-remaining\': \'4993\', \'server\': \'nginx\', \'last-modified\': \'Fri, 14 Sep 2012 18:47:46 GMT\', \'connection\': \'keep-alive\', \'x-ratelimit-limit\': \'5000\', \'etag\': \'"434dfe5d3f50558fe3cea087cb95c401"\', \'cache-control\': \'private, s-maxage=60, max-age=60\', \'date\': \'Mon, 17 Sep 2012 17:12:32 GMT\', \'content-type\': \'application/json; charset=utf-8\'} {"owned_private_repos":3,"disk_usage":18612,"following":28,"type":"User","public_repos":13,"location":"Paris, France","company":"Criteo","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png","plan":{"space":614400,"private_repos":5,"name":"micro","collaborators":1},"blog":"http://vincent-jacques.net","login":"jacquev6","public_gists":3,"html_url":"https://github.com/jacquev6","hireable":false,"created_at":"2010-07-09T06:10:06Z","private_gists":5,"followers":13,"name":"Vincent Jacques","email":"vincent@vincent-jacques.net","bio":"","total_private_repos":3,"collaborators":0,"gravatar_id":"b68de5ae38616c296fa345d2b9df2225","id":327146,"url":"https://api.github.com/users/jacquev6"}') def testLoggingWithOAuthAuthentication(self): self.assertEqual(github.Github(self.oauth_token).get_user().name, "Vincent Jacques") - if atMostPython32: + if python2: self.assertEqual(self.__handler.handled, 'GET https://api.github.com/user {\'Authorization\': \'token (oauth token removed)\', \'User-Agent\': \'PyGithub/Python\'} null ==> 200 {\'status\': \'200 OK\', \'x-ratelimit-remaining\': \'4993\', \'x-github-media-type\': \'github.beta; format=json\', \'x-content-type-options\': \'nosniff\', \'vary\': \'Accept, Authorization, Cookie\', \'content-length\': \'628\', \'server\': \'nginx\', \'last-modified\': \'Tue, 25 Sep 2012 07:42:42 GMT\', \'connection\': \'keep-alive\', \'x-ratelimit-limit\': \'5000\', \'etag\': \'"c23ad6b5815fc3d6ec6341c4a47afe85"\', \'cache-control\': \'private, max-age=60, s-maxage=60\', \'date\': \'Tue, 25 Sep 2012 20:36:54 GMT\', \'x-oauth-scopes\': \'\', \'content-type\': \'application/json; charset=utf-8\', \'x-accepted-oauth-scopes\': \'user\'} {"type":"User","bio":"","html_url":"https://github.com/jacquev6","login":"jacquev6","followers":14,"company":"Criteo","blog":"http://vincent-jacques.net","public_repos":13,"created_at":"2010-07-09T06:10:06Z","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png","email":"vincent@vincent-jacques.net","following":29,"name":"Vincent Jacques","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","hireable":false,"id":327146,"public_gists":3,"location":"Paris, France","url":"https://api.github.com/users/jacquev6"}') def testLoggingWithoutAuthentication(self): self.assertEqual(github.Github().get_user("jacquev6").name, "Vincent Jacques") - if atMostPython32: + if python2: self.assertEqual(self.__handler.handled, 'GET https://api.github.com/users/jacquev6 {\'User-Agent\': \'PyGithub/Python\'} null ==> 200 {\'status\': \'200 OK\', \'content-length\': \'628\', \'x-github-media-type\': \'github.beta; format=json\', \'x-content-type-options\': \'nosniff\', \'vary\': \'Accept\', \'x-ratelimit-remaining\': \'4989\', \'server\': \'nginx\', \'last-modified\': \'Tue, 25 Sep 2012 07:42:42 GMT\', \'connection\': \'keep-alive\', \'x-ratelimit-limit\': \'5000\', \'etag\': \'"9bd085221a16b6d2ea95e72634c3c1ac"\', \'cache-control\': \'public, max-age=60, s-maxage=60\', \'date\': \'Tue, 25 Sep 2012 20:38:56 GMT\', \'content-type\': \'application/json; charset=utf-8\'} {"type":"User","html_url":"https://github.com/jacquev6","login":"jacquev6","followers":14,"company":"Criteo","created_at":"2010-07-09T06:10:06Z","email":"vincent@vincent-jacques.net","hireable":false,"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png","public_gists":3,"bio":"","following":29,"name":"Vincent Jacques","blog":"http://vincent-jacques.net","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","id":327146,"public_repos":13,"location":"Paris, France","url":"https://api.github.com/users/jacquev6"}') def testLoggingWithBaseUrl(self): # ReplayData forged, not recorded self.assertEqual(github.Github(base_url="http://my.enterprise.com/my/prefix").get_user("jacquev6").name, "Vincent Jacques") - if atMostPython32: + if python2: self.assertEqual(self.__handler.handled, 'GET http://my.enterprise.com/my/prefix/users/jacquev6 {\'User-Agent\': \'PyGithub/Python\'} null ==> 200 {\'status\': \'200 OK\', \'content-length\': \'628\', \'x-github-media-type\': \'github.beta; format=json\', \'x-content-type-options\': \'nosniff\', \'vary\': \'Accept\', \'x-ratelimit-remaining\': \'4989\', \'server\': \'nginx\', \'last-modified\': \'Tue, 25 Sep 2012 07:42:42 GMT\', \'connection\': \'keep-alive\', \'x-ratelimit-limit\': \'5000\', \'etag\': \'"9bd085221a16b6d2ea95e72634c3c1ac"\', \'cache-control\': \'public, max-age=60, s-maxage=60\', \'date\': \'Tue, 25 Sep 2012 20:38:56 GMT\', \'content-type\': \'application/json; charset=utf-8\'} {"type":"User","html_url":"https://github.com/jacquev6","login":"jacquev6","followers":14,"company":"Criteo","created_at":"2010-07-09T06:10:06Z","email":"vincent@vincent-jacques.net","hireable":false,"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png","public_gists":3,"bio":"","following":29,"name":"Vincent Jacques","blog":"http://vincent-jacques.net","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","id":327146,"public_repos":13,"location":"Paris, France","url":"https://api.github.com/users/jacquev6"}') diff --git a/github/tests/Persistence.py b/github/tests/Persistence.py index 94f4b5a7..06c52e4c 100644 --- a/github/tests/Persistence.py +++ b/github/tests/Persistence.py @@ -25,10 +25,7 @@ import Framework import github -if Framework.atLeastPython26: - from io import BytesIO as IO -else: - from StringIO import StringIO as IO +from io import BytesIO as IO class Persistence(Framework.TestCase): diff --git a/python25-requirements.txt b/python25-requirements.txt deleted file mode 100644 index 322630ee..00000000 --- a/python25-requirements.txt +++ /dev/null @@ -1 +0,0 @@ -simplejson diff --git a/setup.py b/setup.py index 7dba8e74..73efd21b 100755 --- a/setup.py +++ b/setup.py @@ -82,12 +82,8 @@ if __name__ == "__main__": "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", - "Programming Language :: Python :: 2.5", - "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.2", - "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", @@ -95,6 +91,7 @@ if __name__ == "__main__": ], test_suite="github.tests.AllTests", use_2to3=True, + python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", install_requires=[ "pyjwt" ],