Skip to content

Commit

Permalink
Merge pull request #2 from zopefoundation/python3
Browse files Browse the repository at this point in the history
Python3
  • Loading branch information
janwijbrand committed Jan 31, 2018
2 parents ec30179 + 9baf356 commit f67e6fd
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 59 deletions.
20 changes: 12 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
bin/
eggs/
develop-eggs/
parts/
.installed.cfg
*.egg-info/
*.py[co]
.coverage
.installed.cfg
.tox/
__pycache__/
bin/
build/
develop-eggs/
dist/
*.egg-info/
.tox/
.coverage
eggs/
htmlcov/
lib/
parts/
pip-selfcheck.json
pyvenv.cfg
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ language: python
sudo: false
python:
- 2.7
- 3.6
install:
- python bootstrap.py
- bin/buildout
- pip install -U -r requirements.txt
- buildout -v
script:
- bin/test -v1
notifications:
Expand Down
18 changes: 18 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Changes
=======

3.0 (unreleased)
----------------

- Python 3 compatibility

2.0 (2007-08-23)
----------------

- Added the ``PostMortemDebug`` (pdb) middelware.

1.0 (2007-06-02)
----------------

- Initial release, featuring the Zope 3-compatible interactive AJAX
debugger from Paste.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include *.py
include *.txt
include *.rst
include buildout.cfg
include test.ini
include .coveragerc
Expand Down
14 changes: 0 additions & 14 deletions README.txt → README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,3 @@ a PasteDeploy-style configuration file using the ``pdb`` entry-point::
use = egg:Paste#http
host = 127.0.0.1
port = 8080

Changes
=======

2.0 (2007-08-23)
----------------

Added the ``PostMortemDebug`` (pdb) middelware.

1.0 (2007-06-02)
----------------

Initial release, featuring the Zope 3-compatible interactive AJAX
debugger from Paste.
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# NOTE: setuptools and zc.buildout versions must be in sync with:
# ztk-versions.cfg
setuptools==38.2.4
zc.buildout==2.10.0
40 changes: 27 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,38 @@
import os.path
from setuptools import setup, find_packages


def read(*rnames):
with open(os.path.join(os.path.dirname(__file__), *rnames)) as f:
return f.read()


setup(name='z3c.evalexception',
version = '2.0',
version='3.0.dev0',
license='ZPL 2.1',
description="Debugging middlewares for zope.publisher-based web "
"applications",
author='Philipp von Weitershausen',
author_email='philipp@weitershausen.de',
long_description=open('README.txt').read(),
classifiers = ['Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: Zope Public License',
'Programming Language :: Python',
'Operating System :: OS Independent',
'Topic :: Internet :: WWW/HTTP',
'Framework :: Zope3',
'Framework :: Paste',
],

long_description=(
read('README.rst')
+ '\n\n' +
read('CHANGES.rst')
),
classifiers=['Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: Zope Public License',
'Programming Language :: Python',
'Operating System :: OS Independent',
'Topic :: Internet :: WWW/HTTP',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Framework :: Zope3',
'Framework :: Paste'],
packages=find_packages(),
namespace_packages=['z3c'],
install_requires=['setuptools', 'Paste', 'zope.security'],
Expand Down
40 changes: 30 additions & 10 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
[tox]
envlist =
py27
coverage-clean,
py27,
py36,
coverage-report

# NB tox breaks on:
# https://github.com/pypa/pip/issues/4216
# but buildout-provided py36 test runs fine

[testenv]
deps =
zope.testrunner
.[test]
commands =
zope-testrunner --test-path=. {posargs:-pvc}

[testenv:coverage]
coverage run --source=z3c.evalexception -m zope.testrunner --test-path=. {posargs:-vc}
setenv =
COVERAGE_FILE=.coverage.{envname}
deps =
{[testenv]deps}
.[test]
zope.testrunner
coverage

[testenv:coverage-clean]
deps = coverage
setenv =
COVERAGE_FILE=.coverage
skip_install = true
commands = coverage erase

[testenv:coverage-report]
deps = coverage
setenv =
COVERAGE_FILE=.coverage
skip_install = true
commands =
coverage run -m zope.testrunner --test-path=. {posargs:-pvc}
coverage report -m
coverage combine
coverage report
coverage html
coverage
20 changes: 14 additions & 6 deletions z3c/evalexception/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import zope.security.management
from paste.evalexception.middleware import EvalException


class ZopeEvalException(EvalException):
"""Wrapper around Paste's EvalException middleware that simply
tells zope.publisher to let exceptions propagate to the middleware."""
Expand All @@ -9,9 +10,11 @@ def __call__(self, environ, start_response):
environ['wsgi.handleErrors'] = False
return super(ZopeEvalException, self).__call__(environ, start_response)


def zope_eval_exception(app, global_conf):
return ZopeEvalException(app)


def PostMortemDebug(application):
"""Middleware that catches exceptions coming from a
zope.publisher-based application and invokes pdb's post-mortem
Expand All @@ -21,10 +24,11 @@ def middleware(environ, start_response):
try:
for chunk in application(environ, start_response):
yield chunk
except:
import sys, pdb
print "%s:" % sys.exc_info()[0]
print sys.exc_info()[1]
except Exception:
import sys
import pdb
print("%s:" % sys.exc_info()[0])
print(sys.exc_info()[1])
zope.security.management.restoreInteraction()
try:
pdb.post_mortem(sys.exc_info()[2])
Expand All @@ -33,15 +37,19 @@ def middleware(environ, start_response):
zope.security.management.endInteraction()
return middleware


def post_mortem_debug(app, global_conf):
return PostMortemDebug(app)


def TestApplication(environ, start_response):
"""A simple WSGI app that raises an exception for testing
purposes. Nothing to see here."""
raise RuntimeError('The test application is raising this.')
start_response('200 OK', [('Content-type', 'text/plain')]) # pragma: nocover
yield "Test Application" # pragma: nocover
start_response('200 OK', # pragma: nocover
[('Content-type', 'text/plain')]) # pragma: nocover
yield "Test Application" # pragma: nocover


def test_application_factory(global_config):
return TestApplication
13 changes: 7 additions & 6 deletions z3c/evalexception/tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from cStringIO import StringIO
from io import BytesIO
import unittest

import mock
Expand Down Expand Up @@ -26,8 +26,8 @@ def setUp(self):
'HTTP_HOST': 'localhost:8080',
'wsgi.version': (1, 0),
'wsgi.url_scheme': 'http',
'wsgi.input': StringIO(),
'wsgi.errors': StringIO(),
'wsgi.input': BytesIO(),
'wsgi.errors': BytesIO(),
'wsgi.multithread': False,
'wsgi.multiprocess': False,
'wsgi.run_once': False,
Expand All @@ -38,7 +38,7 @@ def request(self, **kwargs):
environ.update(kwargs)
start_response = mock.Mock()
body_iter = self.middleware(environ, start_response)
return ''.join(body_iter)
return b''.join(body_iter)


class TestZopeEvalException(WsgiMiddlewareTestCase):
Expand All @@ -47,8 +47,9 @@ class TestZopeEvalException(WsgiMiddlewareTestCase):

def test(self):
body = self.request()
self.assertIn('<title>Server Error</title>', body)
self.assertIn('RuntimeError: The test application is raising this.', body)
self.assertIn(b'<title>Server Error</title>', body)
self.assertIn(b'RuntimeError: The test application is raising this.',
body)


class TestPostMortemDebug(WsgiMiddlewareTestCase):
Expand Down

0 comments on commit f67e6fd

Please sign in to comment.