removed python2 compatibility code

This commit is contained in:
Akash Mahanty 2020-11-21 17:00:11 +05:30
parent 9f847a5e55
commit 5088305a58
6 changed files with 66 additions and 93 deletions

View File

@ -3,7 +3,6 @@ os: linux
dist: xenial
cache: pip
python:
- 3.6
- 3.8
before_install:
- python --version
@ -15,4 +14,4 @@ script:
- cd tests
- pytest --cov=../waybackpy
after_success:
- if [[ $TRAVIS_PYTHON_VERSION == 3.8 ]]; then python -m codecov; fi
- python -m codecov

View File

@ -22,7 +22,7 @@ setup(
download_url = 'https://github.com/akamhy/waybackpy/archive/2.2.0.tar.gz',
keywords = ['waybackpy', 'archive', 'archive website', 'wayback machine', 'Internet Archive'],
install_requires=[],
python_requires= ">=3.2",
python_requires= ">=3.4",
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
@ -31,13 +31,12 @@ setup(
'License :: OSI Approved :: MIT License',
'Programming Language :: Python',
'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',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: Implementation :: CPython',
],
entry_points={

View File

@ -9,14 +9,10 @@ import waybackpy.cli as cli # noqa: E402
from waybackpy.wrapper import Url # noqa: E402
from waybackpy.__version__ import __version__
codecov_python = False
if sys.version_info > (3, 7):
codecov_python = True
# Namespace(day=None, get=None, hour=None, minute=None, month=None, near=False,
# newest=False, oldest=False, save=False, total=False, url=None, user_agent=None, version=False, year=None)
if codecov_python:
def test_save():
args = argparse.Namespace(user_agent=None, url="https://pypi.org/user/akamhy/", total=False, version=False,
oldest=False, save=True, json=False, archive_url=False, newest=False, near=False, alive=False, subdomain=False, known_urls=False, get=None)
@ -88,7 +84,6 @@ def test_get():
reply = cli.args_handler(args)
assert "waybackpy" in str(reply)
if codecov_python:
args = argparse.Namespace(user_agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/600.8.9 \
(KHTML, like Gecko) Version/8.0.8 Safari/600.8.9", url="https://pypi.org/user/akamhy/", total=False, version=False,
oldest=False, save=False, json=False, archive_url=False, newest=False, near=False, alive=False, subdomain=False, known_urls=False, get="save")

View File

@ -7,11 +7,10 @@ import random
sys.path.append("..")
import waybackpy.wrapper as waybackpy # noqa: E402
if sys.version_info >= (3, 0): # If the python ver >= 3
from urllib.request import Request, urlopen
from urllib.error import URLError
else: # For python2.x
from urllib2 import Request, urlopen, URLError
user_agent = "Mozilla/5.0 (Windows NT 6.2; rv:20.0) Gecko/20121202 Firefox/20.0"
@ -65,23 +64,14 @@ def test_save():
archived_url1 = str(target.save())
assert url1 in archived_url1
if sys.version_info > (3, 6):
# Test for urls that are incorrect.
with pytest.raises(Exception):
url2 = "ha ha ha ha"
waybackpy.Url(url2, user_agent)
url3 = "http://www.archive.is/faq.html"
# Test for urls not allowed to archive by robot.txt. Doesn't works anymore. Find alternatives.
# with pytest.raises(Exception):
#
# target = waybackpy.Url(
# url3,
# "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:25.0) "
# "Gecko/20100101 Firefox/25.0",
# )
# target.save()
# Non existent urls, test
with pytest.raises(Exception):
target = waybackpy.Url(
url3,
@ -91,9 +81,6 @@ def test_save():
)
target.save()
else:
pass
def test_near():
url = "google.com"
@ -105,7 +92,7 @@ def test_near():
archive_near_year = target.near(year=2010)
assert "2010" in str(archive_near_year)
if sys.version_info > (3, 6):
archive_near_month_year = str(target.near(year=2015, month=2))
assert (
("201502" in archive_near_month_year)
@ -133,8 +120,7 @@ def test_near():
)
target = waybackpy.Url(NeverArchivedUrl, user_agent)
target.near(year=2010)
else:
pass
def test_oldest():
@ -182,11 +168,10 @@ def test_get_response():
def test_total_archives():
if sys.version_info > (3, 6):
target = waybackpy.Url(" https://google.com ", user_agent)
assert target.total_archives() > 500000
else:
pass
target = waybackpy.Url(
" https://gaha.e4i3n.m5iai3kip6ied.cima/gahh2718gs/ahkst63t7gad8 ", user_agent
)

View File

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
import sys
import os
import re

View File

@ -1,17 +1,13 @@
# -*- coding: utf-8 -*-
import re
import sys
import json
from datetime import datetime, timedelta
from waybackpy.exceptions import WaybackError
from waybackpy.__version__ import __version__
if sys.version_info >= (3, 0): # If the python ver >= 3
from urllib.request import Request, urlopen
from urllib.error import URLError
else: # For python2.x
from urllib2 import Request, urlopen, URLError
default_UA = "waybackpy python package - https://github.com/akamhy/waybackpy"