Skip to content
This repository has been archived by the owner on Feb 10, 2023. It is now read-only.

Commit

Permalink
Move ZServer related starter logic from Zope2 project.
Browse files Browse the repository at this point in the history
  • Loading branch information
hannosch committed Aug 7, 2016
1 parent 39566be commit e7077e3
Show file tree
Hide file tree
Showing 12 changed files with 998 additions and 37 deletions.
26 changes: 14 additions & 12 deletions src/ZServer/HTTPServer.py
Expand Up @@ -31,6 +31,8 @@
as requests are received.
"""
from __future__ import absolute_import

import sys
import re
import os
Expand All @@ -40,24 +42,24 @@
import socket
from cStringIO import StringIO

from PubCore import handle
from HTTPResponse import make_response
from ZServer.PubCore import handle
from ZServer.HTTPResponse import make_response
from ZPublisher.HTTPRequest import HTTPRequest

import asyncore
import asynchat

from medusa.http_server import http_server, get_header
from medusa.http_server import fifo, http_channel, VERSION_STRING
from medusa import counter, producers
from medusa.test import max_sockets
from medusa.default_handler import unquote
from ZServer.medusa.http_server import http_server, get_header
from ZServer.medusa.http_server import fifo, http_channel, VERSION_STRING
from ZServer.medusa import counter, producers
from ZServer.medusa.test import max_sockets
from ZServer.medusa.default_handler import unquote
from asyncore import compact_traceback, dispatcher

from ZServer import ZOPE_VERSION, ZSERVER_VERSION
from ZServer import requestCloseOnExec
import DebugLogger
from medusa import logger
from ZServer import DebugLogger
from ZServer.medusa import logger


CONTENT_LENGTH = re.compile('Content-Length: ([0-9]+)',re.I)
Expand Down Expand Up @@ -294,7 +296,7 @@ def status(self):
</ul>""" %(self.module_name, self.hits)
)

from HTTPResponse import ChannelPipe
from ZServer.HTTPResponse import ChannelPipe

class zwsgi_handler(zhttp_handler):

Expand Down Expand Up @@ -488,9 +490,9 @@ def create_socket(self, family, type):
requestCloseOnExec(self.socket)

def readable(self):
from ZServer import CONNECTION_LIMIT
from Zope2.Startup.config import ZSERVER_CONNECTION_LIMIT
return self.accepting and \
len(asyncore.socket_map) < CONNECTION_LIMIT
len(asyncore.socket_map) < ZSERVER_CONNECTION_LIMIT

