Skip to content

Commit

Permalink
Merge b6b9920 into 6bd284b
Browse files Browse the repository at this point in the history
  • Loading branch information
mgedmin committed Apr 10, 2020
2 parents 6bd284b + b6b9920 commit d799cda
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 100 deletions.
33 changes: 19 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
language: python
python:
- 2.7
- 3.5
- 3.6
- 3.7
- 3.8
- pypy
- 2.7
- 3.5
- 3.6
- 3.7
- 3.8
- pypy
jobs:
include:
- name: flake8
install: pip install flake8
script: flake8 src setup.py
after_success:
env: CACHE_NAME=flake8
install:
- pip install -U pip setuptools
- pip install -U coverage coveralls
- pip install -U -e .[test,docs]
- pip install -U pip setuptools
- pip install -U coverage coveralls
- pip install -U -e .[test,docs]
script:
- coverage run -m zope.testrunner --test-path=src
- coverage run -a -m sphinx -b doctest -d docs/_build/doctrees docs docs/_build/doctest
- coverage run -m zope.testrunner --test-path=src
- coverage run -a -m sphinx -b doctest -d docs/_build/doctrees docs docs/_build/doctest
notifications:
email: false
email: false
cache: pip
before_cache:
- rm -f $HOME/.cache/pip/log/debug.log
after_success:
- coveralls
97 changes: 50 additions & 47 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
def read(*rnames):
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()


def alltests():
import os
import sys
Expand All @@ -40,55 +41,57 @@ def alltests():
suites = list(zope.testrunner.find.find_suites(options))
return unittest.TestSuite(suites)


tests_require = [
'zope.testrunner',
]

