[Zope3-checkins] CVS: Zope3/src/zope/thread - __init__.py:1.1.2.1 interfaces.py:1.1.2.1

Marius Gedminas marius at pov.lt
Wed Mar 3 12:36:28 EST 2004


Update of /cvs-repository/Zope3/src/zope/thread
In directory cvs.zope.org:/tmp/cvs-serv22235/src/zope/thread

Added Files:
      Tag: mgedmin-events2-branch
	__init__.py interfaces.py 
Log Message:
Added zope.thread -- support for thread globals like site and interaction.



=== Added File Zope3/src/zope/thread/__init__.py ===
"""zope.thread

Implements thread global variables.
"""

import threading
from zope.interface import moduleProvides, implements
from zope.thread.interfaces import IZopeThreadAPI
from zope.thread.interfaces import IInteractionThreadGlobal, ISiteThreadGlobal

__metaclass__ = type

moduleProvides(IZopeThreadAPI)


def thread_globals(thread=None):
    """See IZopeThreadAPI."""
    if thread is None:
        thread = threading.currentThread()
    if not hasattr(thread, '__zope3_thread_globals__'):
        thread.__zope3_thread_globals__ = ThreadGlobals()
    return thread.__zope3_thread_globals__


class ThreadGlobals:
    implements(IInteractionThreadGlobal, ISiteThreadGlobal)

    interaction = None
    site = None



=== Added File Zope3/src/zope/thread/interfaces.py ===
##############################################################################
#
# Copyright (c) 2002 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.
#
##############################################################################
"""Interfaces for zope.thread.

$Id: interfaces.py,v 1.1.2.1 2004/03/03 17:36:27 mgedmin Exp $
"""

from zope.interface import Interface, Attribute


class IZopeThreadAPI(Interface):

    def thread_globals(thread=None):
        """Return the thread globals instance for the given thread.

        If thread is None, returns the globals for the current thread.
        """


class IInteractionThreadGlobal(Interface):

    interaction = Attribute("""IInteraction for the current thread.""")


class ISiteThreadGlobal(Interface):

    site = Attribute("""Site for the current thread.""")




More information about the Zope3-Checkins mailing list