[Zope-Checkins] CVS: Zope/lib/python/ZServer - utils.py:1.1 __init__.py:1.30
Chris McDonough
chrism@zope.com
Sat, 19 Jul 2003 16:17:08 -0400
Update of /cvs-repository/Zope/lib/python/ZServer
In directory cvs.zope.org:/tmp/cvs-serv3126
Modified Files:
__init__.py
Added Files:
utils.py
Log Message:
Do a bit of cleanup in __init__ (add explanatory comments, move side-effect functions to a utility module).
=== Added File Zope/lib/python/ZServer/utils.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.
#
##############################################################################
""" A set of utility routines used by asyncore initialization """
def getMaxSockets():
from medusa.test import max_sockets
return max_sockets.max_select_sockets()
def getZopeVersion():
import App.version_txt
App.version_txt.version_txt()
def patchAsyncoreLogger():
# Poke zLOG default logging into asyncore to send
# messages to zLOG instead of medusa logger
from zLOG import LOG, register_subsystem, BLATHER, INFO, WARNING, ERROR
register_subsystem('ZServer')
severity={'info':INFO, 'warning':WARNING, 'error': ERROR}
def log_info(self, message, type='info'):
if message[:14]=='adding channel' or \
message[:15]=='closing channel' or \
message == 'Computing default hostname':
LOG('ZServer', BLATHER, message)
else:
LOG('ZServer', severity[type], message)
import asyncore
asyncore.dispatcher.log_info=log_info
# A routine to try to arrange for request sockets to be closed
# on exec. This makes it easier for folks who spawn long running
# processes from Zope code. Thanks to Dieter Maurer for this.
try:
import fcntl
def requestCloseOnExec(sock):
try:
fcntl.fcntl(sock.fileno(), fcntl.F_SETFD, fcntl.FD_CLOEXEC)
except: # XXX What was this supposed to catch?
pass
except (ImportError, AttributeError):
def requestCloseOnExec(sock):
pass
def patchSyslogServiceName():
from medusa import logger
# override the service name in logger.syslog_logger
logger.syslog_logger.svc_name='ZServer'
=== Zope/lib/python/ZServer/__init__.py 1.29 => 1.30 ===
--- Zope/lib/python/ZServer/__init__.py:1.29 Tue Mar 18 16:15:14 2003
+++ Zope/lib/python/ZServer/__init__.py Sat Jul 19 16:17:01 2003
@@ -12,59 +12,25 @@
##############################################################################
import sys
+import utils
-from medusa.test import max_sockets
-CONNECTION_LIMIT=max_sockets.max_select_sockets()
-
-ZSERVER_VERSION='1.1'
-try:
- import App.version_txt
- ZOPE_VERSION=App.version_txt.version_txt()
-except:
- ZOPE_VERSION='experimental'
+#########################################################
+### declarations used by external packages
+# the exit code used to exit a Zope process cleanly
exit_code = 0
-# Try to poke zLOG default logging into asyncore
-# XXX We should probably should do a better job of this,
-# however that would mean that ZServer required zLOG.
-# (Is that really a bad thing?)
-try:
- from zLOG import LOG, register_subsystem, BLATHER, INFO, WARNING, ERROR
-except ImportError:
- pass
-else:
- register_subsystem('ZServer')
- severity={'info':INFO, 'warning':WARNING, 'error': ERROR}
-
- def log_info(self, message, type='info'):
- if message[:14]=='adding channel' or \
- message[:15]=='closing channel' or \
- message == 'Computing default hostname':
- LOG('ZServer', BLATHER, message)
- else:
- LOG('ZServer', severity[type], message)
-
- import asyncore
- asyncore.dispatcher.log_info=log_info
-
-# A routine to try to arrange for request sockets to be closed
-# on exec. This makes it easier for folks who spawn long running
-# processes from Zope code. Thanks to Dieter Maurer for this.
-try:
- import fcntl
-
- def requestCloseOnExec(sock):
- try:
- fcntl.fcntl(sock.fileno(), fcntl.F_SETFD, fcntl.FD_CLOEXEC)
- except: # XXX What was this supposed to catch?
- pass
+# the ZServer version number
+ZSERVER_VERSION='1.1'
-except (ImportError, AttributeError):
+# the maximum number of incoming connections to ZServer
+CONNECTION_LIMIT=utils.getMaxSockets()
- def requestCloseOnExec(sock):
- pass
+# the Zope version string
+ZOPE_VERSION=utils.getZopeVersion()
+# backwards compatibility aliases
+from utils import requestCloseOnExec
import asyncore
from medusa import resolver, logger
from HTTPServer import zhttp_server, zhttp_handler
@@ -74,5 +40,14 @@
from PubCore import setNumberOfThreads
from medusa.monitor import secure_monitor_server
-# override the service name in logger.syslog_logger
-logger.syslog_logger.svc_name='ZServer'
+### end declarations
+##########################################################
+
+# we need to patch asyncore's dispatcher class with a new
+# log_info method so we see medusa messages in the zLOG log
+utils.patchAsyncoreLogger()
+
+# we need to patch the 'service name' of the medusa syslog logger
+utils.patchSyslogServiceName()
+
+