Commit 96f4172a authored by Fred Drake's avatar Fred Drake

Remove all uses of environment variables for configuring ZPublisher.

parent efc1aafc
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
############################################################################## ##############################################################################
__doc__="""Python Object Publisher -- Publish Python objects on web servers __doc__="""Python Object Publisher -- Publish Python objects on web servers
$Id: Publish.py,v 1.166 2003/11/18 13:17:17 tseaver Exp $""" $Id: Publish.py,v 1.167 2004/04/25 21:26:15 fdrake Exp $"""
__version__='$Revision: 1.166 $'[11:-2] __version__='$Revision: 1.167 $'[11:-2]
import sys, os import sys, os
from Response import Response from Response import Response
...@@ -47,6 +47,17 @@ def missing_name(name, request): ...@@ -47,6 +47,17 @@ def missing_name(name, request):
def dont_publish_class(klass, request): def dont_publish_class(klass, request):
request.response.forbiddenError("class %s" % klass.__name__) request.response.forbiddenError("class %s" % klass.__name__)
_default_debug_mode = False
_default_realm = None
def set_default_debug_mode(debug_mode):
global _default_debug_mode
_default_debug_mode = debug_mode
def set_default_authentication_realm(realm):
global _default_realm
_default_realm = realm
def publish(request, module_name, after_list, debug=0, def publish(request, module_name, after_list, debug=0,
# Optimize: # Optimize:
call_object=call_object, call_object=call_object,
...@@ -224,10 +235,8 @@ def get_module_info(module_name, modules={}, ...@@ -224,10 +235,8 @@ def get_module_info(module_name, modules={},
# Let the app specify a realm # Let the app specify a realm
if hasattr(module,'__bobo_realm__'): if hasattr(module,'__bobo_realm__'):
realm=module.__bobo_realm__ realm=module.__bobo_realm__
elif os.environ.has_key('Z_REALM'): elif _default_realm is not None:
realm=os.environ['Z_REALM'] realm=_default_realm
elif os.environ.has_key('BOBO_REALM'):
realm=os.environ['BOBO_REALM']
else: else:
realm=module_name realm=module_name
...@@ -236,15 +245,7 @@ def get_module_info(module_name, modules={}, ...@@ -236,15 +245,7 @@ def get_module_info(module_name, modules={},
if hasattr(module,'__bobo_debug_mode__'): if hasattr(module,'__bobo_debug_mode__'):
debug_mode=not not module.__bobo_debug_mode__ debug_mode=not not module.__bobo_debug_mode__
else: else:
debug_mode = _default_debug_mode
z1 = os.environ.get('Z_DEBUG_MODE','')
z2 = os.environ.get('BOBO_DEBUG_MODE','')
if z1.lower() in ('yes','y') or z1.isdigit():
debug_mode = 1
elif z2.lower() in ('yes','y') or z2.isdigit():
debug_mode = 1
bobo_before = getattr(module, "__bobo_before__", None) bobo_before = getattr(module, "__bobo_before__", None)
bobo_after = getattr(module, "__bobo_after__", None) bobo_after = getattr(module, "__bobo_after__", None)
......
...@@ -60,8 +60,11 @@ class ZopeStarter: ...@@ -60,8 +60,11 @@ class ZopeStarter:
""" """
def __init__(self): def __init__(self):
self.event_logger = logging.getLogger() self.event_logger = logging.getLogger()
# set up our initial logging environment (log everything to stderr # We log events to the root logger, which is backed by a
# if we're not in debug mode). # "StartupHandler" log handler. The "StartupHandler" buffers
# log messages. When the "real" loggers are set up, we flush
# accumulated messages in StartupHandler's buffers to the real
# logger.
formatter = logging.Formatter( formatter = logging.Formatter(
"%(asctime)s %(levelname)s %(name)s %(message)s", "%(asctime)s %(levelname)s %(name)s %(message)s",
"%Y-%m-%d %H:%M:%S") "%Y-%m-%d %H:%M:%S")
...@@ -78,14 +81,10 @@ class ZopeStarter: ...@@ -78,14 +81,10 @@ class ZopeStarter:
self.cfg = cfg self.cfg = cfg
def prepare(self): def prepare(self):
# we log events to the root logger, which is backed by a
# "StartupHandler" log handler. The "StartupHandler" outputs to
# stderr but also buffers log messages. When the "real" loggers
# are set up, we flush accumulated messages in StartupHandler's
# buffers to the real logger.
self.setupInitialLogging() self.setupInitialLogging()
self.setupLocale() self.setupLocale()
self.setupSecurityOptions() self.setupSecurityOptions()
self.setupPublisher()
# Start ZServer servers before we drop privileges so we can bind to # Start ZServer servers before we drop privileges so we can bind to
# "low" ports: # "low" ports:
self.setupZServerThreads() self.setupZServerThreads()
...@@ -127,6 +126,13 @@ class ZopeStarter: ...@@ -127,6 +126,13 @@ class ZopeStarter:
def error(self, msg): def error(self, msg):
logger.error(msg) logger.error(msg)
def setupPublisher(self):
import Globals
import ZPublisher.Publish
Globals.DevelopmentMode = self.cfg.debug_mode
ZPublisher.Publish.set_default_debug_mode(self.cfg.debug_mode)
ZPublisher.Publish.set_default_realm(self.cfg.http_realm)
def setupSecurityOptions(self): def setupSecurityOptions(self):
import AccessControl import AccessControl
AccessControl.setImplementation( AccessControl.setImplementation(
......
...@@ -16,12 +16,6 @@ def _setenv(name, value): ...@@ -16,12 +16,6 @@ def _setenv(name, value):
else: else:
os.environ[name] = `value` os.environ[name] = `value`
def debug_mode(value):
value and _setenv('Z_DEBUG_MODE', '1')
import Globals
Globals.DevelopmentMode = not not value
return value
def locale(value): def locale(value):
import locale import locale
locale.setlocale(locale.LC_ALL, value) locale.setlocale(locale.LC_ALL, value)
...@@ -95,10 +89,6 @@ def publisher_profile_file(value): ...@@ -95,10 +89,6 @@ def publisher_profile_file(value):
install_profiling(value) install_profiling(value)
return value return value
def http_realm(value):
value is not None and _setenv('Z_REALM', value)
return value
def max_listen_sockets(value): def max_listen_sockets(value):
import ZServer import ZServer
ZServer.CONNECTION_LIMIT = value ZServer.CONNECTION_LIMIT = value
......
...@@ -328,8 +328,7 @@ ...@@ -328,8 +328,7 @@
<metadefault>$clienthome/Z2.lock</metadefault> <metadefault>$clienthome/Z2.lock</metadefault>
</key> </key>
<key name="debug-mode" datatype="boolean" default="on" <key name="debug-mode" datatype="boolean" default="on">
handler="debug_mode">
<description> <description>
A switch which controls several aspects of Zope operation useful for A switch which controls several aspects of Zope operation useful for
developing under Zope. When debug mode is on: developing under Zope. When debug mode is on:
...@@ -486,7 +485,7 @@ ...@@ -486,7 +485,7 @@
</description> </description>
</key> </key>
<key name="http-realm" default="Zope" handler="http_realm"> <key name="http-realm" default="Zope">
<description> <description>
The HTTP "Realm" header value sent by this Zope instance. This value The HTTP "Realm" header value sent by this Zope instance. This value
often shows up in basic authentication dialogs. often shows up in basic authentication dialogs.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment