Commit 62f8ccb2 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki Committed by Arnaud Fontaine

WIP: remove ZServer dependency.

parent 0b6c2da1
......@@ -106,14 +106,12 @@ instancehome = getConfiguration().instancehome
if instancehome is not None:
log_directory = os.path.join(instancehome, 'log')
if os.path.isdir(log_directory):
from Signals import Signals
from ZConfig.components.logger.loghandler import FileHandler
log_file_handler = FileHandler(os.path.join(log_directory, 'CMFActivity.log'))
# Default zope log format string borrowed from
# ZConfig/components/logger/factory.xml, but without the extra "------"
# line separating entries.
log_file_handler.setFormatter(logging.Formatter("%(asctime)s %(levelname)s %(name)s %(message)s", "%Y-%m-%dT%H:%M:%S"))
Signals.registerZopeSignals([log_file_handler])
activity_logger.addHandler(log_file_handler)
activity_logger.propagate = 0
......
......@@ -114,7 +114,3 @@ def match(self, request):
return 1
else:
return 0
if six.PY2:
from ZServer.HTTPServer import zhttp_handler
zhttp_handler.match = match
......@@ -61,9 +61,6 @@ from Products.ERP5Type.patches import PersistentMapping
from Products.ERP5Type.patches import DateTimePatch
from Products.ERP5Type.patches import PythonScript
from Products.ERP5Type.patches import MailHost
if six.PY2:
# No more ZServer
from Products.ERP5Type.patches import http_server
from Products.ERP5Type.patches import memcache_client
from Products.ERP5Type.patches import StateChangeInfoPatch
from Products.ERP5Type.patches import transforms
......@@ -94,9 +91,6 @@ from Products.ERP5Type.patches import OFSFile
from Products.ERP5Type.patches import ZSQLMethod
from Products.ERP5Type.patches import MimetypesRegistry
from Products.ERP5Type.patches import users
if six.PY2:
# No ZServer
from Products.ERP5Type.patches import Publish
from Products.ERP5Type.patches import WSGITask
if six.PY2:
# XXX-zope4py3: urllib2 removed (see future/backports/urllib/request.py)
......
This diff is collapsed.
# This code is taken from the medusa in zope 2.8.
#
# The license term should be this one:
#
# Medusa is Copyright 1996-2000, Sam Rushing <rushing@nightmare.com>
#
# All Rights Reserved
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose and without fee is hereby
# granted, provided that the above copyright notice appear in all
# copies and that both that copyright notice and this permission
# notice appear in supporting documentation, and that the name of Sam
# Rushing not be used in advertising or publicity pertaining to
# distribution of the software without specific, written prior
# permission.
# Author: Sam Rushing <rushing@nightmare.com>
# Copyright 1996-2000 by Sam Rushing
# All Rights Reserved.
from ZServer.medusa.http_server import http_request
import ZPublisher.HTTPRequest
import string
import base64
import time
from six.moves.urllib.parse import quote
def log (self, bytes):
addr = self.channel.addr[0]
# Frontend-facing proxy is responsible for sanitising
# HTTP_X_FORWARDED_FOR, and only trusted accesses should bypass
# that proxy. So trust first entry.
#
# <patch>
if ZPublisher.HTTPRequest.trusted_proxies == ('0.0.0.0',): # Magic value to enable this functionality
forwarded_for = (self.get_header('x-forwarded-for') or '').split(',', 1)[0].strip()
if forwarded_for:
addr = forwarded_for
# </patch>
user_agent=self.get_header('user-agent')
if not user_agent: user_agent=''
referer=self.get_header('referer')
if not referer: referer=''
auth=self.get_header('Authorization')
name='Anonymous'
if auth is not None:
if string.lower(auth[:6]) == 'basic ':
try: decoded=base64.decodestring(auth[6:])
except base64.binascii.Error: decoded=''
t = string.split(decoded, ':', 1)
if len(t) < 2:
name = 'Unknown (bad auth string)'
else:
name = t[0]
# Originally, an unquoted request string was logged, but
# it only confuses log analysis programs! Note that Apache
# HTTP Server never unquote URIs in the access log.
t = self.request.split(' ')
quoted_request = '%s %s %s' % (t[0], quote(' '.join(t[1:-1])), t[-1])
self.channel.server.logger.log (
# <patch>
addr,
# </patch>
'- %s [%s] "%s" %d %d "%s" "%s"\n' % (
name,
self.log_date_string (time.time()),
# <patch>
quoted_request,
# </patch>
self.reply_code,
bytes,
referer,
user_agent
)
)
http_request.log = log
......@@ -3,7 +3,6 @@ import errno, logging, os, socket, time
import itertools
from threading import Thread
from UserDict import IterableUserDict
import Lifetime
import transaction
from Testing import ZopeTestCase
from ZODB.POSException import ConflictError
......@@ -140,21 +139,13 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase):
"""
_server_address = None # (host, port) of the http server if it was started, None otherwise
@staticmethod
def asyncore_loop():
try:
Lifetime.lifetime_loop()
except KeyboardInterrupt:
pass
Lifetime.graceful_shutdown_loop()
def startZServer(self, verbose=False):
"""Start HTTP ZServer in background"""
if self._server_address is None:
from Products.ERP5Type.tests.runUnitTest import log_directory
log = os.path.join(log_directory, "Z2.log")
message = "Running %s server at %s:%s\n"
if int(os.environ.get('erp5_wsgi', 0)):
if True:
from Products.ERP5.bin.zopewsgi import app_wrapper, createServer
sockets = []
server_type = 'HTTP'
......@@ -196,23 +187,6 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase):
t = Thread(target=hs.run)
t.setDaemon(1)
t.start()
else:
_print = lambda hs: verbose and ZopeTestCase._print(
message % (hs.server_protocol, hs.server_name, hs.server_port))
try:
hs = createZServer(log)
except RuntimeError as e:
ZopeTestCase._print(str(e))
else:
ProcessingNodeTestCase._server_address = hs.server_name, hs.server_port
_print(hs)
try:
_print(createZServer(log, zserver_type='webdav'))
except RuntimeError as e:
ZopeTestCase._print('Could not start webdav zserver: %s\n' % e)
t = Thread(target=Lifetime.loop)
t.setDaemon(1)
t.start()
from Products.CMFActivity import ActivityTool
# Reset, in case that getServerAddress was already called,
# in which case, the value was ('', '')
......@@ -305,9 +279,6 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase):
ZopeTestCase._print(' %i' % message_count)
old_message_count = message_count
portal_activities.process_timer(None, None)
if Lifetime._shutdown_phase:
# XXX CMFActivity contains bare excepts
raise KeyboardInterrupt
message_list = getMessageList()
message_count = len(message_list)
if time.time() >= deadline or message_count and any(x.processing_node == -2
......@@ -375,7 +346,7 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase):
def processing_node(self):
"""Main loop for nodes that process activities"""
try:
while not Lifetime._shutdown_phase:
while True:
time.sleep(.3)
transaction.begin()
try:
......@@ -398,7 +369,7 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase):
timerserver_thread = None
try:
while not Lifetime._shutdown_phase:
while True:
time.sleep(.3)
transaction.begin()
try:
......
......@@ -463,9 +463,6 @@ class DebugTestResult:
self.result = result
def _start_debugger(self, tb):
import Lifetime
if Lifetime._shutdown_phase:
return
try:
# try ipython if available
import IPython
......@@ -624,11 +621,9 @@ def runUnitTestList(test_list, verbosity=1, debug=0, run_only=None):
TestRunner = unittest.TextTestRunner
import Lifetime
from Zope2.custom_zodb import Storage, save_mysql, \
node_pid_list, neo_cluster, zeo_server_pid, wcfs_server
def shutdown(signum, frame, signum_set=set()):
Lifetime.shutdown(0)
signum_set.add(signum)
if node_pid_list is None and len(signum_set) > 1:
# in case of ^C, a child should also receive a SIGHUP from the parent,
......
......@@ -69,13 +69,6 @@ def get_new_publish(zope_publish):
if patch is False:
patch = True
if six.PY2: # ZServer-specific patch
# Apply the patch TODO: zope4py2 is this really needed ?
from ZPublisher import Publish
Publish.publish = get_new_publish(Publish.publish)
# PATCH 2: Accept
#
# Adds the variable AcceptLanguage to the REQUEST. It provides a higher
......
import six
if six.PY2:
from ZServer.datatypes import ServerFactory
class TimerServerFactory(ServerFactory):
def __init__(self, section):
ServerFactory.__init__(self)
self.interval = section.interval
def create(self):
from .TimerServer import TimerServer
return TimerServer(self.module, self.interval)
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