[Zope-Checkins] CVS: Zope3/lib/python/Zope/Server - Adjustments.py:1.1.2.4.2.5 DualModeChannel.py:1.1.2.4.2.6 ServerBase.py:1.1.2.4.2.4 ServerChannelBase.py:1.1.2.7

Shane Hathaway shane@cvs.zope.org
Wed, 10 Apr 2002 17:59:51 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/Server
In directory cvs.zope.org:/tmp/cvs-serv18340

Modified Files:
      Tag: Zope3-Server-Branch
	Adjustments.py DualModeChannel.py ServerBase.py 
	ServerChannelBase.py 
Log Message:
- Removed AlternateSocketMapMixin.  It was there to support multiple socket
maps, but if we really need multiple socket maps, it would be better to
change asyncore.  Had to update a lot of __init__ methods.

- Added IUsernamePassword and IFilesystemAccess, which provide a way to
implement all kinds of authentication schemes without FTP knowing about
any of the details.  Modified FTPServerChannel to work based on an
IFilesystemAccess object.

- Added detection of the ZOPE_SERVER_DEBUG env var.

- Added comments here and there.

- Fixed CRs :-)


=== Zope3/lib/python/Zope/Server/Adjustments.py 1.1.2.4.2.4 => 1.1.2.4.2.5 ===
 
 class Adjustments:
+    """This class contains tunable communication parameters.
+
+    You can either change default_adj to adjust parameters for
+    all sockets, or you can create a new instance of this class,
+    change its attributes, and pass it to the channel constructors.
+    """
 
     # backlog is the argument to pass to socket.listen().
     backlog = 1024


=== Zope3/lib/python/Zope/Server/DualModeChannel.py 1.1.2.4.2.5 => 1.1.2.4.2.6 ===
 
 
-class AlternateSocketMapMixin:
-    """Mixin for asyncore.dispatcher to more easily support
-    alternate socket maps"""
-
-    socket_map = None
-
-    def add_channel(self, map=None):
-        if map is None:
-            map = self.socket_map
-        asyncore.dispatcher.add_channel(self, map)
-
-    def del_channel(self, map=None):
-        if map is None:
-            map = self.socket_map
-        asyncore.dispatcher.del_channel(self, map)
 
-    def pull_trigger(self):
-        pull_trigger = getattr(self.socket_map, 'pull_trigger', None)
-        if pull_trigger is not None:
-            # Use the trigger from the socket map.
-            pull_trigger()
-        else:
-            SelectTrigger.the_trigger.pull_trigger()
-
-
-class ASMTrigger(AlternateSocketMapMixin, SelectTrigger.Trigger):
-    """Trigger for an alternate socket map"""
-
-    def __init__(self, socket_map):
-        self.socket_map = socket_map
-        select_trigger.trigger.__init__(self)
-
-    pull_trigger = SelectTrigger.Trigger.pull_trigger
-
-
-class SocketMapWithTrigger(UserDict):
-
-    def __init__(self):
-        UserDict.__init__(self)
-        self.pull_trigger = ASMTrigger(self).pull_trigger
+class DualModeChannel(asyncore.dispatcher):
+    """Channel that switches between asynchronous and synchronous mode.
 
+    Call set_sync() before using a channel in a thread other than
+    the thread handling the main loop.
 
-class DualModeChannel(AlternateSocketMapMixin, asyncore.dispatcher):
-    """Channel that switches between asynchronous and synchronous mode.
+    Call set_async() to give the channel back to the thread handling
+    the main loop.
     """
 
     __implements__ = asyncore.dispatcher.__implements__
@@ -85,12 +50,11 @@
     # boolean: async or sync mode
     async_mode = 1
 
-    def __init__(self, conn, addr, adj=None, socket_map=None):
+    def __init__(self, conn, addr, adj=None):
         self.addr = addr
         if adj is None:
             adj = default_adj
         self.adj = adj
-        self.socket_map = socket_map
         self.outbuf = OverflowableBuffer(adj.outbuf_overflow)
         self.creation_time = time()
         asyncore.dispatcher.__init__(self, conn)
@@ -209,6 +173,11 @@
     # METHODS USED IN BOTH MODES
     #
 
+    def pull_trigger(self):
+        """Wakes up the main loop.
+        """
+        SelectTrigger.the_trigger.pull_trigger()
+
     def _flush_some(self):
         """Flushes data.
 
@@ -252,7 +221,7 @@
     __implements__ = asyncore.dispatcher.__implements__
 
 
-    def __init__(self, conn, addr, adj=None, socket_map=None):
+    def __init__(self, conn, addr, adj=None):
         global allocate_lock
         if allocate_lock is None:
             from thread import allocate_lock
@@ -263,7 +232,7 @@
         self._writelock_acquire = writelock.acquire
         self._writelock_release = writelock.release
         self._writelock_locked = writelock.locked
-        DualModeChannel.__init__(self, conn, addr, adj, socket_map)
+        DualModeChannel.__init__(self, conn, addr, adj)
 
     #
     # ASYNCHRONOUS METHODS


=== Zope3/lib/python/Zope/Server/ServerBase.py 1.1.2.4.2.3 => 1.1.2.4.2.4 ===
 import socket
 
-from DualModeChannel import AlternateSocketMapMixin
 from Adjustments import default_adj
 
 from IServer import IServer
 
 
-class ServerBase(AlternateSocketMapMixin, asyncore.dispatcher, object):
+class ServerBase(asyncore.dispatcher, object):
     """Async. server base for launching derivatives of ServerChannelBase.
     """
 
@@ -35,11 +34,10 @@
     SERVER_IDENT = 'Zope.Server.ServerBase'  # Override.
 
     def __init__(self, ip, port, task_dispatcher=None, adj=None, start=1,
-                 hit_log=None, verbose=0, socket_map=None):
+                 hit_log=None, verbose=0):
         if adj is None:
             adj = default_adj
         self.adj = adj
-        self.socket_map = socket_map
         asyncore.dispatcher.__init__(self)
         self.port = port
         self.task_dispatcher = task_dispatcher
@@ -133,7 +131,7 @@
                 self.log_info ('warning: server accept() threw an exception',
                                'warning')
             return
-        self.channel_class(self, conn, addr, self.adj, self.socket_map)
+        self.channel_class(self, conn, addr, self.adj)
 
     #
     ############################################################


=== Zope3/lib/python/Zope/Server/ServerChannelBase.py 1.1.2.6 => 1.1.2.7 ===
     #
 
-    def __init__(self, server, conn, addr, adj=None, socket_map=None):
-        ChannelBaseClass.__init__(self, conn, addr, adj, socket_map)
+    def __init__(self, server, conn, addr, adj=None):
+        ChannelBaseClass.__init__(self, conn, addr, adj)
         self.server = server
         self.last_activity = t = self.creation_time
         self.check_maintenance(t)