[Zope-Checkins] CVS: Zope/lib/python/ZServer/PubCore - ZEvent.py:1.1.2.1 ZRendezvous.py:1.1.2.1 ZServerPublisher.py:1.1.2.1 __init__.py:1.1.2.1

Chris McDonough chrism@zope.com
Tue, 17 Sep 2002 01:16:06 -0400


Update of /cvs-repository/Zope/lib/python/ZServer/PubCore
In directory cvs.zope.org:/tmp/cvs-serv12650/lib/python/ZServer/PubCore

Added Files:
      Tag: chrism-install-branch
	ZEvent.py ZRendezvous.py ZServerPublisher.py __init__.py 
Log Message:
Moved ZServer into lib/python.


=== Added File Zope/lib/python/ZServer/PubCore/ZEvent.py ===
##############################################################################
#
# Copyright (c) 2001 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
#
##############################################################################

"""Simple Event Manager Based on Pipes
"""

from ZServer.medusa.thread.select_trigger import trigger
from ZServer.medusa.asyncore import socket_map

class simple_trigger(trigger):
    def handle_close(self):
        pass

the_trigger=simple_trigger()

def Wakeup(thunk=None):
    global the_trigger
    try:
        the_trigger.pull_trigger(thunk)
    except OSError, why:
        # this broken pipe as a result of perhaps a signal
        # we want to handle this gracefully so we get rid of the old
        # trigger and install a new one.
        if why[0] == 32:
            del socket_map[the_trigger._fileno]
            the_trigger = simple_trigger() # adds itself back into socket_map
            the_trigger.pull_trigger(thunk)


=== Added File Zope/lib/python/ZServer/PubCore/ZRendezvous.py ===
##############################################################################
#
# Copyright (c) 2001 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
#
##############################################################################

import thread
from ZServerPublisher import ZServerPublisher

class ZRendevous:

    def __init__(self, n=1):
        sync=thread.allocate_lock()
        self._a=sync.acquire
        self._r=sync.release
        pool=[]
        self._lists=pool, [], []
        self._a()
        try:
            while n > 0:
                l=thread.allocate_lock()
                l.acquire()
                pool.append(l)
                thread.start_new_thread(ZServerPublisher,
                                        (self.accept,))
                n=n-1
        finally: self._r()

    def accept(self):
        self._a()
        try:
            pool, requests, ready = self._lists
            while not requests:
                l=pool[-1]
                del pool[-1]
                ready.append(l)
                self._r()
                l.acquire()
                self._a()
                pool.append(l)

            r=requests[0]
            del requests[0]
            return r
        finally: self._r()

    def handle(self, name, request, response):
        self._a()
        try:
            pool, requests, ready = self._lists
            requests.append((name, request, response))
            if ready:
                l=ready[-1]
                del ready[-1]
                l.release()
        finally: self._r()


=== Added File Zope/lib/python/ZServer/PubCore/ZServerPublisher.py ===
##############################################################################
#
# Copyright (c) 2001 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
#
##############################################################################
from ZPublisher import publish_module

class ZServerPublisher:
    def __init__(self, accept):
        while 1:
            try:
                name, request, response=accept()
                publish_module(
                    name,
                    request=request,
                    response=response)
            finally:
                response._finish()
                request=response=None


=== Added File Zope/lib/python/ZServer/PubCore/__init__.py ===
##############################################################################
#
# Copyright (c) 2001 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
#
##############################################################################

import ZRendezvous

_handle=None
_n=1

def handle(*args, **kw):
    global _handle

    if _handle is None: _handle=ZRendezvous.ZRendevous(_n).handle

    return apply(_handle, args, kw)

def setNumberOfThreads(n):
    global _n
    _n=n
    global setNumberOfThreads
    del setNumberOfThreads