def listen(self, num):
# override asyncore limits for nt's listen queue size
Expand Down
19 changes: 10 additions & 9 deletions src/ZServer/PCGIServer.py
Expand Up @@ -27,22 +27,23 @@
Note that ZServer can operate multiple PCGI servers.
"""
from __future__ import absolute_import

from medusa import logger
from ZServer.medusa import logger
import asynchat, asyncore
from medusa.counter import counter
from medusa.http_server import compute_timezone_for_log
from ZServer.medusa.counter import counter
from ZServer.medusa.http_server import compute_timezone_for_log
from asyncore import compact_traceback

import ZServer
from ZServer import requestCloseOnExec

from PubCore import handle
from PubCore.ZEvent import Wakeup
from ZServer.PubCore import handle
from ZServer.PubCore.ZEvent import Wakeup
from ZPublisher.HTTPResponse import HTTPResponse
from ZPublisher.HTTPRequest import HTTPRequest
from Producers import ShutdownProducer, LoggingProducer, CallbackProducer
import DebugLogger
from ZServer.Producers import ShutdownProducer, LoggingProducer, CallbackProducer
from ZServer import DebugLogger

from Zope2.Startup import config

Expand Down Expand Up @@ -328,8 +329,8 @@ def handle_accept (self):
self.channel_class(self, conn, addr)

def readable(self):
from ZServer import CONNECTION_LIMIT
return len(asyncore.socket_map) < CONNECTION_LIMIT
from Zope2.Startup.config import ZSERVER_CONNECTION_LIMIT
return len(asyncore.socket_map) < ZSERVER_CONNECTION_LIMIT

def writable (self):
return 0
Expand Down
Empty file.
Empty file.
140 changes: 140 additions & 0 deletions src/ZServer/Zope2/App/tests/test_schema.py
@@ -0,0 +1,140 @@
##############################################################################
#
# Copyright (c) 2003 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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 os
import cStringIO
import tempfile
import unittest

import ZConfig

import Products
from Zope2.Startup import datatypes
from Zope2.Startup.options import ZopeOptions

_SCHEMA = {}
TEMPNAME = tempfile.mktemp()
TEMPPRODUCTS = os.path.join(TEMPNAME, "Products")
TEMPVAR = os.path.join(TEMPNAME, "var")


def getSchema(schemafile):
global _SCHEMA
if schemafile not in _SCHEMA:
opts = ZopeOptions()
opts.schemafile = schemafile
opts.load_schema()
_SCHEMA[schemafile] = opts.schema
return _SCHEMA[schemafile]


class ZServerStartupTestCase(unittest.TestCase):

def tearDown(self):
Products.__path__ = [d for d in Products.__path__
if os.path.exists(d)]

@property
def schema(self):
return getSchema('zopeschema.xml')

def load_config_text(self, text):
# We have to create a directory of our own since the existence
# of the directory is checked. This handles this in a
# platform-independent way.
schema = self.schema
sio = cStringIO.StringIO(
text.replace("<<INSTANCE_HOME>>", TEMPNAME))
os.mkdir(TEMPNAME)
os.mkdir(TEMPPRODUCTS)
os.mkdir(TEMPVAR)
try:
conf, handler = ZConfig.loadConfigFile(schema, sio)
finally:
os.rmdir(TEMPPRODUCTS)
os.rmdir(TEMPVAR)
os.rmdir(TEMPNAME)
self.assertEqual(conf.instancehome, TEMPNAME)
return conf, handler

def test_cgi_environment(self):
conf, handler = self.load_config_text("""\
# instancehome is here since it's required
instancehome <<INSTANCE_HOME>>
<cgi-environment>
HEADER value
ANOTHER value2
</cgi-environment>
""")
items = conf.cgi_environment.items()
items.sort()
self.assertEqual(
items, [("ANOTHER", "value2"), ("HEADER", "value")])

def test_ms_public_header(self):
from Zope2.Startup import config
from Zope2.Startup.handlers import handleConfig

default_setting = config.ZSERVER_ENABLE_MS_PUBLIC_HEADER
try:
conf, handler = self.load_config_text("""\
instancehome <<INSTANCE_HOME>>
enable-ms-public-header true
""")
handleConfig(None, handler)
self.assertTrue(config.ZSERVER_ENABLE_MS_PUBLIC_HEADER)

conf, handler = self.load_config_text("""\
instancehome <<INSTANCE_HOME>>
enable-ms-public-header false
""")
handleConfig(None, handler)
self.assertFalse(config.ZSERVER_ENABLE_MS_PUBLIC_HEADER)
finally:
config.ZSERVER_ENABLE_MS_PUBLIC_HEADER = default_setting

def test_path(self):
p1 = tempfile.mktemp()
p2 = tempfile.mktemp()
try:
os.mkdir(p1)
os.mkdir(p2)
conf, handler = self.load_config_text("""\
# instancehome is here since it's required
instancehome <<INSTANCE_HOME>>
path %s
path %s
""" % (p1, p2))
items = conf.path
self.assertEqual(items, [p1, p2])
finally:
if os.path.exists(p1):
os.rmdir(p1)
if os.path.exists(p2):
os.rmdir(p2)

def test_access_and_trace_logs(self):
fn = tempfile.mktemp()
conf, handler = self.load_config_text("""
instancehome <<INSTANCE_HOME>>
<logger access>
<logfile>
path %s
</logfile>
</logger>
""" % fn)
self.assert_(isinstance(conf.access, datatypes.LoggerFactory))
self.assertEqual(conf.access.name, "access")
self.assertEqual(conf.access.handler_factories[0].section.path, fn)
self.assert_(conf.trace is None)
Empty file.

0 comments on commit e7077e3

Please sign in to comment.