Skip to content

Commit

Permalink
Merge pull request #223 from secynic/221/pysupport
Browse files Browse the repository at this point in the history
221/pysupport
  • Loading branch information
secynic committed Jan 29, 2019
2 parents d313cb0 + 48058c6 commit fc0dd40
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 89 deletions.
10 changes: 4 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
language: python
sudo: required
dist: xenial
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 .
Expand Down
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
------------------
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Guidelines
- Follow the `Google docstring style guide
<https://google.github.io/styleguide/pyguide.html#Comments>`_ 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)
Expand Down
12 changes: 3 additions & 9 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
8 changes: 2 additions & 6 deletions ipwhois/asn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand Down Expand Up @@ -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.')
Expand Down
9 changes: 1 addition & 8 deletions ipwhois/examples/elastic_search/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions ipwhois/examples/elastic_search/requirements26.txt

This file was deleted.

8 changes: 1 addition & 7 deletions ipwhois/examples/redis_cache/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 0 additions & 18 deletions ipwhois/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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:

Expand Down
6 changes: 2 additions & 4 deletions ipwhois/scripts/ipwhois_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''

Expand Down
24 changes: 0 additions & 24 deletions ipwhois/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]
Expand Down

0 comments on commit fc0dd40

Please sign in to comment.