From 19827c41ececde66d2900c23c88eace685dc838b Mon Sep 17 00:00:00 2001 From: Thomas Hisch Date: Wed, 6 Feb 2019 22:23:43 +0100 Subject: [PATCH] PYTHON-1467 Remove outdated code for old python versions (#395) --- bson/_cbsonmodule.h | 9 --------- setup.py | 29 ++++++++++++++--------------- test/test_uri_parser.py | 21 ++++++--------------- 3 files changed, 20 insertions(+), 39 deletions(-) diff --git a/bson/_cbsonmodule.h b/bson/_cbsonmodule.h index d3a43c389..f483a8b3c 100644 --- a/bson/_cbsonmodule.h +++ b/bson/_cbsonmodule.h @@ -19,15 +19,6 @@ #ifndef _CBSONMODULE_H #define _CBSONMODULE_H -/* Py_ssize_t was new in python 2.5. See conversion - * guidlines in http://www.python.org/dev/peps/pep-0353 - * */ -#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN) -typedef int Py_ssize_t; -#define PY_SSIZE_T_MAX INT_MAX -#define PY_SSIZE_T_MIN INT_MIN -#endif - #if defined(WIN32) || defined(_MSC_VER) /* * This macro is basically an implementation of asprintf for win32 diff --git a/setup.py b/setup.py index f3c51f711..455313b8a 100755 --- a/setup.py +++ b/setup.py @@ -4,6 +4,11 @@ import re import sys import warnings + +if sys.version_info[:2] < (2, 7): + raise RuntimeError("Python version >= 2.7 required.") + + # Hack to silence atexit traceback in some Python versions try: import multiprocessing @@ -289,23 +294,17 @@ http://api.mongodb.org/python/current/installation.html#osx def build_extension(self, ext): name = ext.name - if sys.version_info[:3] >= (2, 7, 0): - try: - build_ext.build_extension(self, ext) - except build_errors: - e = sys.exc_info()[1] - sys.stdout.write('%s\n' % str(e)) - warnings.warn(self.warning_message % ("The %s extension " - "module" % (name,), - "The output above " - "this warning shows how " - "the compilation " - "failed.")) - else: + try: + build_ext.build_extension(self, ext) + except build_errors: + e = sys.exc_info()[1] + sys.stdout.write('%s\n' % str(e)) warnings.warn(self.warning_message % ("The %s extension " "module" % (name,), - "PyMongo supports python " - ">= 2.7.")) + "The output above " + "this warning shows how " + "the compilation " + "failed.")) ext_modules = [Extension('bson._cbson', include_dirs=['bson'], diff --git a/test/test_uri_parser.py b/test/test_uri_parser.py index 4211ba439..e8a538232 100644 --- a/test/test_uri_parser.py +++ b/test/test_uri_parser.py @@ -113,16 +113,10 @@ class TestURI(unittest.TestCase): 'connect=foo', warn=True) self.assertRaises(Warning, split_options, 'ssl_match_hostname=foo', warn=True) - - # On most platforms float('inf') and float('-inf') represent - # +/- infinity, although on Python 2.4 and 2.5 on Windows those - # expressions are invalid - if not (sys.platform == "win32" and sys.version_info <= (2, 5)): - self.assertRaises(Warning, split_options, - 'connectTimeoutMS=inf', warn=True) - self.assertRaises(Warning, split_options, - 'connectTimeoutMS=-inf', warn=True) - + self.assertRaises(Warning, split_options, + 'connectTimeoutMS=inf', warn=True) + self.assertRaises(Warning, split_options, + 'connectTimeoutMS=-inf', warn=True) self.assertRaises(Warning, split_options, 'wtimeoutms=foo', warn=True) self.assertRaises(Warning, split_options, 'wtimeoutms=5.5', @@ -148,11 +142,8 @@ class TestURI(unittest.TestCase): self.assertRaises(ValueError, split_options, 'ssl=foo') self.assertRaises(ValueError, split_options, 'connect=foo') self.assertRaises(ValueError, split_options, 'ssl_match_hostname=foo') - if not (sys.platform == "win32" and sys.version_info <= (2, 5)): - self.assertRaises(ValueError, split_options, - 'connectTimeoutMS=inf') - self.assertRaises(ValueError, split_options, - 'connectTimeoutMS=-inf') + self.assertRaises(ValueError, split_options, 'connectTimeoutMS=inf') + self.assertRaises(ValueError, split_options, 'connectTimeoutMS=-inf') self.assertRaises(ValueError, split_options, 'wtimeoutms=foo') self.assertRaises(ValueError, split_options, 'wtimeoutms=5.5') self.assertRaises(ValueError, split_options, 'fsync=foo')