Commit 62d6e254 authored by Hanno Schlichting's avatar Hanno Schlichting

Move zope.conf warnfilter into ZServer.

parent 70b5d923
##############################################################################
#
# Copyright (c) 2003 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Datatypes for warning filter component """
import re
import warnings
def warn_category(category):
if not category:
return Warning
if re.match("^[a-zA-Z0-9_]+$", category):
try:
cat = eval(category)
except NameError:
raise ValueError("unknown warning category: %r" % category)
else:
i = category.rfind(".")
module = category[:i]
klass = category[i + 1:]
try:
m = __import__(module, None, None, [klass])
except ImportError:
raise ValueError("invalid module name: %r" % module)
try:
cat = getattr(m, klass)
except AttributeError:
raise ValueError("unknown warning category: %r" % category)
if (not isinstance(cat, type(Warning)) or
not issubclass(cat, Warning)):
raise ValueError("invalid warning category: %r" % category)
return cat
def warn_action(val):
OK = ("error", "ignore", "always", "default", "module", "once")
if val not in OK:
raise ValueError("warning action %s not one of %s" % (val, OK))
return val
def warning_filter_handler(section):
# add the warning filter
warnings.filterwarnings(section.action, section.message, section.category,
section.module, section.lineno)
return section
<component prefix="Zope2.Startup.warnfilter">
<sectiontype name="warnfilter" datatype=".warning_filter_handler">
<key name="action" datatype=".warn_action" default="default"/>
<key name="message" default=""/>
<key name="category" datatype=".warn_category" default="Warning"/>
<key name="module" default=""/>
<key name="lineno" datatype="integer" default="0"/>
</sectiontype>
</component>
......@@ -7,7 +7,6 @@
<import package="ZConfig.components.logger" file="handlers.xml"/>
<import package="ZConfig.components.logger" file="eventlog.xml"/>
<import package="ZODB"/>
<import package="Zope2.Startup" file="warnfilter.xml"/>
<sectiontype name="logger" datatype=".LoggerFactory">
<description>
......@@ -102,41 +101,6 @@
<!-- schema begins -->
<multisection type="warnfilter" name="*" attribute="warnfilters">
<!-- from zLOG -->
<description>
A multisection which allows a user to set up a Python "warning" filter.
The following keys are valid within a warnfilter section:
action: one of the following strings:
"error" turn matching warnings into exceptions
"ignore" never print matching warnings
"always" always print matching warnings
"default" print the first occurrence of matching warnings
for each location where the warning is issued
"module" print the first occurrence of matching warnings
for each module where the warning is issued
"once" print only the first occurrence of matching
warnings, regardless of location
message: a string containing a regular expression that the
warning message must match (the match is compiled to
always be case-insensitive)
category: a Python dotted-path classname (must be a subclass of
Warning) of which the warning category must be a subclass in
order to match
module: a string containing a regular expression that the
module name must match (the match is compiled to be
case-sensitive)
lineno: an integer that the line number where the warning
occurred must match, or 0 to match all line numbers
</description>
</multisection>
<section type="environment" attribute="environment" name="*">
<description>
A section which allows a user to define arbitrary key-value pairs for
......
......@@ -7,6 +7,7 @@
<import package="tempstorage" condition="tempstorage"/>
<import package="ZServer"/>
<import package="ZServer.Zope2.Startup" file="warnfilter.xml"/>
<sectiontype name="cgi-environment"
datatype=".cgi_environment"
......@@ -171,6 +172,41 @@
<!-- schema begins -->
<multisection type="warnfilter" name="*" attribute="warnfilters">
<!-- from zLOG -->
<description>
A multisection which allows a user to set up a Python "warning" filter.
The following keys are valid within a warnfilter section:
action: one of the following strings:
"error" turn matching warnings into exceptions
"ignore" never print matching warnings
"always" always print matching warnings
"default" print the first occurrence of matching warnings
for each location where the warning is issued
"module" print the first occurrence of matching warnings
for each module where the warning is issued
"once" print only the first occurrence of matching
warnings, regardless of location
message: a string containing a regular expression that the
warning message must match (the match is compiled to
always be case-insensitive)
category: a Python dotted-path classname (must be a subclass of
Warning) of which the warning category must be a subclass in
order to match
module: a string containing a regular expression that the
module name must match (the match is compiled to be
case-sensitive)
lineno: an integer that the line number where the warning
occurred must match, or 0 to match all line numbers
</description>
</multisection>
<multikey name="products" datatype="existing-directory">
<description>
This specifies a product directory which is added to Products.__path__.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment