From 5a3a3bec1967576c27de2b64092d9a685da05348 Mon Sep 17 00:00:00 2001 From: shivammathur Date: Fri, 19 May 2017 02:50:05 +0530 Subject: [PATCH] Add python 2 backward compatiblity --- .gitignore | 3 +++ .travis.yml | 8 ++++++-- README.md | 4 ++-- README.rst | 4 ++-- examples/example1.py | 8 +++++++- examples/example2.py | 8 +++++++- ippy/__init__.py | 2 +- ippy/ippy.py | 20 +++++++++++++++----- requirements.txt | 5 ++++- setup.cfg | 2 +- setup.py | 7 ++++--- tests/test_ippy.py | 10 +++++++++- tox.ini | 6 +++--- 13 files changed, 64 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index 8b649aa..574e611 100644 --- a/.gitignore +++ b/.gitignore @@ -62,3 +62,6 @@ target/ # pyenv python configuration file .python-version + +#pycharm +.idea* diff --git a/.travis.yml b/.travis.yml index 3b44385..f55c3ce 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,10 @@ language: python matrix: include: + - python: 2.6 + env: TOXENV=py26 + - python: 2.7 + env: TOXENV=py27 - python: 3.3 env: TOXENV=py33 - python: 3.4 @@ -14,14 +18,14 @@ matrix: env: TOXENV=py36 # command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors -install: +install: - pip install -U tox - pip install tox codecov coveralls - pip install -r requirements.txt - pip install pytest-cov # command to run tests, e.g. python setup.py test -script: +script: - py.test --cov=ippy tests/ - tox -e ${TOXENV} diff --git a/README.md b/README.md index 0198cb0..e31e29b 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,8 @@ Parallel testing of IP addresses and domains in python. Reads IP addresses and domains from a CSV file and gives two lists of accessible and inaccessible ones. ## About -- Written in Python 3 -- Testing of IPs and domains is done in parallel. +- Compatible with both Python 2 and 3. +- Testing of IPs and domains is done in parallel. - By default there are 4 Workers. - All Workers work on an input Queue and a output Queue. diff --git a/README.rst b/README.rst index 7b22e2c..d923b22 100644 --- a/README.rst +++ b/README.rst @@ -8,7 +8,7 @@ and inaccessible ones. About ----- -- Written in Python 3 +- Compatible with both Python 2 and 3. - Testing of IPs and domains is done in parallel. - By default there are 4 Workers. - All Workers work on an input Queue and a output Queue. @@ -75,4 +75,4 @@ then run tox from the project root directory. :: - $ tox \ No newline at end of file + $ tox diff --git a/examples/example1.py b/examples/example1.py index 73b4a33..4796dcd 100644 --- a/examples/example1.py +++ b/examples/example1.py @@ -1,6 +1,11 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python # -*- coding: utf-8 -*- +from __future__ import print_function +from __future__ import unicode_literals +from __future__ import division +from __future__ import absolute_import +from future.standard_library import install_aliases from ippy import ippy import sys @@ -14,4 +19,5 @@ def main(): print(output) if __name__ == "__main__": + install_aliases() sys.exit(main()) diff --git a/examples/example2.py b/examples/example2.py index 1b17703..9adcb8e 100644 --- a/examples/example2.py +++ b/examples/example2.py @@ -1,6 +1,11 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python # -*- coding: utf-8 -*- +from __future__ import print_function +from __future__ import unicode_literals +from __future__ import division +from __future__ import absolute_import +from future.standard_library import install_aliases from ippy import ippy import sys @@ -14,4 +19,5 @@ def main(): print(output) if __name__ == "__main__": + install_aliases() sys.exit(main()) diff --git a/ippy/__init__.py b/ippy/__init__.py index b1a5b94..ebb1aff 100644 --- a/ippy/__init__.py +++ b/ippy/__init__.py @@ -2,6 +2,6 @@ __author__ = """Shivam Mathur""" __email__ = 'shivam_jpr@hotmail.com' -__version__ = '0.2.3' +__version__ = '0.3.0' from .ippy import Ippy diff --git a/ippy/ippy.py b/ippy/ippy.py index ca45ce8..f30e4ae 100644 --- a/ippy/ippy.py +++ b/ippy/ippy.py @@ -1,23 +1,27 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python # -*- coding: utf-8 -*- """ Python script to check if IP address and domains are accessible or not. .. codeauthor:: Shivam Mathur """ - +from __future__ import print_function +from __future__ import unicode_literals +from __future__ import division +from __future__ import absolute_import +from future.standard_library import install_aliases from io import StringIO from json import dumps from csv import writer -from itertools import zip_longest +from future.moves.itertools import zip_longest import sys import os import platform import subprocess import threading -import queue import pingparsing +import queue class Ippy(object): @@ -185,10 +189,16 @@ def result(self): result = dumps(result_dict, indent=4) elif self.output == 'csv': result = StringIO() - writer(result) + ippy_writer = writer(result) + d = [self._accessible, self._not_accessible] + for x in zip_longest(*d): + ippy_writer.writerow(x) result = result.getvalue().strip('\r\n') result = 'Accessible,Not Accessible\n' + result else: raise ValueError("Unknown output mode") return result + +if __name__ == "__main__": + install_aliases() diff --git a/requirements.txt b/requirements.txt index a8be80e..d106485 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,4 @@ -pingparsing==0.6.0 \ No newline at end of file + +pingparsing>=0.6.0 + +future>=0.16.0 diff --git a/setup.cfg b/setup.cfg index 233ecd8..04b1531 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.2.3 +current_version = 0.3.0 commit = True tag = True diff --git a/setup.py b/setup.py index 440d0f9..bceed39 100644 --- a/setup.py +++ b/setup.py @@ -21,12 +21,12 @@ setup( name='ippy', - version='0.2.3', + version='0.3.0', description="Parallel testing of IP addresses and domains in python.", author="Shivam Mathur", author_email='shivam_jpr@hotmail.com', url='https://github.com/shivammathur/ippy', - download_url='https://github.com/shivammathur/ippy/archive/0.2.3.tar.gz', + download_url='https://github.com/shivammathur/ippy/archive/0.3.0.tar.gz', packages=[ 'ippy', ], @@ -42,7 +42,8 @@ "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Natural Language :: English", - "Programming Language :: Python :: 3", + "Programming Language :: Python :: 2.6", + "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", diff --git a/tests/test_ippy.py b/tests/test_ippy.py index 39b23da..03d69e9 100644 --- a/tests/test_ippy.py +++ b/tests/test_ippy.py @@ -7,14 +7,20 @@ Tests for `ippy` module. """ +from __future__ import unicode_literals +from __future__ import print_function +from __future__ import division +from __future__ import absolute_import -import pytest +from future.standard_library import install_aliases from ippy import ippy +import pytest import sys import os import json from io import StringIO from csv import reader +install_aliases() def test_config(): @@ -74,12 +80,14 @@ def test_empty_result(): ippt.run() pytest.raises(ValueError, "ippt.result()") + def test_json_result(): ippt = ippy.Ippy() ippt.set_config(False, 'json', 10) result = ippt.result() assert json.loads(result) is not None + def test_csv_result(): ippt = ippy.Ippy() ippt.set_config(False, 'csv', 10) diff --git a/tox.ini b/tox.ini index 7b5554b..915258a 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py33, py34, py35, py36 +envlist = py26, py27, py33, py34, py35, py36 [testenv] setenv = @@ -9,9 +9,9 @@ deps = -r{toxinidir}/requirements.txt codecov>=1.4.0 coveralls -passenv = CI TRAVIS TRAVIS_* +passenv = CI TRAVIS TRAVIS_* commands = pip install -U pip py.test --basetemp={envtmpdir} - codecov -e TOXENV + codecov -e TOXENV coveralls