# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/.
import sys from contextlib import contextmanager
class ErrorMessage(Exception): """Exception type raised from errors.error() and errors.fatal()"""
class AccumulatedErrors(Exception): """Exception type raised from errors.accumulate()"""
class ErrorCollector(object): """
Error handling/logging class. A global instance, errors, is provided for
convenience.
Warnings, errors and fatal errors may be logged by calls to the following
functions:
- errors.warn(message)
- errors.error(message)
- errors.fatal(message)
Warnings only send the message on the logging output, while errors and
fatal errors send the message and throw an ErrorMessage exception. The
exception, however, may be deferred. See further below.
Errors may be ignored by calling:
- errors.ignore_errors()
After calling that function, only fatal errors throw an exception.
The warnings, errors or fatal errors messages may be augmented with context
information when a context is provided. Context is defined by a pair
(filename, linenumber), and may be set with errors.context() used as a
context manager:
.. code-block:: python
with errors.context(filename, linenumber):
errors.warn(message)
Arbitrary nesting is supported, both for errors.context calls:
.. code-block:: python
with errors.context(filename1, linenumber1):
errors.warn(message) with errors.context(filename2, linenumber2):
errors.warn(message)
as well asfor function calls:
.. code-block:: python
def func():
errors.warn(message) with errors.context(filename, linenumber):
func()
Errors and fatal errors can have their exception thrown at a later time,
allowing for several different errors to be reported at once before
throwing. This is achieved with errors.accumulate() as a context manager:
.. code-block:: python
with errors.accumulate(): if test1:
errors.error(message1) if test2:
errors.error(message2)
In such cases, a single AccumulatedErrors exception is thrown, but doesn't
contain information about the exceptions. The logged messages do. """
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.