[Zope-Checkins] CVS: Zope/lib/python/Zope/Startup - warnfilter.py:1.1 warnfilter.xml:1.1 zopeschema.xml:1.23

Chris McDonough cvs-admin at zope.org
Thu Nov 6 03:02:15 EST 2003


Update of /cvs-repository/Zope/lib/python/Zope/Startup
In directory cvs.zope.org:/tmp/cvs-serv14511

Modified Files:
	zopeschema.xml 
Added Files:
	warnfilter.py warnfilter.xml 
Log Message:
Moved warnfilter to Zope.Startup (from zLOG package).

Added tests.


=== Added File Zope/lib/python/Zope/Startup/warnfilter.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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 """

def warn_category(category):
    import re, types
    if not category:
        return Warning
    if re.match("^[a-zA-Z0-9_]+$", category):
        try:
            cat = eval(category)
        except NameError:
            raise ValueError("unknown warning category: %s" % `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: %s" % `module`)
        try:
            cat = getattr(m, klass)
        except AttributeError:
            raise ValueError("unknown warning category: %s" % `category`)
    if (not isinstance(cat, types.ClassType) or
        not issubclass(cat, Warning)):
        raise ValueError("invalid warning category: %s" % `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):
    import warnings
    # add the warning filter
    warnings.filterwarnings(section.action, section.message, section.category,
                            section.module, section.lineno, 1)
    return section




=== Added File Zope/lib/python/Zope/Startup/warnfilter.xml ===
<component prefix="Zope.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>



=== Zope/lib/python/Zope/Startup/zopeschema.xml 1.22 => 1.23 ===
--- Zope/lib/python/Zope/Startup/zopeschema.xml:1.22	Fri Oct 31 03:00:21 2003
+++ Zope/lib/python/Zope/Startup/zopeschema.xml	Thu Nov  6 03:01:45 2003
@@ -8,6 +8,7 @@
   <import package="ZODB"/>
   <import package="ZServer"/>
   <import package="tempstorage"/>
+  <import package="Zope.Startup" file="warnfilter.xml"/>
 
   <sectiontype name="logger" datatype=".LoggerFactory">
     <description>




More information about the Zope-Checkins mailing list