From 992f5650bdb8d0533d9a27cace647a399e37bdcb Mon Sep 17 00:00:00 2001 From: Sasha Hart Date: Tue, 29 Jul 2014 13:51:23 -0500 Subject: [PATCH] completely forget about mechanize --- README.md | 1 - setup.py | 1 - test/test_mechanize_intercept.py | 102 -------------------------- wsgi_intercept/__init__.py | 5 +- wsgi_intercept/mechanize_intercept.py | 33 --------- 5 files changed, 2 insertions(+), 140 deletions(-) delete mode 100644 test/test_mechanize_intercept.py delete mode 100644 wsgi_intercept/mechanize_intercept.py diff --git a/README.md b/README.md index 1bc0125..d088a9e 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,6 @@ with a working implementation in Python 2 for: * `httplib` * `httplib2` * `requests` -* `mechanize` and in Python 3 for: diff --git a/setup.py b/setup.py index 941017f..adf59a2 100644 --- a/setup.py +++ b/setup.py @@ -35,7 +35,6 @@ META = { 'pytest>=2.4', 'httplib2', 'requests>=2.0.1', - 'mechanize>=0.2.5', ], }, } diff --git a/test/test_mechanize_intercept.py b/test/test_mechanize_intercept.py deleted file mode 100644 index b2707d9..0000000 --- a/test/test_mechanize_intercept.py +++ /dev/null @@ -1,102 +0,0 @@ -import sys -import platform -import py.test -from wsgi_intercept import WSGIAppError -from test import wsgi_app -from test.install import installer_class -try: - import urllib.request as url_lib -except ImportError: - import urllib2 as url_lib - - -# Without this conditional, the import of mechanize_intercept attempts -# to import mechanize, which cannot be installed on Python3 and throws -# exceptions on PyPy, resulting in a spurious error during test -# collection. -CAN_RUN_TESTS = ( - sys.version_info < (3, 0) and platform.python_implementation() != 'PyPy' -) -if CAN_RUN_TESTS: - from wsgi_intercept import mechanize_intercept - import mechanize - InstalledApp = installer_class(mechanize_intercept) -else: - InstalledApp = None - - -HOST = 'some_hopefully_nonexistent_domain' - -ONLY_PYTHON2_NOT_PYPY = py.test.mark.skipif( - not CAN_RUN_TESTS, - reason="mechanize is not ported from Python 2 and fails in PyPy") - - -@ONLY_PYTHON2_NOT_PYPY -def test_http(): - with InstalledApp(wsgi_app.simple_app, host=HOST, port=80) as app: - browser = mechanize.Browser() - url = 'http://some_hopefully_nonexistent_domain:80' - response = browser.open(url) - content = response.read() - assert content == b'WSGI intercept successful!\n' - assert app.success() - - -@ONLY_PYTHON2_NOT_PYPY -def test_http_default_port(): - with InstalledApp(wsgi_app.simple_app, host=HOST, port=80) as app: - browser = mechanize.Browser() - url = 'http://some_hopefully_nonexistent_domain' - response = browser.open(url) - content = response.read() - assert content == b'WSGI intercept successful!\n' - assert app.success() - - -@ONLY_PYTHON2_NOT_PYPY -def test_http_other_port(): - with InstalledApp(wsgi_app.simple_app, host=HOST, port=8080) as app: - browser = mechanize.Browser() - url = 'http://some_hopefully_nonexistent_domain:8080' - response = browser.open(url) - content = response.read() - assert content == b'WSGI intercept successful!\n' - assert app.success() - - -@ONLY_PYTHON2_NOT_PYPY -def test_bogus_domain(): - with InstalledApp(wsgi_app.simple_app, host=HOST, port=80): - browser = mechanize.Browser() - with py.test.raises(url_lib.URLError): - browser.open('https://_nonexistent_domain') - - -@ONLY_PYTHON2_NOT_PYPY -def test_https(): - with InstalledApp(wsgi_app.simple_app, host=HOST, port=443) as app: - browser = mechanize.Browser() - response = browser.open('https://some_hopefully_nonexistent_domain') - content = response.read() - assert content == b'WSGI intercept successful!\n' - assert app.success() - - -@ONLY_PYTHON2_NOT_PYPY -def test_https_default_port(): - with InstalledApp(wsgi_app.simple_app, host=HOST, port=443) as app: - browser = mechanize.Browser() - response = browser.open('https://some_hopefully_nonexistent_domain:443') - content = response.read() - assert content == b'WSGI intercept successful!\n' - assert app.success() - - -@ONLY_PYTHON2_NOT_PYPY -def test_app_error(): - with InstalledApp(wsgi_app.raises_app, host=HOST, port=80): - with py.test.raises(WSGIAppError): - browser = mechanize.Browser() - response = browser.open('http://some_hopefully_nonexistent_domain') - response.read() diff --git a/wsgi_intercept/__init__.py b/wsgi_intercept/__init__.py index 63359e8..6d3fdfe 100644 --- a/wsgi_intercept/__init__.py +++ b/wsgi_intercept/__init__.py @@ -40,9 +40,8 @@ Packages Intercepted Unfortunately each of the Web testing frameworks uses its own specific mechanism for making HTTP call-outs, so individual implementations are needed. At this time there are implementations for ``httplib2`` and -``requests`` in both Python 2 and 3, ``urllib2``, ``httplib`` and -``mechanize`` in Python 2 and ``urllib.request`` and ``http.client`` in -Python 3. +``requests`` in both Python 2 and 3, ``urllib2`` and ``httplib`` +in Python 2 and ``urllib.request`` and ``http.client`` in Python 3. If you are using Python 2 and need support for a different HTTP client, require a version of ``wsgi_intercept<0.6``. Earlier versions diff --git a/wsgi_intercept/mechanize_intercept.py b/wsgi_intercept/mechanize_intercept.py deleted file mode 100644 index b2e1e63..0000000 --- a/wsgi_intercept/mechanize_intercept.py +++ /dev/null @@ -1,33 +0,0 @@ -"""Intercept HTTP connections that use `mechanize `_. -""" -import sys -import platform -assert sys.version_info < (3, 0), "mechanize cannot be installed in Python 3" -assert platform.python_implementation() != "PyPy", ( - "mechanize does not import on PyPy" -) -import mechanize -from wsgi_intercept.urllib_intercept import WSGI_HTTPHandler, WSGI_HTTPSHandler - - -_ORIGINAL_BROWSER = mechanize.Browser - - -class Browser(_ORIGINAL_BROWSER): - """mechanize Browser class with our WSGI intercept handlers installed. - """ - handler_classes = _ORIGINAL_BROWSER.handler_classes.copy() - handler_classes['http'] = WSGI_HTTPHandler - handler_classes['https'] = WSGI_HTTPSHandler - - def __init__(self, *args, **kwargs): - _ORIGINAL_BROWSER.__init__(self, *args, **kwargs) - - -def install(): - mechanize.Browser = Browser - - -def uninstall(): - if mechanize.Browser == Browser: - mechanize.Browser = _ORIGINAL_BROWSER