From 881bd08af4a80bfcb864b463611b16cbfcdf39d9 Mon Sep 17 00:00:00 2001 From: secynic Date: Mon, 28 Jan 2019 20:26:00 -0600 Subject: [PATCH 1/2] Removed support for Python 2.6/3.3, added support for 3.7 (#221) --- .travis.yml | 8 ++----- CHANGES.rst | 1 + CONTRIBUTING.rst | 2 +- README.rst | 12 +++------- ipwhois/asn.py | 8 ++----- ipwhois/examples/elastic_search/README.rst | 9 +------ .../elastic_search/requirements26.txt | 4 ---- ipwhois/examples/redis_cache/README.rst | 8 +------ ipwhois/net.py | 18 -------------- ipwhois/scripts/ipwhois_cli.py | 6 ++--- ipwhois/tests/__init__.py | 24 ------------------- setup.py | 3 +-- 12 files changed, 14 insertions(+), 89 deletions(-) delete mode 100644 ipwhois/examples/elastic_search/requirements26.txt diff --git a/.travis.yml b/.travis.yml index 74836f2..eca6d79 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,19 +1,15 @@ language: python python: - - 2.6 - 2.7 - - 3.3 - 3.4 - 3.5 - 3.6 + - 3.7 install: - pip install --upgrade setuptools - pip install --upgrade pip - if [[ $TRAVIS_PYTHON_VERSION == 2* ]]; then pip install -r requirements/python2.txt; fi - - if [[ $TRAVIS_PYTHON_VERSION == 3.3* ]]; then pip install -r requirements/python3.txt; fi - - if [[ $TRAVIS_PYTHON_VERSION == 3.4* ]]; then pip install -r requirements/python3.txt; fi - - if [[ $TRAVIS_PYTHON_VERSION == 3.5* ]]; then pip install -r requirements/python3.txt; fi - - if [[ $TRAVIS_PYTHON_VERSION == 3.6* ]]; then pip install -r requirements/python3.txt; fi + - if [[ $TRAVIS_PYTHON_VERSION == 3* ]]; then pip install -r requirements/python3.txt; fi - pip install coveralls - pip install codeclimate-test-reporter - pip install -e . diff --git a/CHANGES.rst b/CHANGES.rst index 8817837..94368ba 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -9,6 +9,7 @@ Changelog - Fixed list output for generate_examples.py (#196) - Fixed bug in ASN HTTP lookup where the ARIN results were reversed, and parsing would fail on the first item (#220) +- Removed support for Python 2.6/3.3, added support for 3.7 (#221) 1.0.0 (2017-07-30) ------------------ diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index a4beceb..5808f7f 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -110,7 +110,7 @@ Guidelines - Follow the `Google docstring style guide `_ for comments -- Must be compatible with Python 2.6, 2.7, and 3.3+ +- Must be compatible with Python 2.7 and 3.4+ - Break out reusable code to functions - Make your code easy to read and comment where necessary - Reference the GitHub issue number in the description (e.g., Issue #01) diff --git a/README.rst b/README.rst index a11268e..879025c 100644 --- a/README.rst +++ b/README.rst @@ -11,7 +11,7 @@ ipwhois :target: https://codeclimate.com/github/secynic/ipwhois .. image:: https://img.shields.io/badge/license-BSD%202--Clause-blue.svg :target: https://github.com/secynic/ipwhois/tree/master/LICENSE.txt -.. image:: https://img.shields.io/badge/python-2.6%2C%202.7%2C%203.3+-blue.svg +.. image:: https://img.shields.io/badge/python-2.7%2C%203.4+-blue.svg :target: https://docs.python.org .. image:: https://img.shields.io/badge/docs-latest-green.svg?style=flat :target: https://ipwhois.readthedocs.io/en/latest @@ -45,7 +45,7 @@ Features * Recursive network parsing for IPs with parent/children networks listed * National Internet Registry support for JPNIC and KRNIC * Supports IP to ASN and ASN origin queries -* Python 2.6+ and 3.3+ supported +* Python 2.7 and 3.4+ supported * Useful set of utilities * Experimental bulk query support * BSD license @@ -97,18 +97,12 @@ https://ipwhois.readthedocs.io/en/latest/UPGRADING.html Dependencies ============ -Python 2.6:: - - dnspython - ipaddr - argparse (required only for CLI) - Python 2.7:: dnspython ipaddr -Python 3.3+:: +Python 3.4+:: dnspython diff --git a/ipwhois/asn.py b/ipwhois/asn.py index 6d39c73..68a6c40 100644 --- a/ipwhois/asn.py +++ b/ipwhois/asn.py @@ -480,9 +480,7 @@ def lookup(self, inc_raw=False, retry_count=3, asn_alts=None, else: - # Python 2.6 doesn't support set literal expressions, use explicit - # set() instead. - if set(['dns', 'whois', 'http']).isdisjoint(asn_methods): + if {'dns', 'whois', 'http'}.isdisjoint(asn_methods): raise ValueError('methods argument requires at least one of ' 'dns, whois, http.') @@ -844,9 +842,7 @@ def lookup(self, asn=None, inc_raw=False, retry_count=3, response=None, else: - # Python 2.6 doesn't support set literal expressions, use explicit - # set() instead. - if set(['whois', 'http']).isdisjoint(asn_methods): + if {'whois', 'http'}.isdisjoint(asn_methods): raise ValueError('methods argument requires at least one of ' 'whois, http.') diff --git a/ipwhois/examples/elastic_search/README.rst b/ipwhois/examples/elastic_search/README.rst index 3fc34d4..62de92a 100644 --- a/ipwhois/examples/elastic_search/README.rst +++ b/ipwhois/examples/elastic_search/README.rst @@ -22,14 +22,7 @@ Tested using:: ElasticSearch 5.5.1 Kibana 5.5.1 -Python 2.6 (requirements26.txt - geopy is not supported):: - - ipwhois - elasticsearch - geoip2 - argparse - -Python 2.7, 3.3+ (requirements.txt):: +Python 2.7, 3.4+ (requirements.txt):: ipwhois elasticsearch diff --git a/ipwhois/examples/elastic_search/requirements26.txt b/ipwhois/examples/elastic_search/requirements26.txt deleted file mode 100644 index 8c9f0ba..0000000 --- a/ipwhois/examples/elastic_search/requirements26.txt +++ /dev/null @@ -1,4 +0,0 @@ -ipwhois -elasticsearch -geoip2 -argparse diff --git a/ipwhois/examples/redis_cache/README.rst b/ipwhois/examples/redis_cache/README.rst index 1b1457e..4f81770 100644 --- a/ipwhois/examples/redis_cache/README.rst +++ b/ipwhois/examples/redis_cache/README.rst @@ -15,13 +15,7 @@ Tested using:: Redis 3.2.1 -Python 2.6 (requirements26.txt):: - - ipwhois - redis - argparse - -Python 2.7, 3.3+ (requirements.txt):: +Python 2.7, 3.4+ (requirements.txt):: ipwhois redis diff --git a/ipwhois/net.py b/ipwhois/net.py index 65b2881..a80ece0 100644 --- a/ipwhois/net.py +++ b/ipwhois/net.py @@ -768,15 +768,6 @@ def get_http_json(self, url=None, retry_count=3, rate_limit_timeout=120, except (URLError, socket.timeout, socket.error) as e: - # Check needed for Python 2.6, also why URLError is caught. - try: # pragma: no cover - if not isinstance(e.reason, (socket.timeout, socket.error)): - raise HTTPLookupError('HTTP lookup failed for {0}.' - ''.format(url)) - except AttributeError: # pragma: no cover - - pass - log.debug('HTTP query socket error: {0}'.format(e)) if retry_count > 0: @@ -920,15 +911,6 @@ def get_http_raw(self, url=None, retry_count=3, headers=None, except (URLError, socket.timeout, socket.error) as e: - # Check needed for Python 2.6, also why URLError is caught. - try: # pragma: no cover - if not isinstance(e.reason, (socket.timeout, socket.error)): - raise HTTPLookupError('HTTP lookup failed for {0}.' - ''.format(url)) - except AttributeError: # pragma: no cover - - pass - log.debug('HTTP query socket error: {0}'.format(e)) if retry_count > 0: diff --git a/ipwhois/scripts/ipwhois_cli.py b/ipwhois/scripts/ipwhois_cli.py index faf9a5b..56daa6a 100644 --- a/ipwhois/scripts/ipwhois_cli.py +++ b/ipwhois/scripts/ipwhois_cli.py @@ -482,10 +482,8 @@ def generate_output_asn(self, json_data=None, hr=True, show_name=False, if json_data is None: json_data = {} - # Python 2.6 doesn't support set literal expressions, use explicit - # set() instead. - keys = set(['asn', 'asn_cidr', 'asn_country_code', 'asn_date', - 'asn_registry', 'asn_description']).intersection(json_data) + keys = {'asn', 'asn_cidr', 'asn_country_code', 'asn_date', + 'asn_registry', 'asn_description'}.intersection(json_data) output = '' diff --git a/ipwhois/tests/__init__.py b/ipwhois/tests/__init__.py index 82e2ce6..fdfca02 100644 --- a/ipwhois/tests/__init__.py +++ b/ipwhois/tests/__init__.py @@ -4,30 +4,6 @@ class TestCommon(unittest.TestCase): longMessage = False - # Python 2.6 doesn't have unittest._formatMessage or - # unittest.util.safe_repr - # Borrowed and modified both functions from Python 2.7. - if not hasattr(unittest.TestCase, '_formatMessage'): - def safe_repr(self, obj, short=False): - try: - result = repr(obj) - except Exception: - result = object.__repr__(obj) - if not short or len(result) < 80: - return result - return result[:80] + ' [truncated]...' - - def _formatMessage(self, msg, standardMsg): - if not self.longMessage: - return msg or standardMsg - if msg is None: - return standardMsg - try: - return '{0} : {0}'.format(standardMsg, msg) - except UnicodeDecodeError: - return '{0} : {0}'.format(self.safe_repr(standardMsg), - self.safe_repr(msg)) - if not hasattr(unittest.TestCase, 'assertIsInstance'): def assertIsInstance(self, obj, cls, msg=None): if not isinstance(obj, cls): diff --git a/setup.py b/setup.py index 4e61331..090e821 100644 --- a/setup.py +++ b/setup.py @@ -52,13 +52,12 @@ 'Operating System :: OS Independent', 'Programming Language :: Python', 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', 'Topic :: Internet', 'Topic :: Software Development', ] From 48058c604461fc01ca193a06330392562e080a51 Mon Sep 17 00:00:00 2001 From: secynic Date: Mon, 28 Jan 2019 20:41:04 -0600 Subject: [PATCH 2/2] Python 3.7 Travis workaround (#221) --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index eca6d79..a363b5e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,6 @@ language: python +sudo: required +dist: xenial python: - 2.7 - 3.4