<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[14847] twext/trunk/twext</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/14847">14847</a></dd>
<dt>Author</dt> <dd>wsanchez@apple.com</dd>
<dt>Date</dt> <dd>2015-05-28 14:49:02 -0700 (Thu, 28 May 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Get rid of twext.python.log</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#twexttrunktwextapplicationmasterchildpy">twext/trunk/twext/application/masterchild.py</a></li>
<li><a href="#twexttrunktwextapplicationservicepy">twext/trunk/twext/application/service.py</a></li>
<li><a href="#twexttrunktwextenterprisejobqueuepy">twext/trunk/twext/enterprise/jobqueue.py</a></li>
<li><a href="#twexttrunktwextinternetsendfdportpy">twext/trunk/twext/internet/sendfdport.py</a></li>
<li><a href="#twexttrunktwextinternetsocketfilepy">twext/trunk/twext/internet/socketfile.py</a></li>
<li><a href="#twexttrunktwextinternettcppy">twext/trunk/twext/internet/tcp.py</a></li>
<li><a href="#twexttrunktwextwholdap_servicepy">twext/trunk/twext/who/ldap/_service.py</a></li>
<li><a href="#twexttrunktwextwhoopendirectory_servicepy">twext/trunk/twext/who/opendirectory/_service.py</a></li>
</ul>

<h3>Removed Paths</h3>
<ul>
<li><a href="#twexttrunktwextpythonlogpy">twext/trunk/twext/python/log.py</a></li>
<li><a href="#twexttrunktwextpythontesttest_logpy">twext/trunk/twext/python/test/test_log.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="twexttrunktwextapplicationmasterchildpy"></a>
<div class="modfile"><h4>Modified: twext/trunk/twext/application/masterchild.py (14846 => 14847)</h4>
<pre class="diff"><span>
<span class="info">--- twext/trunk/twext/application/masterchild.py        2015-05-28 21:41:18 UTC (rev 14846)
+++ twext/trunk/twext/application/masterchild.py        2015-05-28 21:49:02 UTC (rev 14847)
</span><span class="lines">@@ -44,6 +44,7 @@
</span><span class="cx"> from twisted.python.usage import Options, UsageError
</span><span class="cx"> from twisted.python.reflect import namedClass
</span><span class="cx"> from twisted.python.util import FancyStrMixin
</span><ins>+from twisted.logger import Logger
</ins><span class="cx"> from twisted.application.service import MultiService, Service
</span><span class="cx"> from twisted.application.service import IServiceMaker
</span><span class="cx"> from twisted.application.internet import TCPServer
</span><span class="lines">@@ -52,7 +53,6 @@
</span><span class="cx"> from twisted.internet.protocol import ServerFactory
</span><span class="cx"> from twisted.internet.protocol import ProcessProtocol
</span><span class="cx"> 
</span><del>-from twext.python.log import Logger
</del><span class="cx"> from twext.internet.sendfdport import InheritingProtocolFactory, IStatus
</span><span class="cx"> from twext.internet.sendfdport import InheritedSocketDispatcher
</span><span class="cx"> from twext.internet.sendfdport import IStatusWatcher
</span></span></pre></div>
<a id="twexttrunktwextapplicationservicepy"></a>
<div class="modfile"><h4>Modified: twext/trunk/twext/application/service.py (14846 => 14847)</h4>
<pre class="diff"><span>
<span class="info">--- twext/trunk/twext/application/service.py        2015-05-28 21:41:18 UTC (rev 14846)
+++ twext/trunk/twext/application/service.py        2015-05-28 21:49:02 UTC (rev 14847)
</span><span class="lines">@@ -26,12 +26,11 @@
</span><span class="cx"> import os
</span><span class="cx"> import signal
</span><span class="cx"> 
</span><ins>+from twisted.logger import Logger
</ins><span class="cx"> from twisted.application.service import MultiService
</span><span class="cx"> 
</span><del>-from twext.python.log import Logger
</del><span class="cx"> 
</span><span class="cx"> 
</span><del>-
</del><span class="cx"> class ReExecService(MultiService):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     A MultiService which catches SIGHUP and re-exec's the process.
</span></span></pre></div>
<a id="twexttrunktwextenterprisejobqueuepy"></a>
<div class="modfile"><h4>Modified: twext/trunk/twext/enterprise/jobqueue.py (14846 => 14847)</h4>
<pre class="diff"><span>
<span class="info">--- twext/trunk/twext/enterprise/jobqueue.py        2015-05-28 21:41:18 UTC (rev 14846)
+++ twext/trunk/twext/enterprise/jobqueue.py        2015-05-28 21:49:02 UTC (rev 14847)
</span><span class="lines">@@ -130,6 +130,8 @@
</span><span class="cx"> 
</span><span class="cx"> from zope.interface import implements
</span><span class="cx"> 
</span><ins>+from twisted.python.reflect import qual
+from twisted.logger import Logger
</ins><span class="cx"> from twisted.application.service import MultiService
</span><span class="cx"> from twisted.internet.protocol import Factory
</span><span class="cx"> from twisted.internet.defer import (
</span><span class="lines">@@ -138,8 +140,6 @@
</span><span class="cx"> from twisted.internet.endpoints import TCP4ClientEndpoint
</span><span class="cx"> from twisted.internet.error import AlreadyCalled, AlreadyCancelled
</span><span class="cx"> from twisted.protocols.amp import AMP, Command, Integer, String, Argument
</span><del>-from twisted.python.reflect import qual
-from twext.python.log import Logger
</del><span class="cx"> 
</span><span class="cx"> from twext.enterprise.dal.syntax import (
</span><span class="cx">     SchemaSyntax, Lock, NamedValue
</span></span></pre></div>
<a id="twexttrunktwextinternetsendfdportpy"></a>
<div class="modfile"><h4>Modified: twext/trunk/twext/internet/sendfdport.py (14846 => 14847)</h4>
<pre class="diff"><span>
<span class="info">--- twext/trunk/twext/internet/sendfdport.py        2015-05-28 21:41:18 UTC (rev 14846)
+++ twext/trunk/twext/internet/sendfdport.py        2015-05-28 21:49:02 UTC (rev 14847)
</span><span class="lines">@@ -29,10 +29,10 @@
</span><span class="cx"> from zope.interface import Interface
</span><span class="cx"> 
</span><span class="cx"> from twisted.python.sendmsg import send1msg, recv1msg, getsockfam
</span><ins>+from twisted.logger import Logger
</ins><span class="cx"> from twisted.internet.abstract import FileDescriptor
</span><span class="cx"> from twisted.internet.protocol import Protocol, Factory
</span><span class="cx"> 
</span><del>-from twext.python.log import Logger
</del><span class="cx"> from twext.python.sendfd import sendfd, recvfd
</span><span class="cx"> 
</span><span class="cx"> log = Logger()
</span></span></pre></div>
<a id="twexttrunktwextinternetsocketfilepy"></a>
<div class="modfile"><h4>Modified: twext/trunk/twext/internet/socketfile.py (14846 => 14847)</h4>
<pre class="diff"><span>
<span class="info">--- twext/trunk/twext/internet/socketfile.py        2015-05-28 21:41:18 UTC (rev 14846)
+++ twext/trunk/twext/internet/socketfile.py        2015-05-28 21:49:02 UTC (rev 14847)
</span><span class="lines">@@ -23,11 +23,11 @@
</span><span class="cx"> ]
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+from twisted.logger import Logger
</ins><span class="cx"> from twisted.application import service
</span><span class="cx"> from twisted.internet import endpoints
</span><span class="cx"> from twisted.internet.defer import inlineCallbacks
</span><span class="cx"> 
</span><del>-from twext.python.log import Logger
</del><span class="cx"> 
</span><span class="cx"> log = Logger()
</span><span class="cx"> 
</span></span></pre></div>
<a id="twexttrunktwextinternettcppy"></a>
<div class="modfile"><h4>Modified: twext/trunk/twext/internet/tcp.py (14846 => 14847)</h4>
<pre class="diff"><span>
<span class="info">--- twext/trunk/twext/internet/tcp.py        2015-05-28 21:41:18 UTC (rev 14846)
+++ twext/trunk/twext/internet/tcp.py        2015-05-28 21:49:02 UTC (rev 14847)
</span><span class="lines">@@ -26,11 +26,11 @@
</span><span class="cx"> import socket
</span><span class="cx"> from OpenSSL import SSL
</span><span class="cx"> 
</span><ins>+from twisted.logger import Logger
</ins><span class="cx"> from twisted.application import internet
</span><span class="cx"> from twisted.internet import tcp, ssl
</span><span class="cx"> from twisted.internet.defer import succeed
</span><span class="cx"> 
</span><del>-from twext.python.log import Logger
</del><span class="cx"> 
</span><span class="cx"> log = Logger()
</span><span class="cx"> 
</span></span></pre></div>
<a id="twexttrunktwextpythonlogpy"></a>
<div class="delfile"><h4>Deleted: twext/trunk/twext/python/log.py (14846 => 14847)</h4>
<pre class="diff"><span>
<span class="info">--- twext/trunk/twext/python/log.py        2015-05-28 21:41:18 UTC (rev 14846)
+++ twext/trunk/twext/python/log.py        2015-05-28 21:49:02 UTC (rev 14847)
</span><span class="lines">@@ -1,1011 +0,0 @@
</span><del>-# -*- test-case-name: twext.python.test.test_log-*-
-##
-# Copyright (c) 2006-2015 Apple Inc. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-##
-
-&quot;&quot;&quot;
-Classes and functions to do granular logging.
-
-Example usage in a module C{some.module}::
-
-    from twext.python.log import Logger
-    log = Logger()
-
-    def handleData(data):
-        log.debug(&quot;Got data: {data!r}.&quot;, data=data)
-
-Or in a class::
-
-    from twext.python.log import Logger
-
-    class Foo(object):
-        log = Logger()
-
-        def oops(self, data):
-            self.log.error(&quot;Oops! Invalid data from server: {data!r}&quot;,
-                           data=data)
-
-C{Logger}s have namespaces, for which logging can be configured independently.
-Namespaces may be specified by passing in a C{namespace} argument to L{Logger}
-when instantiating it, but if none is given, the logger will derive its own
-namespace by using the module name of the callable that instantiated it, or, in
-the case of a class, by using the fully qualified name of the class.
-
-In the first example above, the namespace would be C{some.module}, and in the
-second example, it would be C{some.module.Foo}.
-&quot;&quot;&quot;
-
-__all__ = [
-    &quot;InvalidLogLevelError&quot;,
-    &quot;LogLevel&quot;,
-    &quot;formatEvent&quot;,
-    &quot;Logger&quot;,
-    &quot;LegacyLogger&quot;,
-    &quot;ILogObserver&quot;,
-    &quot;LogPublisher&quot;,
-    &quot;PredicateResult&quot;,
-    &quot;ILogFilterPredicate&quot;,
-    &quot;FilteringLogObserver&quot;,
-    &quot;LogLevelFilterPredicate&quot;,
-    &quot;LegacyLogObserver&quot;,
-    &quot;replaceTwistedLoggers&quot;,
-]
-
-
-
-import sys
-from sys import stdout, stderr
-from string import Formatter
-import inspect
-import logging
-import time
-
-from zope.interface import Interface, implementer
-from twisted.python.constants import NamedConstant, Names
-from twisted.python.failure import Failure
-from twisted.python.reflect import safe_str, safe_repr
-import twisted.python.log
-from twisted.python.log import msg as twistedLogMessage
-from twisted.python.log import addObserver, removeObserver
-
-
-
-OBSERVER_REMOVED = (
-    &quot;Temporarily removing observer {observer} due to exception: {e}&quot;
-)
-
-
-
-#
-# Log level definitions
-#
-
-class InvalidLogLevelError(Exception):
-    &quot;&quot;&quot;
-    Someone tried to use a L{LogLevel} that is unknown to the logging system.
-    &quot;&quot;&quot;
-    def __init__(self, level):
-        &quot;&quot;&quot;
-        @param level: a L{LogLevel}
-        &quot;&quot;&quot;
-        super(InvalidLogLevelError, self).__init__(str(level))
-        self.level = level
-
-
-
-class LogLevel(Names):
-    &quot;&quot;&quot;
-    Constants denoting log levels:
-
-     - C{debug}: Information of use to a developer of the software, not
-       generally of interest to someone running the software unless they are
-       attempting to diagnose a software issue.
-
-     - C{info}: Informational events: Routine information about the status of
-       an application, such as incoming connections, startup of a subsystem,
-       etc.
-
-     - C{warn}: Warnings events: Events that may require greater attention than
-       informational events but are not a systemic failure condition, such as
-       authorization failures, bad data from a network client, etc.
-
-     - C{error}: Error conditions: Events indicating a systemic failure, such
-       as unhandled exceptions, loss of connectivity to a back-end database,
-       etc.
-    &quot;&quot;&quot;
-    debug = NamedConstant()
-    info = NamedConstant()
-    warn = NamedConstant()
-    error = NamedConstant()
-    critical = NamedConstant()
-
-    @classmethod
-    def levelWithName(cls, name):
-        &quot;&quot;&quot;
-        @param name: the name of a L{LogLevel}
-
-        @return: the L{LogLevel} with the specified C{name}
-        &quot;&quot;&quot;
-        try:
-            return cls.lookupByName(name)
-        except ValueError:
-            raise InvalidLogLevelError(name)
-
-
-    @classmethod
-    def _priorityForLevel(cls, constant):
-        &quot;&quot;&quot;
-        We want log levels to have defined ordering - the order of definition -
-        but they aren't value constants (the only value is the name).  This is
-        arguably a bug in Twisted, so this is just a workaround for U{until
-        this is fixed in some way
-        &lt;https://twistedmatrix.com/trac/ticket/6523&gt;}.
-        &quot;&quot;&quot;
-        return cls._levelPriorities[constant]
-
-
-LogLevel._levelPriorities = dict(
-    (constant, idx) for (idx, constant) in
-    (enumerate(LogLevel.iterconstants()))
-)
-
-
-
-#
-# Mappings to Python's logging module
-#
-pythonLogLevelMapping = {
-    LogLevel.debug: logging.DEBUG,
-    LogLevel.info: logging.INFO,
-    LogLevel.warn: logging.WARNING,
-    LogLevel.error: logging.ERROR,
-    LogLevel.critical: logging.CRITICAL,
-}
-
-
-
-##
-# Loggers
-##
-
-def formatEvent(event):
-    &quot;&quot;&quot;
-    Formats an event as a L{unicode}, using the format in
-    C{event[&quot;log_format&quot;]}.
-
-    This implementation should never raise an exception; if the formatting
-    cannot be done, the returned string will describe the event generically so
-    that a useful message is emitted regardless.
-
-    @param event: a logging event
-
-    @return: a L{unicode}
-    &quot;&quot;&quot;
-    try:
-        format = event.get(&quot;log_format&quot;, None)
-
-        if format is None:
-            raise ValueError(&quot;No log format provided&quot;)
-
-        # Make sure format is unicode.
-        if isinstance(format, bytes):
-            # If we get bytes, assume it's UTF-8 bytes
-            format = format.decode(&quot;utf-8&quot;)
-
-        elif isinstance(format, unicode):
-            pass
-
-        else:
-            raise TypeError(&quot;Log format must be unicode or bytes, not {0!r}&quot;
-                            .format(format))
-
-        return formatWithCall(format, event)
-
-    except BaseException as e:
-        return formatUnformattableEvent(event, e)
-
-
-
-def formatUnformattableEvent(event, error):
-    &quot;&quot;&quot;
-    Formats an event as a L{unicode} that describes the event generically and a
-    formatting error.
-
-    @param event: a logging event
-    @type dict: L{dict}
-
-    @param error: the formatting error
-    @type error: L{Exception}
-
-    @return: a L{unicode}
-    &quot;&quot;&quot;
-    try:
-        return (
-            u&quot;Unable to format event {event!r}: {error}&quot;
-            .format(event=event, error=error)
-        )
-    except BaseException:
-        # Yikes, something really nasty happened.
-        #
-        # Try to recover as much formattable data as possible; hopefully at
-        # least the namespace is sane, which will help you find the offending
-        # logger.
-        failure = Failure()
-
-        text = &quot;, &quot;.join(&quot; = &quot;.join((safe_repr(key), safe_repr(value)))
-                         for key, value in event.items())
-
-        return (
-            u&quot;MESSAGE LOST: unformattable object logged: {error}\n&quot;
-            u&quot;Recoverable data: {text}\n&quot;
-            u&quot;Exception during formatting:\n{failure}&quot;
-            .format(error=safe_repr(error), failure=failure, text=text)
-        )
-
-
-
-class Logger(object):
-    &quot;&quot;&quot;
-    Logging object.
-    &quot;&quot;&quot;
-
-    publisher = lambda e: None
-
-
-    @staticmethod
-    def _namespaceFromCallingContext():
-        &quot;&quot;&quot;
-        Derive a namespace from the module containing the caller's caller.
-
-        @return: a namespace
-        &quot;&quot;&quot;
-        return inspect.currentframe().f_back.f_back.f_globals[&quot;__name__&quot;]
-
-
-    def __init__(self, namespace=None, source=None):
-        &quot;&quot;&quot;
-        @param namespace: The namespace for this logger.  Uses a dotted
-            notation, as used by python modules.  If not C{None}, then the name
-            of the module of the caller is used.
-
-        @param source: The object which is emitting events to this
-            logger; this is automatically set on instances of a class
-            if this L{Logger} is an attribute of that class.
-        &quot;&quot;&quot;
-        if namespace is None:
-            namespace = self._namespaceFromCallingContext()
-
-        self.namespace = namespace
-        self.source = source
-
-
-    def __get__(self, oself, type=None):
-        &quot;&quot;&quot;
-        When used as a descriptor, i.e.::
-
-            # athing.py
-            class Something(object):
-                log = Logger()
-                def hello(self):
-                    self.log.info(&quot;Hello&quot;)
-
-        a L{Logger}'s namespace will be set to the name of the class it is
-        declared on.  In the above example, the namespace would be
-        C{athing.Something}.
-
-        Additionally, it's source will be set to the actual object referring to
-        the L{Logger}.  In the above example, C{Something.log.source} would be
-        C{Something}, and C{Something().log.source} would be an instance of
-        C{Something}.
-        &quot;&quot;&quot;
-        if oself is None:
-            source = type
-        else:
-            source = oself
-
-        return self.__class__(
-            '.'.join([type.__module__, type.__name__]),
-            source
-        )
-
-
-    def __repr__(self):
-        return &quot;&lt;%s %r&gt;&quot; % (self.__class__.__name__, self.namespace)
-
-
-    def emit(self, level, format=None, **kwargs):
-        &quot;&quot;&quot;
-        Emit a log event to all log observers at the given level.
-
-        @param level: a L{LogLevel}
-
-        @param format: a message format using new-style (PEP 3101)
-            formatting.  The logging event (which is a L{dict}) is
-            used to render this format string.
-
-        @param kwargs: additional keyword parameters to include with
-            the event.
-        &quot;&quot;&quot;
-        # FIXME: Updated Twisted supports 'in' on constants container
-        if level not in LogLevel.iterconstants():
-            self.failure(
-                &quot;Got invalid log level {invalidLevel!r} in {logger}.emit().&quot;,
-                Failure(InvalidLogLevelError(level)),
-                invalidLevel=level,
-                logger=self,
-            )
-            # level = LogLevel.error
-            # FIXME: continue to emit?
-            return
-
-        kwargs.update(
-            log_logger=self, log_level=level, log_namespace=self.namespace,
-            log_source=self.source, log_format=format, log_time=time.time(),
-        )
-
-        self.publisher(kwargs)
-
-
-    def failure(self, format, failure=None, level=LogLevel.error, **kwargs):
-        &quot;&quot;&quot;
-        Log an failure and emit a traceback.
-
-        For example::
-
-            try:
-                frob(knob)
-            except Exception:
-                log.failure(&quot;While frobbing {knob}&quot;, knob=knob)
-
-        or::
-
-            d = deferredFrob(knob)
-            d.addErrback(lambda f: log.failure, &quot;While frobbing {knob}&quot;,
-                         f, knob=knob)
-
-        @param format: a message format using new-style (PEP 3101)
-            formatting.  The logging event (which is a L{dict}) is
-            used to render this format string.
-
-        @param failure: a L{Failure} to log.  If C{None}, a L{Failure} is
-            created from the exception in flight.
-
-        @param level: a L{LogLevel} to use.
-
-        @param kwargs: additional keyword parameters to include with the
-            event.
-        &quot;&quot;&quot;
-        if failure is None:
-            failure = Failure()
-
-        self.emit(level, format, log_failure=failure, **kwargs)
-
-
-
-class LegacyLogger(object):
-    &quot;&quot;&quot;
-    A logging object that provides some compatibility with the
-    L{twisted.python.log} module.
-    &quot;&quot;&quot;
-
-    def __init__(self, logger=None):
-        if logger is None:
-            self.newStyleLogger = Logger(Logger._namespaceFromCallingContext())
-        else:
-            self.newStyleLogger = logger
-
-
-    def __getattribute__(self, name):
-        try:
-            return super(LegacyLogger, self).__getattribute__(name)
-        except AttributeError:
-            return getattr(twisted.python.log, name)
-
-
-    def msg(self, *message, **kwargs):
-        &quot;&quot;&quot;
-        This method is API-compatible with L{twisted.python.log.msg} and exists
-        for compatibility with that API.
-        &quot;&quot;&quot;
-        if message:
-            message = &quot; &quot;.join(map(safe_str, message))
-        else:
-            message = None
-        return self.newStyleLogger.emit(LogLevel.info, message, **kwargs)
-
-
-    def err(self, _stuff=None, _why=None, **kwargs):
-        &quot;&quot;&quot;
-        This method is API-compatible with L{twisted.python.log.err} and exists
-        for compatibility with that API.
-        &quot;&quot;&quot;
-        if _stuff is None:
-            _stuff = Failure()
-        elif isinstance(_stuff, Exception):
-            _stuff = Failure(_stuff)
-
-        if isinstance(_stuff, Failure):
-            self.newStyleLogger.emit(LogLevel.error, failure=_stuff, why=_why,
-                                     isError=1, **kwargs)
-        else:
-            # We got called with an invalid _stuff.
-            self.newStyleLogger.emit(LogLevel.error, repr(_stuff), why=_why,
-                                     isError=1, **kwargs)
-
-
-
-def bindEmit(level):
-    doc = &quot;&quot;&quot;
-    Emit a log event at log level L{{{level}}}.
-
-    @param format: a message format using new-style (PEP 3101)
-        formatting.  The logging event (which is a L{{dict}}) is used to
-        render this format string.
-
-    @param kwargs: additional keyword parameters to include with the
-        event.
-    &quot;&quot;&quot;.format(level=level.name)
-
-    #
-    # Attach methods to Logger
-    #
-    def log_emit(self, format=None, **kwargs):
-        self.emit(level, format, **kwargs)
-
-    log_emit.__doc__ = doc
-
-    setattr(Logger, level.name, log_emit)
-
-
-
-def _bindLevels():
-    for level in LogLevel.iterconstants():
-        bindEmit(level)
-
-_bindLevels()
-
-
-#
-# Observers
-#
-
-class ILogObserver(Interface):
-    &quot;&quot;&quot;
-    An observer which can handle log events.
-    &quot;&quot;&quot;
-
-    def __call__(event):
-        &quot;&quot;&quot;
-        Log an event.
-
-        @type event: C{dict} with (native) C{str} keys.
-
-        @param event: A dictionary with arbitrary keys as defined by
-            the application emitting logging events, as well as keys
-            added by the logging system, with are:
-            ...
-        &quot;&quot;&quot;
-
-
-
-@implementer(ILogObserver)
-class LogPublisher(object):
-    &quot;&quot;&quot;
-    I{ILogObserver} that fans out events to other observers.
-
-    Keeps track of a set of L{ILogObserver} objects and forwards
-    events to each.
-    &quot;&quot;&quot;
-    log = Logger()
-
-    def __init__(self, *observers):
-        self._observers = set(observers)
-
-
-    @property
-    def observers(self):
-        return frozenset(self._observers)
-
-
-    def addObserver(self, observer):
-        &quot;&quot;&quot;
-        Registers an observer with this publisher.
-
-        @param observer: An L{ILogObserver} to add.
-        &quot;&quot;&quot;
-        self._observers.add(observer)
-
-
-    def removeObserver(self, observer):
-        &quot;&quot;&quot;
-        Unregisters an observer with this publisher.
-
-        @param observer: An L{ILogObserver} to remove.
-        &quot;&quot;&quot;
-        try:
-            self._observers.remove(observer)
-        except KeyError:
-            pass
-
-
-    def __call__(self, event):
-        for observer in self.observers:
-            try:
-                observer(event)
-            except BaseException as e:
-                #
-                # We have to remove the offending observer because
-                # we're going to badmouth it to all of its friends
-                # (other observers) and it might get offended and
-                # raise again, causing an infinite loop.
-                #
-                self.removeObserver(observer)
-                try:
-                    self.log.failure(OBSERVER_REMOVED, observer=observer, e=e)
-                except BaseException:
-                    pass
-                finally:
-                    self.addObserver(observer)
-
-
-
-class PredicateResult(Names):
-    &quot;&quot;&quot;
-    Predicate results.
-    &quot;&quot;&quot;
-    yes = NamedConstant()    # Log this
-    no = NamedConstant()     # Don't log this
-    maybe = NamedConstant()  # No opinion
-
-
-
-class ILogFilterPredicate(Interface):
-    &quot;&quot;&quot;
-    A predicate that determined whether an event should be logged.
-    &quot;&quot;&quot;
-
-    def __call__(event):
-        &quot;&quot;&quot;
-        Determine whether an event should be logged.
-
-        @returns: a L{PredicateResult}.
-        &quot;&quot;&quot;
-
-
-
-@implementer(ILogObserver)
-class FilteringLogObserver(object):
-    &quot;&quot;&quot;
-    L{ILogObserver} that wraps another L{ILogObserver}, but filters
-    out events based on applying a series of L{ILogFilterPredicate}s.
-    &quot;&quot;&quot;
-
-    def __init__(self, observer, predicates):
-        &quot;&quot;&quot;
-        @param observer: an L{ILogObserver} to which this observer
-            will forward events.
-
-        @param predicates: an ordered iterable of predicates to apply
-            to events before forwarding to the wrapped observer.
-        &quot;&quot;&quot;
-        self.observer = observer
-        self.predicates = list(predicates)
-
-
-    def shouldLogEvent(self, event):
-        &quot;&quot;&quot;
-        Determine whether an event should be logged, based
-        C{self.predicates}.
-
-        @param event: an event
-        &quot;&quot;&quot;
-        for predicate in self.predicates:
-            result = predicate(event)
-            if result == PredicateResult.yes:
-                return True
-            if result == PredicateResult.no:
-                return False
-            if result == PredicateResult.maybe:
-                continue
-            raise TypeError(&quot;Invalid predicate result: {0!r}&quot;.format(result))
-        return True
-
-
-    def __call__(self, event):
-        if self.shouldLogEvent(event):
-            self.observer(event)
-
-
-
-@implementer(ILogFilterPredicate)
-class LogLevelFilterPredicate(object):
-    &quot;&quot;&quot;
-    L{ILogFilterPredicate} that filters out events with a log level
-    lower than the log level for the event's namespace.
-
-    Events that not not have a log level or namespace are also dropped.
-    &quot;&quot;&quot;
-
-    def __init__(self):
-        # FIXME: Make this a class variable. But that raises an
-        # _initializeEnumerants constants error in Twisted 12.2.0.
-        self.defaultLogLevel = LogLevel.info
-
-        self._logLevelsByNamespace = {}
-        self.clearLogLevels()
-
-
-    def logLevelForNamespace(self, namespace):
-        &quot;&quot;&quot;
-        @param namespace: a logging namespace, or C{None} for the default
-            namespace.
-
-        @return: the L{LogLevel} for the specified namespace.
-        &quot;&quot;&quot;
-        if not namespace:
-            return self._logLevelsByNamespace[None]
-
-        if namespace in self._logLevelsByNamespace:
-            return self._logLevelsByNamespace[namespace]
-
-        segments = namespace.split(&quot;.&quot;)
-        index = len(segments) - 1
-
-        while index &gt; 0:
-            namespace = &quot;.&quot;.join(segments[:index])
-            if namespace in self._logLevelsByNamespace:
-                return self._logLevelsByNamespace[namespace]
-            index -= 1
-
-        return self._logLevelsByNamespace[None]
-
-
-    def setLogLevelForNamespace(self, namespace, level):
-        &quot;&quot;&quot;
-        Sets the global log level for a logging namespace.
-
-        @param namespace: a logging namespace
-
-        @param level: the L{LogLevel} for the given namespace.
-        &quot;&quot;&quot;
-        if level not in LogLevel.iterconstants():
-            raise InvalidLogLevelError(level)
-
-        if namespace:
-            self._logLevelsByNamespace[namespace] = level
-        else:
-            self._logLevelsByNamespace[None] = level
-
-
-    def clearLogLevels(self):
-        &quot;&quot;&quot;
-        Clears all global log levels to the default.
-        &quot;&quot;&quot;
-        self._logLevelsByNamespace.clear()
-        self._logLevelsByNamespace[None] = self.defaultLogLevel
-
-
-    def __call__(self, event):
-        level = event.get(&quot;log_level&quot;, None)
-        namespace = event.get(&quot;log_namespace&quot;, None)
-
-        if (
-            level is None or
-            namespace is None or
-            LogLevel._priorityForLevel(level) &lt;
-            LogLevel._priorityForLevel(self.logLevelForNamespace(namespace))
-        ):
-            return PredicateResult.no
-
-        return PredicateResult.maybe
-
-
-
-@implementer(ILogObserver)
-class LegacyLogObserver(object):
-    &quot;&quot;&quot;
-    L{ILogObserver} that wraps an L{ILegacyLogObserver}.
-    &quot;&quot;&quot;
-
-    def __init__(self, legacyObserver):
-        &quot;&quot;&quot;
-        @param legacyObserver: an L{ILegacyLogObserver} to which this
-            observer will forward events.
-        &quot;&quot;&quot;
-        self.legacyObserver = legacyObserver
-
-
-    def __call__(self, event):
-        prefix = &quot;[{log_namespace}#{log_level.name}] &quot;.format(**event)
-
-        level = event[&quot;log_level&quot;]
-
-        #
-        # Twisted's logging supports indicating a python log level, so let's
-        # provide the equivalent to our logging levels.
-        #
-        if level in pythonLogLevelMapping:
-            event[&quot;logLevel&quot;] = pythonLogLevelMapping[level]
-
-        # Format new style -&gt; old style
-        if event[&quot;log_format&quot;]:
-            #
-            # Create an object that implements __str__() in order to
-            # defer the work of formatting until it's needed by a
-            # legacy log observer.
-            #
-            class LegacyFormatStub(object):
-                def __str__(oself):
-                    return formatEvent(event).encode(&quot;utf-8&quot;)
-
-            event[&quot;format&quot;] = prefix + &quot;%(log_legacy)s&quot;
-            event[&quot;log_legacy&quot;] = LegacyFormatStub()
-
-        # log.failure() -&gt; isError blah blah
-        if &quot;log_failure&quot; in event:
-            event[&quot;failure&quot;] = event[&quot;log_failure&quot;]
-            event[&quot;isError&quot;] = 1
-            event[&quot;why&quot;] = &quot;{prefix}{message}&quot;.format(
-                prefix=prefix, message=formatEvent(event)
-            )
-
-        self.legacyObserver(**event)
-
-
-
-# FIXME: This could have a better name.
-class DefaultLogPublisher(object):
-    &quot;&quot;&quot;
-    This observer sets up a set of chained observers as follows:
-
-        1. B{rootPublisher} - a L{LogPublisher}
-
-        2. B{filters}: a L{FilteringLogObserver} that filters out messages
-           using a L{LogLevelFilterPredicate}
-
-        3. B{filteredPublisher} - a L{LogPublisher}
-
-        4. B{legacyLogObserver} - a L{LegacyLogObserver} wired up to
-           L{twisted.python.log.msg}.  This allows any observers registered
-           with Twisted's logging (that is, most observers in presently use) to
-           receive (filtered) events.
-
-    The purpose of this class is to provide a default log observer with
-    sufficient hooks to enable applications to add observers that can either
-    receive all log messages, or only log messages that are configured to pass
-    though the L{LogLevelFilterPredicate}::
-
-        from twext.python.log import Logger, ILogObserver
-
-        log = Logger()
-
-        @implementer(ILogObserver)
-        class AMPObserver(object):
-            def __call__(self, event):
-                # eg.: Hold events in a ring buffer and expose them via AMP.
-                ...
-
-        @implementer(ILogObserver)
-        class FileObserver(object):
-            def __call__(self, event):
-                # eg.: Take events and write them into a file.
-                ...
-
-        # Send all events to the AMPObserver
-        log.publisher.addObserver(AMPObserver(), filtered=False)
-
-        # Send filtered events to the FileObserver
-        log.publisher.addObserver(AMPObserver())
-
-    With no observers added, the default behavior is that the legacy Twisted
-    logging system sees messages as controlled by L{LogLevelFilterPredicate}.
-    &quot;&quot;&quot;
-
-    def __init__(self):
-        self.legacyLogObserver = LegacyLogObserver(twistedLogMessage)
-        self.filteredPublisher = LogPublisher(self.legacyLogObserver)
-        self.levels = LogLevelFilterPredicate()
-        self.filters = FilteringLogObserver(
-            self.filteredPublisher, (self.levels,)
-        )
-        self.rootPublisher = LogPublisher(self.filters)
-
-
-    def addObserver(self, observer, filtered=True):
-        &quot;&quot;&quot;
-        Registers an observer with this publisher.
-
-        @param observer: An L{ILogObserver} to add.
-
-        @param filtered: If true, registers C{observer} after filters are
-            applied; otherwise C{observer} will get all events.
-        &quot;&quot;&quot;
-        if filtered:
-            self.filteredPublisher.addObserver(observer)
-            self.rootPublisher.removeObserver(observer)
-        else:
-            self.rootPublisher.addObserver(observer)
-            self.filteredPublisher.removeObserver(observer)
-
-
-    def removeObserver(self, observer):
-        &quot;&quot;&quot;
-        Unregisters an observer with this publisher.
-
-        @param observer: An L{ILogObserver} to remove.
-        &quot;&quot;&quot;
-        self.rootPublisher.removeObserver(observer)
-        self.filteredPublisher.removeObserver(observer)
-
-
-    def __call__(self, event):
-        self.rootPublisher(event)
-
-
-
-Logger.publisher = DefaultLogPublisher()
-
-
-
-#
-# Utilities
-#
-
-class CallMapping(object):
-    def __init__(self, submapping):
-        self._submapping = submapping
-
-
-    def __getitem__(self, key):
-        callit = key.endswith(u&quot;()&quot;)
-        realKey = key[:-2] if callit else key
-        value = self._submapping[realKey]
-        if callit:
-            value = value()
-        return value
-
-
-
-def formatWithCall(formatString, mapping):
-    &quot;&quot;&quot;
-    Format a string like L{unicode.format}, but:
-
-        - taking only a name mapping; no positional arguments
-
-        - with the additional syntax that an empty set of parentheses
-          correspond to a formatting item that should be called, and its result
-          C{str}'d, rather than calling C{str} on the element directly as
-          normal.
-
-    For example::
-
-        &gt;&gt;&gt; formatWithCall(&quot;{string}, {function()}.&quot;,
-        ...                dict(string=&quot;just a string&quot;,
-        ...                     function=lambda: &quot;a function&quot;))
-        'just a string, a function.'
-
-    @param formatString: A PEP-3101 format string.
-    @type formatString: L{unicode}
-
-    @param mapping: A L{dict}-like object to format.
-
-    @return: The string with formatted values interpolated.
-    @rtype: L{unicode}
-    &quot;&quot;&quot;
-    return unicode(
-        theFormatter.vformat(formatString, (), CallMapping(mapping))
-    )
-
-theFormatter = Formatter()
-
-
-def replaceTwistedLoggers():
-    &quot;&quot;&quot;
-    Visit all Python modules that have been loaded and:
-
-     - replace L{twisted.python.log} with a L{LegacyLogger}
-
-     - replace L{twisted.python.log.msg} with a L{LegacyLogger}'s C{msg}
-
-     - replace L{twisted.python.log.err} with a L{LegacyLogger}'s C{err}
-    &quot;&quot;&quot;
-    log = Logger()
-
-    for moduleName, module in sys.modules.iteritems():
-        # Oddly, this happens
-        if module is None:
-            continue
-
-        # Don't patch Twisted's logging module
-        if module in (twisted.python, twisted.python.log):
-            continue
-
-        # Don't patch this module
-        if moduleName is __name__:
-            continue
-
-        try:
-            for name, obj in module.__dict__.iteritems():
-                try:
-                    newLogger = Logger(namespace=module.__name__)
-                except AttributeError:
-                    # Can't look up __name__.  A hack in the &quot;six&quot; module causes
-                    # this.  Skip the module.
-                    # See https://trac.calendarserver.org/ticket/832
-                    continue
-
-                legacyLogger = LegacyLogger(logger=newLogger)
-
-                if obj is twisted.python.log:
-                    log.info(
-                        &quot;Replacing Twisted log module object {0} in {1}&quot;
-                        .format(name, module.__name__)
-                    )
-                    setattr(module, name, legacyLogger)
-
-                elif obj is twisted.python.log.msg:
-                    log.info(
-                        &quot;Replacing Twisted log.msg object {0} in {1}&quot;
-                        .format(name, module.__name__)
-                    )
-                    setattr(module, name, legacyLogger.msg)
-
-                elif obj is twisted.python.log.err:
-                    log.info(
-                        &quot;Replacing Twisted log.err object {0} in {1}&quot;
-                        .format(name, module.__name__)
-                    )
-                    setattr(module, name, legacyLogger.err)
-        except RuntimeError as e:
-            # Python could use more specific exceptions, eh.
-            # What we mean to catch is:
-            # RuntimeError: dictionary changed size during iteration
-            log.error(
-                &quot;Unable to replace twisted loggers for module {module}: &quot;
-                &quot;{error}&quot;,
-                module=module, error=e
-            )
-
-
-
-# FIXME: This may not be needed; look into removing it.
-
-class StandardIOObserver(object):
-    &quot;&quot;&quot;
-    (Legacy) log observer that writes to standard I/O.
-    &quot;&quot;&quot;
-    def emit(self, eventDict):
-        text = None
-
-        if eventDict[&quot;isError&quot;]:
-            output = stderr
-            if &quot;failure&quot; in eventDict:
-                text = eventDict[&quot;failure&quot;].getTraceback()
-        else:
-            output = stdout
-
-        if not text:
-            text = &quot; &quot;.join([str(m) for m in eventDict[&quot;message&quot;]]) + &quot;\n&quot;
-
-        output.write(text)
-        output.flush()
-
-
-    def start(self):
-        addObserver(self.emit)
-
-
-    def stop(self):
-        removeObserver(self.emit)
</del></span></pre></div>
<a id="twexttrunktwextpythontesttest_logpy"></a>
<div class="delfile"><h4>Deleted: twext/trunk/twext/python/test/test_log.py (14846 => 14847)</h4>
<pre class="diff"><span>
<span class="info">--- twext/trunk/twext/python/test/test_log.py        2015-05-28 21:41:18 UTC (rev 14846)
+++ twext/trunk/twext/python/test/test_log.py        2015-05-28 21:49:02 UTC (rev 14847)
</span><span class="lines">@@ -1,1029 +0,0 @@
</span><del>-##
-# Copyright (c) 2005-2015 Apple Inc. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-##
-
-from zope.interface.verify import verifyObject, BrokenMethodImplementation
-
-from twisted.python import log as twistedLogging
-from twisted.python.failure import Failure
-from twisted.trial import unittest
-
-from twext.python.log import (
-    LogLevel, InvalidLogLevelError,
-    pythonLogLevelMapping,
-    formatEvent, formatUnformattableEvent, formatWithCall,
-    Logger, LegacyLogger,
-    ILogObserver, LogPublisher, DefaultLogPublisher,
-    FilteringLogObserver, PredicateResult,
-    LogLevelFilterPredicate, OBSERVER_REMOVED
-)
-
-
-
-defaultLogLevel = LogLevelFilterPredicate().defaultLogLevel
-clearLogLevels = Logger.publisher.levels.clearLogLevels
-logLevelForNamespace = Logger.publisher.levels.logLevelForNamespace
-setLogLevelForNamespace = Logger.publisher.levels.setLogLevelForNamespace
-
-
-
-class TestLogger(Logger):
-    def emit(self, level, format=None, **kwargs):
-        if False:
-            print &quot;*&quot; * 60
-            print &quot;level =&quot;, level
-            print &quot;format =&quot;, format
-            for key, value in kwargs.items():
-                print key, &quot;=&quot;, value
-            print &quot;*&quot; * 60
-
-        def observer(event):
-            self.event = event
-
-        twistedLogging.addObserver(observer)
-        try:
-            Logger.emit(self, level, format, **kwargs)
-        finally:
-            twistedLogging.removeObserver(observer)
-
-        self.emitted = {
-            &quot;level&quot;: level,
-            &quot;format&quot;: format,
-            &quot;kwargs&quot;: kwargs,
-        }
-
-
-
-class TestLegacyLogger(LegacyLogger):
-    def __init__(self, logger=TestLogger()):
-        LegacyLogger.__init__(self, logger=logger)
-
-
-
-class LogComposedObject(object):
-    &quot;&quot;&quot;
-    Just a regular object.
-    &quot;&quot;&quot;
-    log = TestLogger()
-
-    def __init__(self, state=None):
-        self.state = state
-
-
-    def __str__(self):
-        return &quot;&lt;LogComposedObject {state}&gt;&quot;.format(state=self.state)
-
-
-
-class SetUpTearDown(object):
-    def setUp(self):
-        super(SetUpTearDown, self).setUp()
-        clearLogLevels()
-
-
-    def tearDown(self):
-        super(SetUpTearDown, self).tearDown()
-        clearLogLevels()
-
-
-
-class LoggingTests(SetUpTearDown, unittest.TestCase):
-    &quot;&quot;&quot;
-    General module tests.
-    &quot;&quot;&quot;
-
-    def test_levelWithName(self):
-        &quot;&quot;&quot;
-        Look up log level by name.
-        &quot;&quot;&quot;
-        for level in LogLevel.iterconstants():
-            self.assertIdentical(LogLevel.levelWithName(level.name), level)
-
-
-    def test_levelWithInvalidName(self):
-        &quot;&quot;&quot;
-        You can't make up log level names.
-        &quot;&quot;&quot;
-        bogus = &quot;*bogus*&quot;
-        try:
-            LogLevel.levelWithName(bogus)
-        except InvalidLogLevelError as e:
-            self.assertIdentical(e.level, bogus)
-        else:
-            self.fail(&quot;Expected InvalidLogLevelError.&quot;)
-
-
-    def test_defaultLogLevel(self):
-        &quot;&quot;&quot;
-        Default log level is used.
-        &quot;&quot;&quot;
-        self.failUnless(logLevelForNamespace(None), defaultLogLevel)
-        self.failUnless(logLevelForNamespace(&quot;&quot;), defaultLogLevel)
-        self.failUnless(logLevelForNamespace(&quot;rocker.cool.namespace&quot;),
-                        defaultLogLevel)
-
-
-    def test_setLogLevel(self):
-        &quot;&quot;&quot;
-        Setting and retrieving log levels.
-        &quot;&quot;&quot;
-        setLogLevelForNamespace(None, LogLevel.error)
-        setLogLevelForNamespace(&quot;twext.web2&quot;, LogLevel.debug)
-        setLogLevelForNamespace(&quot;twext.web2.dav&quot;, LogLevel.warn)
-
-        self.assertEquals(logLevelForNamespace(None),
-                          LogLevel.error)
-        self.assertEquals(logLevelForNamespace(&quot;twisted&quot;),
-                          LogLevel.error)
-        self.assertEquals(logLevelForNamespace(&quot;twext.web2&quot;),
-                          LogLevel.debug)
-        self.assertEquals(logLevelForNamespace(&quot;twext.web2.dav&quot;),
-                          LogLevel.warn)
-        self.assertEquals(logLevelForNamespace(&quot;twext.web2.dav.test&quot;),
-                          LogLevel.warn)
-        self.assertEquals(logLevelForNamespace(&quot;twext.web2.dav.test1.test2&quot;),
-                          LogLevel.warn)
-
-
-    def test_setInvalidLogLevel(self):
-        &quot;&quot;&quot;
-        Can't pass invalid log levels to setLogLevelForNamespace().
-        &quot;&quot;&quot;
-        self.assertRaises(InvalidLogLevelError, setLogLevelForNamespace,
-                          &quot;twext.web2&quot;, object())
-
-        # Level must be a constant, not the name of a constant
-        self.assertRaises(InvalidLogLevelError, setLogLevelForNamespace,
-                          &quot;twext.web2&quot;, &quot;debug&quot;)
-
-
-    def test_clearLogLevels(self):
-        &quot;&quot;&quot;
-        Clearing log levels.
-        &quot;&quot;&quot;
-        setLogLevelForNamespace(&quot;twext.web2&quot;, LogLevel.debug)
-        setLogLevelForNamespace(&quot;twext.web2.dav&quot;, LogLevel.error)
-
-        clearLogLevels()
-
-        self.assertEquals(logLevelForNamespace(&quot;twisted&quot;), defaultLogLevel)
-        self.assertEquals(logLevelForNamespace(&quot;twext.web2&quot;), defaultLogLevel)
-        self.assertEquals(logLevelForNamespace(&quot;twext.web2.dav&quot;),
-                          defaultLogLevel)
-        self.assertEquals(logLevelForNamespace(&quot;twext.web2.dav.test&quot;),
-                          defaultLogLevel)
-        self.assertEquals(logLevelForNamespace(&quot;twext.web2.dav.test1.test2&quot;),
-                          defaultLogLevel)
-
-
-    def test_namespace_default(self):
-        &quot;&quot;&quot;
-        Default namespace is module name.
-        &quot;&quot;&quot;
-        log = Logger()
-        self.assertEquals(log.namespace, __name__)
-
-
-    def test_formatWithCall(self):
-        &quot;&quot;&quot;
-        L{formatWithCall} is an extended version of L{unicode.format} that will
-        interpret a set of parentheses &quot;C{()}&quot; at the end of a format key to
-        mean that the format key ought to be I{called} rather than stringified.
-        &quot;&quot;&quot;
-        self.assertEquals(
-            formatWithCall(
-                u&quot;Hello, {world}. {callme()}.&quot;,
-                dict(world=&quot;earth&quot;, callme=lambda: &quot;maybe&quot;)
-            ),
-            &quot;Hello, earth. maybe.&quot;
-        )
-        self.assertEquals(
-            formatWithCall(
-                u&quot;Hello, {repr()!r}.&quot;,
-                dict(repr=lambda: &quot;repr&quot;)
-            ),
-            &quot;Hello, 'repr'.&quot;
-        )
-
-
-    def test_formatEvent(self):
-        &quot;&quot;&quot;
-        L{formatEvent} will format an event according to several rules:
-
-            - A string with no formatting instructions will be passed straight
-              through.
-
-            - PEP 3101 strings will be formatted using the keys and values of
-              the event as named fields.
-
-            - PEP 3101 keys ending with C{()} will be treated as instructions
-              to call that key (which ought to be a callable) before
-              formatting.
-
-        L{formatEvent} will always return L{unicode}, and if given
-        bytes, will always treat its format string as UTF-8 encoded.
-        &quot;&quot;&quot;
-        def format(log_format, **event):
-            event[&quot;log_format&quot;] = log_format
-            result = formatEvent(event)
-            self.assertIdentical(type(result), unicode)
-            return result
-
-        self.assertEquals(u&quot;&quot;, format(b&quot;&quot;))
-        self.assertEquals(u&quot;&quot;, format(u&quot;&quot;))
-        self.assertEquals(u&quot;abc&quot;, format(&quot;{x}&quot;, x=&quot;abc&quot;))
-        self.assertEquals(u&quot;no, yes.&quot;,
-                          format(&quot;{not_called}, {called()}.&quot;,
-                                 not_called=&quot;no&quot;, called=lambda: &quot;yes&quot;))
-        self.assertEquals(u'S\xe1nchez', format(&quot;S\xc3\xa1nchez&quot;))
-        self.assertIn(u&quot;Unable to format event&quot;, format(b&quot;S\xe1nchez&quot;))
-        self.assertIn(u&quot;Unable to format event&quot;,
-                      format(b&quot;S{a}nchez&quot;, a=b&quot;\xe1&quot;))
-        self.assertIn(u&quot;S'\\xe1'nchez&quot;,
-                      format(b&quot;S{a!r}nchez&quot;, a=b&quot;\xe1&quot;))
-
-
-    def test_formatEventNoFormat(self):
-        &quot;&quot;&quot;
-        Formatting an event with no format.
-        &quot;&quot;&quot;
-        event = dict(foo=1, bar=2)
-        result = formatEvent(event)
-
-        self.assertIn(&quot;Unable to format event&quot;, result)
-        self.assertIn(repr(event), result)
-
-
-    def test_formatEventWeirdFormat(self):
-        &quot;&quot;&quot;
-        Formatting an event with a bogus format.
-        &quot;&quot;&quot;
-        event = dict(log_format=object(), foo=1, bar=2)
-        result = formatEvent(event)
-
-        self.assertIn(&quot;Log format must be unicode or bytes&quot;, result)
-        self.assertIn(repr(event), result)
-
-
-    def test_formatUnformattableEvent(self):
-        &quot;&quot;&quot;
-        Formatting an event that's just plain out to get us.
-        &quot;&quot;&quot;
-        event = dict(log_format=&quot;{evil()}&quot;, evil=lambda: 1 / 0)
-        result = formatEvent(event)
-
-        self.assertIn(&quot;Unable to format event&quot;, result)
-        self.assertIn(repr(event), result)
-
-
-    def test_formatUnformattableEventWithUnformattableKey(self):
-        &quot;&quot;&quot;
-        Formatting an unformattable event that has an unformattable key.
-        &quot;&quot;&quot;
-        event = {
-            &quot;log_format&quot;: &quot;{evil()}&quot;,
-            &quot;evil&quot;: lambda: 1 / 0,
-            Unformattable(): &quot;gurk&quot;,
-        }
-        result = formatEvent(event)
-        self.assertIn(&quot;MESSAGE LOST: unformattable object logged:&quot;, result)
-        self.assertIn(&quot;Recoverable data:&quot;, result)
-        self.assertIn(&quot;Exception during formatting:&quot;, result)
-
-
-    def test_formatUnformattableEventWithUnformattableValue(self):
-        &quot;&quot;&quot;
-        Formatting an unformattable event that has an unformattable value.
-        &quot;&quot;&quot;
-        event = dict(
-            log_format=&quot;{evil()}&quot;,
-            evil=lambda: 1 / 0,
-            gurk=Unformattable(),
-        )
-        result = formatEvent(event)
-        self.assertIn(&quot;MESSAGE LOST: unformattable object logged:&quot;, result)
-        self.assertIn(&quot;Recoverable data:&quot;, result)
-        self.assertIn(&quot;Exception during formatting:&quot;, result)
-
-
-    def test_formatUnformattableEventWithUnformattableErrorOMGWillItStop(self):
-        &quot;&quot;&quot;
-        Formatting an unformattable event that has an unformattable value.
-        &quot;&quot;&quot;
-        event = dict(
-            log_format=&quot;{evil()}&quot;,
-            evil=lambda: 1 / 0,
-            recoverable=&quot;okay&quot;,
-        )
-        # Call formatUnformattableEvent() directly with a bogus exception.
-        result = formatUnformattableEvent(event, Unformattable())
-        self.assertIn(&quot;MESSAGE LOST: unformattable object logged:&quot;, result)
-        self.assertIn(repr(&quot;recoverable&quot;) + &quot; = &quot; + repr(&quot;okay&quot;), result)
-
-
-
-class LoggerTests(SetUpTearDown, unittest.TestCase):
-    &quot;&quot;&quot;
-    Tests for L{Logger}.
-    &quot;&quot;&quot;
-
-    def test_repr(self):
-        &quot;&quot;&quot;
-        repr() on Logger
-        &quot;&quot;&quot;
-        namespace = &quot;bleargh&quot;
-        log = Logger(namespace)
-        self.assertEquals(repr(log), &quot;&lt;Logger {0}&gt;&quot;.format(repr(namespace)))
-
-
-    def test_namespace_attribute(self):
-        &quot;&quot;&quot;
-        Default namespace for classes using L{Logger} as a descriptor is the
-        class name they were retrieved from.
-        &quot;&quot;&quot;
-        obj = LogComposedObject()
-        self.assertEquals(obj.log.namespace,
-                          &quot;twext.python.test.test_log.LogComposedObject&quot;)
-        self.assertEquals(LogComposedObject.log.namespace,
-                          &quot;twext.python.test.test_log.LogComposedObject&quot;)
-        self.assertIdentical(LogComposedObject.log.source, LogComposedObject)
-        self.assertIdentical(obj.log.source, obj)
-        self.assertIdentical(Logger().source, None)
-
-
-    def test_sourceAvailableForFormatting(self):
-        &quot;&quot;&quot;
-        On instances that have a L{Logger} class attribute, the C{log_source}
-        key is available to format strings.
-        &quot;&quot;&quot;
-        obj = LogComposedObject(&quot;hello&quot;)
-        log = obj.log
-        log.error(&quot;Hello, {log_source}.&quot;)
-
-        self.assertIn(&quot;log_source&quot;, log.event)
-        self.assertEquals(log.event[&quot;log_source&quot;], obj)
-
-        stuff = formatEvent(log.event)
-        self.assertIn(&quot;Hello, &lt;LogComposedObject hello&gt;.&quot;, stuff)
-
-
-    def test_basic_Logger(self):
-        &quot;&quot;&quot;
-        Test that log levels and messages are emitted correctly for
-        Logger.
-        &quot;&quot;&quot;
-        # FIXME: Need a basic test like this for logger attached to a class.
-        # At least: source should not be None in that case.
-
-        log = TestLogger()
-
-        for level in LogLevel.iterconstants():
-            format = &quot;This is a {level_name} message&quot;
-            message = format.format(level_name=level.name)
-
-            method = getattr(log, level.name)
-            method(format, junk=message, level_name=level.name)
-
-            # Ensure that test_emit got called with expected arguments
-            self.assertEquals(log.emitted[&quot;level&quot;], level)
-            self.assertEquals(log.emitted[&quot;format&quot;], format)
-            self.assertEquals(log.emitted[&quot;kwargs&quot;][&quot;junk&quot;], message)
-
-            if level &gt;= logLevelForNamespace(log.namespace):
-                self.assertTrue(hasattr(log, &quot;event&quot;), &quot;No event observed.&quot;)
-                self.assertEquals(log.event[&quot;log_format&quot;], format)
-                self.assertEquals(log.event[&quot;log_level&quot;], level)
-                self.assertEquals(log.event[&quot;log_namespace&quot;], __name__)
-                self.assertEquals(log.event[&quot;log_source&quot;], None)
-
-                self.assertEquals(log.event[&quot;logLevel&quot;],
-                                  pythonLogLevelMapping[level])
-
-                self.assertEquals(log.event[&quot;junk&quot;], message)
-
-                # FIXME: this checks the end of message because we do
-                # formatting in emit()
-                self.assertEquals(
-                    formatEvent(log.event),
-                    message
-                )
-            else:
-                self.assertFalse(hasattr(log, &quot;event&quot;))
-
-
-    def test_defaultFailure(self):
-        &quot;&quot;&quot;
-        Test that log.failure() emits the right data.
-        &quot;&quot;&quot;
-        log = TestLogger()
-        try:
-            raise RuntimeError(&quot;baloney!&quot;)
-        except RuntimeError:
-            log.failure(&quot;Whoops&quot;)
-
-        #
-        # log.failure() will cause trial to complain, so here we check that
-        # trial saw the correct error and remove it from the list of things to
-        # complain about.
-        #
-        errors = self.flushLoggedErrors(RuntimeError)
-        self.assertEquals(len(errors), 1)
-
-        self.assertEquals(log.emitted[&quot;level&quot;], LogLevel.error)
-        self.assertEquals(log.emitted[&quot;format&quot;], &quot;Whoops&quot;)
-
-
-    def test_conflicting_kwargs(self):
-        &quot;&quot;&quot;
-        Make sure that kwargs conflicting with args don't pass through.
-        &quot;&quot;&quot;
-        log = TestLogger()
-
-        log.warn(
-            &quot;*&quot;,
-            log_format=&quot;#&quot;,
-            log_level=LogLevel.error,
-            log_namespace=&quot;*namespace*&quot;,
-            log_source=&quot;*source*&quot;,
-        )
-
-        # FIXME: Should conflicts log errors?
-
-        self.assertEquals(log.event[&quot;log_format&quot;], &quot;*&quot;)
-        self.assertEquals(log.event[&quot;log_level&quot;], LogLevel.warn)
-        self.assertEquals(log.event[&quot;log_namespace&quot;], log.namespace)
-        self.assertEquals(log.event[&quot;log_source&quot;], None)
-
-
-    def test_logInvalidLogLevel(self):
-        &quot;&quot;&quot;
-        Test passing in a bogus log level to C{emit()}.
-        &quot;&quot;&quot;
-        log = TestLogger()
-
-        log.emit(&quot;*bogus*&quot;)
-
-        errors = self.flushLoggedErrors(InvalidLogLevelError)
-        self.assertEquals(len(errors), 1)
-
-
-
-class LogPublisherTests(SetUpTearDown, unittest.TestCase):
-    &quot;&quot;&quot;
-    Tests for L{LogPublisher}.
-    &quot;&quot;&quot;
-
-    def test_interface(self):
-        &quot;&quot;&quot;
-        L{LogPublisher} is an L{ILogObserver}.
-        &quot;&quot;&quot;
-        publisher = LogPublisher()
-        try:
-            verifyObject(ILogObserver, publisher)
-        except BrokenMethodImplementation as e:
-            self.fail(e)
-
-
-    def test_observers(self):
-        &quot;&quot;&quot;
-        L{LogPublisher.observers} returns the observers.
-        &quot;&quot;&quot;
-        o1 = lambda e: None
-        o2 = lambda e: None
-
-        publisher = LogPublisher(o1, o2)
-        self.assertEquals(set((o1, o2)), set(publisher.observers))
-
-
-    def test_addObserver(self):
-        &quot;&quot;&quot;
-        L{LogPublisher.addObserver} adds an observer.
-        &quot;&quot;&quot;
-        o1 = lambda e: None
-        o2 = lambda e: None
-        o3 = lambda e: None
-
-        publisher = LogPublisher(o1, o2)
-        publisher.addObserver(o3)
-        self.assertEquals(set((o1, o2, o3)), set(publisher.observers))
-
-
-    def test_removeObserver(self):
-        &quot;&quot;&quot;
-        L{LogPublisher.removeObserver} removes an observer.
-        &quot;&quot;&quot;
-        o1 = lambda e: None
-        o2 = lambda e: None
-        o3 = lambda e: None
-
-        publisher = LogPublisher(o1, o2, o3)
-        publisher.removeObserver(o2)
-        self.assertEquals(set((o1, o3)), set(publisher.observers))
-
-
-    def test_removeObserverNotRegistered(self):
-        &quot;&quot;&quot;
-        L{LogPublisher.removeObserver} removes an observer that is not
-        registered.
-        &quot;&quot;&quot;
-        o1 = lambda e: None
-        o2 = lambda e: None
-        o3 = lambda e: None
-
-        publisher = LogPublisher(o1, o2)
-        publisher.removeObserver(o3)
-        self.assertEquals(set((o1, o2)), set(publisher.observers))
-
-
-    def test_fanOut(self):
-        &quot;&quot;&quot;
-        L{LogPublisher} calls its observers.
-        &quot;&quot;&quot;
-        event = dict(foo=1, bar=2)
-
-        events1 = []
-        events2 = []
-        events3 = []
-
-        o1 = lambda e: events1.append(e)
-        o2 = lambda e: events2.append(e)
-        o3 = lambda e: events3.append(e)
-
-        publisher = LogPublisher(o1, o2, o3)
-        publisher(event)
-        self.assertIn(event, events1)
-        self.assertIn(event, events2)
-        self.assertIn(event, events3)
-
-
-    def test_observerRaises(self):
-        nonTestEvents = []
-        Logger.publisher.addObserver(lambda e: nonTestEvents.append(e))
-
-        event = dict(foo=1, bar=2)
-        exception = RuntimeError(&quot;ARGH! EVIL DEATH!&quot;)
-
-        events = []
-
-        def observer(event):
-            events.append(event)
-            raise exception
-
-        publisher = LogPublisher(observer)
-        publisher(event)
-
-        # Verify that the observer saw my event
-        self.assertIn(event, events)
-
-        # Verify that the observer raised my exception
-        errors = self.flushLoggedErrors(exception.__class__)
-        self.assertEquals(len(errors), 1)
-        self.assertIdentical(errors[0].value, exception)
-
-        # Verify that the exception was logged
-        for event in nonTestEvents:
-            if (
-                event.get(&quot;log_format&quot;, None) == OBSERVER_REMOVED and
-                getattr(event.get(&quot;failure&quot;, None), &quot;value&quot;) is exception
-            ):
-                break
-        else:
-            self.fail(&quot;Observer raised an exception &quot;
-                      &quot;and the exception was not logged.&quot;)
-
-
-    def test_observerRaisesAndLoggerHatesMe(self):
-        nonTestEvents = []
-        Logger.publisher.addObserver(lambda e: nonTestEvents.append(e))
-
-        event = dict(foo=1, bar=2)
-        exception = RuntimeError(&quot;ARGH! EVIL DEATH!&quot;)
-
-        def observer(event):
-            raise RuntimeError(&quot;Sad panda&quot;)
-
-        class GurkLogger(Logger):
-            def failure(self, *args, **kwargs):
-                raise exception
-
-        publisher = LogPublisher(observer)
-        publisher.log = GurkLogger()
-        publisher(event)
-
-        # Here, the lack of an exception thus far is a success, of sorts
-
-
-
-class DefaultLogPublisherTests(SetUpTearDown, unittest.TestCase):
-    def test_addObserver(self):
-        o1 = lambda e: None
-        o2 = lambda e: None
-        o3 = lambda e: None
-
-        publisher = DefaultLogPublisher()
-        publisher.addObserver(o1)
-        publisher.addObserver(o2, filtered=True)
-        publisher.addObserver(o3, filtered=False)
-
-        self.assertEquals(
-            set((o1, o2, publisher.legacyLogObserver)),
-            set(publisher.filteredPublisher.observers),
-            &quot;Filtered observers do not match expected set&quot;
-        )
-        self.assertEquals(
-            set((o3, publisher.filters)),
-            set(publisher.rootPublisher.observers),
-            &quot;Root observers do not match expected set&quot;
-        )
-
-
-    def test_addObserverAgain(self):
-        o1 = lambda e: None
-        o2 = lambda e: None
-        o3 = lambda e: None
-
-        publisher = DefaultLogPublisher()
-        publisher.addObserver(o1)
-        publisher.addObserver(o2, filtered=True)
-        publisher.addObserver(o3, filtered=False)
-
-        # Swap filtered-ness of o2 and o3
-        publisher.addObserver(o1)
-        publisher.addObserver(o2, filtered=False)
-        publisher.addObserver(o3, filtered=True)
-
-        self.assertEquals(
-            set((o1, o3, publisher.legacyLogObserver)),
-            set(publisher.filteredPublisher.observers),
-            &quot;Filtered observers do not match expected set&quot;
-        )
-        self.assertEquals(
-            set((o2, publisher.filters)),
-            set(publisher.rootPublisher.observers),
-            &quot;Root observers do not match expected set&quot;
-        )
-
-
-    def test_removeObserver(self):
-        o1 = lambda e: None
-        o2 = lambda e: None
-        o3 = lambda e: None
-
-        publisher = DefaultLogPublisher()
-        publisher.addObserver(o1)
-        publisher.addObserver(o2, filtered=True)
-        publisher.addObserver(o3, filtered=False)
-        publisher.removeObserver(o2)
-        publisher.removeObserver(o3)
-
-        self.assertEquals(
-            set((o1, publisher.legacyLogObserver)),
-            set(publisher.filteredPublisher.observers),
-            &quot;Filtered observers do not match expected set&quot;
-        )
-        self.assertEquals(
-            set((publisher.filters,)),
-            set(publisher.rootPublisher.observers),
-            &quot;Root observers do not match expected set&quot;
-        )
-
-
-    def test_filteredObserver(self):
-        namespace = __name__
-
-        event_debug = dict(log_namespace=namespace,
-                           log_level=LogLevel.debug, log_format=&quot;&quot;)
-        event_error = dict(log_namespace=namespace,
-                           log_level=LogLevel.error, log_format=&quot;&quot;)
-        events = []
-
-        observer = lambda e: events.append(e)
-
-        publisher = DefaultLogPublisher()
-
-        publisher.addObserver(observer, filtered=True)
-        publisher(event_debug)
-        publisher(event_error)
-        self.assertNotIn(event_debug, events)
-        self.assertIn(event_error, events)
-
-
-    def test_filteredObserverNoFilteringKeys(self):
-        event_debug = dict(log_level=LogLevel.debug)
-        event_error = dict(log_level=LogLevel.error)
-        event_none = dict()
-        events = []
-
-        observer = lambda e: events.append(e)
-
-        publisher = DefaultLogPublisher()
-        publisher.addObserver(observer, filtered=True)
-        publisher(event_debug)
-        publisher(event_error)
-        publisher(event_none)
-        self.assertNotIn(event_debug, events)
-        self.assertNotIn(event_error, events)
-        self.assertNotIn(event_none, events)
-
-
-    def test_unfilteredObserver(self):
-        namespace = __name__
-
-        event_debug = dict(log_namespace=namespace, log_level=LogLevel.debug,
-                           log_format=&quot;&quot;)
-        event_error = dict(log_namespace=namespace, log_level=LogLevel.error,
-                           log_format=&quot;&quot;)
-        events = []
-
-        observer = lambda e: events.append(e)
-
-        publisher = DefaultLogPublisher()
-
-        publisher.addObserver(observer, filtered=False)
-        publisher(event_debug)
-        publisher(event_error)
-        self.assertIn(event_debug, events)
-        self.assertIn(event_error, events)
-
-
-
-class FilteringLogObserverTests(SetUpTearDown, unittest.TestCase):
-    &quot;&quot;&quot;
-    Tests for L{FilteringLogObserver}.
-    &quot;&quot;&quot;
-
-    def test_interface(self):
-        &quot;&quot;&quot;
-        L{FilteringLogObserver} is an L{ILogObserver}.
-        &quot;&quot;&quot;
-        observer = FilteringLogObserver(lambda e: None, ())
-        try:
-            verifyObject(ILogObserver, observer)
-        except BrokenMethodImplementation as e:
-            self.fail(e)
-
-
-    def filterWith(self, *filters):
-        events = [
-            dict(count=0),
-            dict(count=1),
-            dict(count=2),
-            dict(count=3),
-        ]
-
-        class Filters(object):
-            @staticmethod
-            def twoMinus(event):
-                if event[&quot;count&quot;] &lt;= 2:
-                    return PredicateResult.yes
-                return PredicateResult.maybe
-
-            @staticmethod
-            def twoPlus(event):
-                if event[&quot;count&quot;] &gt;= 2:
-                    return PredicateResult.yes
-                return PredicateResult.maybe
-
-            @staticmethod
-            def notTwo(event):
-                if event[&quot;count&quot;] == 2:
-                    return PredicateResult.no
-                return PredicateResult.maybe
-
-            @staticmethod
-            def no(event):
-                return PredicateResult.no
-
-            @staticmethod
-            def bogus(event):
-                return None
-
-        predicates = (getattr(Filters, f) for f in filters)
-        eventsSeen = []
-        trackingObserver = lambda e: eventsSeen.append(e)
-        filteringObserver = FilteringLogObserver(trackingObserver, predicates)
-        for e in events:
-            filteringObserver(e)
-
-        return [e[&quot;count&quot;] for e in eventsSeen]
-
-
-    def test_shouldLogEvent_noFilters(self):
-        self.assertEquals(self.filterWith(), [0, 1, 2, 3])
-
-
-    def test_shouldLogEvent_noFilter(self):
-        self.assertEquals(self.filterWith(&quot;notTwo&quot;), [0, 1, 3])
-
-
-    def test_shouldLogEvent_yesFilter(self):
-        self.assertEquals(self.filterWith(&quot;twoPlus&quot;), [0, 1, 2, 3])
-
-
-    def test_shouldLogEvent_yesNoFilter(self):
-        self.assertEquals(self.filterWith(&quot;twoPlus&quot;, &quot;no&quot;), [2, 3])
-
-
-    def test_shouldLogEvent_yesYesNoFilter(self):
-        self.assertEquals(self.filterWith(&quot;twoPlus&quot;, &quot;twoMinus&quot;, &quot;no&quot;),
-                          [0, 1, 2, 3])
-
-
-    def test_shouldLogEvent_badPredicateResult(self):
-        self.assertRaises(TypeError, self.filterWith, &quot;bogus&quot;)
-
-
-    def test_call(self):
-        e = dict(obj=object())
-
-        def callWithPredicateResult(result):
-            seen = []
-            observer = FilteringLogObserver(lambda e: seen.append(e),
-                                            (lambda e: result,))
-            observer(e)
-            return seen
-
-        self.assertIn(e, callWithPredicateResult(PredicateResult.yes))
-        self.assertIn(e, callWithPredicateResult(PredicateResult.maybe))
-        self.assertNotIn(e, callWithPredicateResult(PredicateResult.no))
-
-
-
-class LegacyLoggerTests(SetUpTearDown, unittest.TestCase):
-    &quot;&quot;&quot;
-    Tests for L{LegacyLogger}.
-    &quot;&quot;&quot;
-
-    def test_namespace_default(self):
-        &quot;&quot;&quot;
-        Default namespace is module name.
-        &quot;&quot;&quot;
-        log = TestLegacyLogger(logger=None)
-        self.assertEquals(log.newStyleLogger.namespace, __name__)
-
-
-    def test_passThroughAttributes(self):
-        &quot;&quot;&quot;
-        C{__getattribute__} on L{LegacyLogger} is passing through to Twisted's
-        logging module.
-        &quot;&quot;&quot;
-        log = TestLegacyLogger()
-
-        # Not passed through
-        self.assertIn(&quot;API-compatible&quot;, log.msg.__doc__)
-        self.assertIn(&quot;API-compatible&quot;, log.err.__doc__)
-
-        # Passed through
-        self.assertIdentical(log.addObserver, twistedLogging.addObserver)
-
-
-    def test_legacy_msg(self):
-        &quot;&quot;&quot;
-        Test LegacyLogger's log.msg()
-        &quot;&quot;&quot;
-        log = TestLegacyLogger()
-
-        message = &quot;Hi, there.&quot;
-        kwargs = {&quot;foo&quot;: &quot;bar&quot;, &quot;obj&quot;: object()}
-
-        log.msg(message, **kwargs)
-
-        self.assertIdentical(log.newStyleLogger.emitted[&quot;level&quot;],
-                             LogLevel.info)
-        self.assertEquals(log.newStyleLogger.emitted[&quot;format&quot;], message)
-
-        for key, value in kwargs.items():
-            self.assertIdentical(log.newStyleLogger.emitted[&quot;kwargs&quot;][key],
-                                 value)
-
-        log.msg(foo=&quot;&quot;)
-
-        self.assertIdentical(log.newStyleLogger.emitted[&quot;level&quot;],
-                             LogLevel.info)
-        self.assertIdentical(log.newStyleLogger.emitted[&quot;format&quot;], None)
-
-
-    def test_legacy_err_implicit(self):
-        &quot;&quot;&quot;
-        Test LegacyLogger's log.err() capturing the in-flight exception.
-        &quot;&quot;&quot;
-        log = TestLegacyLogger()
-
-        exception = RuntimeError(&quot;Oh me, oh my.&quot;)
-        kwargs = {&quot;foo&quot;: &quot;bar&quot;, &quot;obj&quot;: object()}
-
-        try:
-            raise exception
-        except RuntimeError:
-            log.err(**kwargs)
-
-        self.legacy_err(log, kwargs, None, exception)
-
-
-    def test_legacy_err_exception(self):
-        &quot;&quot;&quot;
-        Test LegacyLogger's log.err() with a given exception.
-        &quot;&quot;&quot;
-        log = TestLegacyLogger()
-
-        exception = RuntimeError(&quot;Oh me, oh my.&quot;)
-        kwargs = {&quot;foo&quot;: &quot;bar&quot;, &quot;obj&quot;: object()}
-        why = &quot;Because I said so.&quot;
-
-        try:
-            raise exception
-        except RuntimeError as e:
-            log.err(e, why, **kwargs)
-
-        self.legacy_err(log, kwargs, why, exception)
-
-
-    def test_legacy_err_failure(self):
-        &quot;&quot;&quot;
-        Test LegacyLogger's log.err() with a given L{Failure}.
-        &quot;&quot;&quot;
-        log = TestLegacyLogger()
-
-        exception = RuntimeError(&quot;Oh me, oh my.&quot;)
-        kwargs = {&quot;foo&quot;: &quot;bar&quot;, &quot;obj&quot;: object()}
-        why = &quot;Because I said so.&quot;
-
-        try:
-            raise exception
-        except RuntimeError:
-            log.err(Failure(), why, **kwargs)
-
-        self.legacy_err(log, kwargs, why, exception)
-
-
-    def test_legacy_err_bogus(self):
-        &quot;&quot;&quot;
-        Test LegacyLogger's log.err() with a bogus argument.
-        &quot;&quot;&quot;
-        log = TestLegacyLogger()
-
-        exception = RuntimeError(&quot;Oh me, oh my.&quot;)
-        kwargs = {&quot;foo&quot;: &quot;bar&quot;, &quot;obj&quot;: object()}
-        why = &quot;Because I said so.&quot;
-        bogus = object()
-
-        try:
-            raise exception
-        except RuntimeError:
-            log.err(bogus, why, **kwargs)
-
-        errors = self.flushLoggedErrors(exception.__class__)
-        self.assertEquals(len(errors), 0)
-
-        self.assertIdentical(log.newStyleLogger.emitted[&quot;level&quot;],
-                             LogLevel.error)
-        self.assertEquals(log.newStyleLogger.emitted[&quot;format&quot;], repr(bogus))
-        self.assertIdentical(log.newStyleLogger.emitted[&quot;kwargs&quot;][&quot;why&quot;], why)
-
-        for key, value in kwargs.items():
-            self.assertIdentical(log.newStyleLogger.emitted[&quot;kwargs&quot;][key],
-                                 value)
-
-
-    def legacy_err(self, log, kwargs, why, exception):
-        #
-        # log.failure() will cause trial to complain, so here we check that
-        # trial saw the correct error and remove it from the list of things to
-        # complain about.
-        #
-        errors = self.flushLoggedErrors(exception.__class__)
-        self.assertEquals(len(errors), 1)
-
-        self.assertIdentical(log.newStyleLogger.emitted[&quot;level&quot;],
-                             LogLevel.error)
-        self.assertEquals(log.newStyleLogger.emitted[&quot;format&quot;], None)
-        emittedKwargs = log.newStyleLogger.emitted[&quot;kwargs&quot;]
-        self.assertIdentical(emittedKwargs[&quot;failure&quot;].__class__, Failure)
-        self.assertIdentical(emittedKwargs[&quot;failure&quot;].value, exception)
-        self.assertIdentical(emittedKwargs[&quot;why&quot;], why)
-
-        for key, value in kwargs.items():
-            self.assertIdentical(log.newStyleLogger.emitted[&quot;kwargs&quot;][key],
-                                 value)
-
-
-
-class Unformattable(object):
-    &quot;&quot;&quot;
-    An object that raises an exception from C{__repr__}.
-    &quot;&quot;&quot;
-
-    def __repr__(self):
-        return str(1 / 0)
</del></span></pre></div>
<a id="twexttrunktwextwholdap_servicepy"></a>
<div class="modfile"><h4>Modified: twext/trunk/twext/who/ldap/_service.py (14846 => 14847)</h4>
<pre class="diff"><span>
<span class="info">--- twext/trunk/twext/who/ldap/_service.py        2015-05-28 21:41:18 UTC (rev 14846)
+++ twext/trunk/twext/who/ldap/_service.py        2015-05-28 21:49:02 UTC (rev 14847)
</span><span class="lines">@@ -29,13 +29,13 @@
</span><span class="cx"> import ldap.async
</span><span class="cx"> 
</span><span class="cx"> from twisted.python.constants import Names, NamedConstant
</span><ins>+from twisted.python.threadpool import ThreadPool
+from twisted.logger import Logger
+from twisted.internet import reactor
</ins><span class="cx"> from twisted.internet.defer import succeed, inlineCallbacks, returnValue
</span><span class="cx"> from twisted.internet.threads import deferToThreadPool
</span><span class="cx"> from twisted.cred.credentials import IUsernamePassword
</span><del>-from twisted.python.threadpool import ThreadPool
-from twisted.internet import reactor
</del><span class="cx"> 
</span><del>-from twext.python.log import Logger
</del><span class="cx"> from twext.python.types import MappingProxyType
</span><span class="cx"> 
</span><span class="cx"> from ..idirectory import (
</span></span></pre></div>
<a id="twexttrunktwextwhoopendirectory_servicepy"></a>
<div class="modfile"><h4>Modified: twext/trunk/twext/who/opendirectory/_service.py (14846 => 14847)</h4>
<pre class="diff"><span>
<span class="info">--- twext/trunk/twext/who/opendirectory/_service.py        2015-05-28 21:41:18 UTC (rev 14846)
+++ twext/trunk/twext/who/opendirectory/_service.py        2015-05-28 21:49:02 UTC (rev 14847)
</span><span class="lines">@@ -25,12 +25,11 @@
</span><span class="cx"> from uuid import UUID
</span><span class="cx"> from zope.interface import implementer
</span><span class="cx"> 
</span><ins>+from twisted.logger import Logger
</ins><span class="cx"> from twisted.internet.defer import succeed, fail, inlineCallbacks, returnValue
</span><span class="cx"> from twisted.internet.threads import deferToThread
</span><span class="cx"> from twisted.web.guard import DigestCredentialFactory
</span><span class="cx"> 
</span><del>-from twext.python.log import Logger
-
</del><span class="cx"> from ..idirectory import (
</span><span class="cx">     DirectoryServiceError, DirectoryAvailabilityError,
</span><span class="cx">     InvalidDirectoryRecordError, QueryNotSupportedError,
</span></span></pre>
</div>
</div>

</body>
</html>