[bridgedb/master] Add a utility for registering interface adapter classes.
commit ab5c6b01c2c0dc461d45899105a0e6892e682ef7 Author: Isis Lovecruft <isis@torproject.org> Date: Mon May 11 02:01:45 2015 +0000 Add a utility for registering interface adapter classes. --- lib/bridgedb/util.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/bridgedb/util.py b/lib/bridgedb/util.py index 7f906d7..f15e08b 100644 --- a/lib/bridgedb/util.py +++ b/lib/bridgedb/util.py @@ -19,6 +19,8 @@ import logging.config import logging.handlers import os +from twisted.python import components + def _getLogHandlers(logToFile=True, logToStderr=True): """Get the appropriate list of log handlers. @@ -245,6 +247,20 @@ def replaceControlChars(text, replacement=None, encoding="utf-8"): return str(escaped) +def registerAdapter(adapter, adapted, interface): + """Register a Zope interface adapter for global use. + + See :api:`twisted.python.components.registerAdapter` and the Twisted + Matrix Labs `howto documentation for components`_. + + .. howto documentation for components: + https://twistedmatrix.com/documents/current/core/howto/components.html + """ + try: + components.registerAdapter(adapter, adapted, interface) + except ValueError: # An adapter class was already registered + pass + class JustifiedLogFormatter(logging.Formatter): """A logging formatter which pretty prints thread and calling function
participants (1)
-
isis@torproject.org