setup(name='zope.exceptions',
version='4.4.dev0',
author='Zope Foundation and Contributors',
author_email='zope-dev@zope.org',
description='Zope Exceptions',
long_description=(read('README.rst') + '\n\n' +
read('CHANGES.rst')),
keywords='zope exceptions',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: Zope Public License',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Natural Language :: English',
'Operating System :: OS Independent',
'Topic :: Internet :: WWW/HTTP',
'Framework :: Zope :: 3',
],
url='https://github.com/zopefoundation/zope.exceptions',
license='ZPL 2.1',
packages=find_packages('src'),
package_dir={'': 'src'},
namespace_packages=['zope'],
install_requires=[
'setuptools',
'zope.interface',
],
tests_require=[
'zope.testrunner',
],
test_suite='__main__.alltests',
include_package_data=True,
zip_safe=False,
extras_require={
'docs': ['Sphinx', 'repoze.sphinx.autointerface'],
'test': tests_require,
},
setup(
name='zope.exceptions',
version='4.4.dev0',
author='Zope Foundation and Contributors',
author_email='zope-dev@zope.org',
description='Zope Exceptions',
long_description=(read('README.rst') + '\n\n' +
read('CHANGES.rst')),
keywords='zope exceptions',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: Zope Public License',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Natural Language :: English',
'Operating System :: OS Independent',
'Topic :: Internet :: WWW/HTTP',
'Framework :: Zope :: 3',
],
url='https://github.com/zopefoundation/zope.exceptions',
license='ZPL 2.1',
packages=find_packages('src'),
package_dir={'': 'src'},
namespace_packages=['zope'],
install_requires=[
'setuptools',
'zope.interface',
],
tests_require=[
'zope.testrunner',
],
test_suite='__main__.alltests',
include_package_data=True,
zip_safe=False,
extras_require={
'docs': ['Sphinx', 'repoze.sphinx.autointerface'],
'test': tests_require,
},
)
2 changes: 1 addition & 1 deletion src/zope/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__import__('pkg_resources').declare_namespace(__name__) # pragma: no cover
__import__('pkg_resources').declare_namespace(__name__) # pragma: no cover
17 changes: 14 additions & 3 deletions src/zope/exceptions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
These exceptions are so general purpose that they don't belong in Zope
application-specific packages.
"""

from zope.exceptions.interfaces import DuplicationError
from zope.exceptions.interfaces import IDuplicationError
from zope.exceptions.interfaces import UserError
Expand All @@ -25,17 +26,27 @@
from zope.exceptions.exceptionformatter import print_exception
from zope.exceptions.exceptionformatter import extract_stack

__all__ = [
'DuplicationError', 'IDuplicationError', 'UserError', 'IUserError',
'format_exception', 'print_exception', 'extract_stack',
]


# avoid dependency on zope.security:
try:
import zope.security
except ImportError as v: #pragma: no cover
import zope.security # noqa: suppress unused import warning from flake8
except ImportError as v: # pragma: no cover
# "ImportError: No module named security"
if 'security' not in str(v):
raise
else: #pragma: no cover
else: # pragma: no cover
from zope.security.interfaces import IUnauthorized
from zope.security.interfaces import Unauthorized
from zope.security.interfaces import IForbidden
from zope.security.interfaces import IForbiddenAttribute
from zope.security.interfaces import Forbidden
from zope.security.interfaces import ForbiddenAttribute
__all__ += [
'IUnauthorized', 'Unauthorized', 'IForbidden', 'IForbiddenAttribute',
'Forbidden', 'ForbiddenAttribute',
]
23 changes: 12 additions & 11 deletions src/zope/exceptions/exceptionformatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def formatSupplement(self, supplement, tb):
extra = getInfo()
if extra:
result.append(self.formatSupplementInfo(extra))
except: #pragma: no cover
except Exception: # pragma: no cover
if DEBUG_EXCEPTION_FORMATTER:
traceback.print_exc()
# else just swallow the exception.
Expand Down Expand Up @@ -150,7 +150,7 @@ def formatLine(self, tb=None, f=None):
try:
supp = factory(*args)
result.extend(self.formatSupplement(supp, tb))
except: #pragma: no cover
except Exception: # pragma: no cover
if DEBUG_EXCEPTION_FORMATTER:
traceback.print_exc()
# else just swallow the exception.
Expand All @@ -159,7 +159,7 @@ def formatLine(self, tb=None, f=None):
tbi = f_locals.get('__traceback_info__', None)
if tbi is not None:
result.append(self.formatTracebackInfo(tbi))
except: #pragma: no cover
except Exception: # pragma: no cover
if DEBUG_EXCEPTION_FORMATTER:
traceback.print_exc()
# else just swallow the exception.
Expand All @@ -174,8 +174,9 @@ def formatLastLine(self, exc_line):
return self.escape(exc_line)

def formatException(self, etype, value, tb):
# The next line provides a way to detect recursion.
__exception_formatter__ = 1
# The next line provides a way to detect recursion. The 'noqa'
# comment disables a flake8 warning about the unused variable.
__exception_formatter__ = 1 # noqa
result = []
while tb is not None:
if tb.tb_frame.f_locals.get('__exception_formatter__'):
Expand Down Expand Up @@ -206,8 +207,9 @@ def extractStack(self, f=None):
except ZeroDivisionError:
f = sys.exc_info()[2].tb_frame.f_back

# The next line provides a way to detect recursion.
__exception_formatter__ = 1
# The next line provides a way to detect recursion. The 'noqa'
# comment disables a flake8 warning about the unused variable.
__exception_formatter__ = 1 # noqa
result = []
while f is not None:
if f.f_locals.get('__exception_formatter__'):
Expand Down Expand Up @@ -250,10 +252,9 @@ def escape(self, s):
s = str(s)
except UnicodeError:
if hasattr(s, 'encode'):
# We probably got a unicode string on
# Python 2.
# We probably got a unicode string on Python 2.
s = s.encode('utf-8')
else: # pragma: no cover
else: # pragma: no cover
raise
return escape(s, quote=False)

Expand Down Expand Up @@ -309,7 +310,7 @@ def print_exception(t, v, tb, limit=None, file=None, as_html=False,
information to the traceback and accepts two options, 'as_html'
and 'with_filenames'.
"""
if file is None: # pragma: no cover
if file is None: # pragma: no cover
file = sys.stderr
lines = format_exception(t, v, tb, limit, as_html, with_filenames)
for line in lines:
Expand Down
1 change: 1 addition & 0 deletions src/zope/exceptions/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

Buffer = io.StringIO if bytes is not str else io.BytesIO


class Formatter(logging.Formatter):

def formatException(self, ei):
Expand Down

0 comments on commit d799cda

Please sign in to comment.