Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
95d7a661
Commit
95d7a661
authored
Aug 07, 2016
by
Hanno Schlichting
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Copy startup and zope.conf parsing logic to ZServer.
parent
519ca223
Changes
21
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
142 additions
and
872 deletions
+142
-872
develop/ZServer/src/ZServer/Zope2/Startup/tests/test_warnfilter.py
...Server/src/ZServer/Zope2/Startup/tests/test_warnfilter.py
+0
-123
src/App/config.py
src/App/config.py
+3
-4
src/OFS/tests/testAcquisition.py
src/OFS/tests/testAcquisition.py
+3
-3
src/OFS/tests/testCopySupportEvents.py
src/OFS/tests/testCopySupportEvents.py
+1
-1
src/OFS/tests/testCopySupportHooks.py
src/OFS/tests/testCopySupportHooks.py
+1
-1
src/OFS/tests/testFileAndImage.py
src/OFS/tests/testFileAndImage.py
+1
-1
src/OFS/tests/testHistory.py
src/OFS/tests/testHistory.py
+6
-6
src/Testing/ZopeTestCase/ZopeLite.py
src/Testing/ZopeTestCase/ZopeLite.py
+2
-1
src/ZPublisher/tests/testPostTraversal.py
src/ZPublisher/tests/testPostTraversal.py
+1
-1
src/Zope2/Startup/__init__.py
src/Zope2/Startup/__init__.py
+4
-13
src/Zope2/Startup/datatypes.py
src/Zope2/Startup/datatypes.py
+21
-61
src/Zope2/Startup/handlers.py
src/Zope2/Startup/handlers.py
+30
-101
src/Zope2/Startup/options.py
src/Zope2/Startup/options.py
+12
-15
src/Zope2/Startup/run.py
src/Zope2/Startup/run.py
+23
-21
src/Zope2/Startup/starter.py
src/Zope2/Startup/starter.py
+1
-1
src/Zope2/Startup/tests/test_schema.py
src/Zope2/Startup/tests/test_schema.py
+2
-2
src/Zope2/Startup/tests/test_starter.py
src/Zope2/Startup/tests/test_starter.py
+4
-4
src/Zope2/Startup/wsgischema.xml
src/Zope2/Startup/wsgischema.xml
+3
-58
src/Zope2/Startup/zopeschema.xml
src/Zope2/Startup/zopeschema.xml
+0
-442
src/Zope2/__init__.py
src/Zope2/__init__.py
+20
-9
src/Zope2/utilities/finder.py
src/Zope2/utilities/finder.py
+4
-4
No files found.
develop/ZServer/src/ZServer/Zope2/Startup/tests/test_warnfilter.py
deleted
100644 → 0
View file @
519ca223
##############################################################################
#
# 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
sys
import
tempfile
import
unittest
import
warnings
import
ZConfig
import
Zope2.Startup
import
Products
TEMPNAME
=
tempfile
.
mktemp
()
TEMPPRODUCTS
=
os
.
path
.
join
(
TEMPNAME
,
"Products"
)
def
getSchema
():
startup
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
Zope2
.
Startup
.
__file__
))
schemafile
=
os
.
path
.
join
(
startup
,
'wsgischema.xml'
)
return
ZConfig
.
loadSchema
(
schemafile
)
class
TestSchemaWarning
(
Warning
):
pass
class
TestWarnFilter
(
unittest
.
TestCase
):
schema
=
None
def
setUp
(
self
):
if
self
.
schema
is
None
:
TestWarnFilter
.
schema
=
getSchema
()
# There is no official API to restore warning filters to a previous
# state. Here we cheat.
self
.
original_warning_filters
=
warnings
.
filters
[:]
def
tearDown
(
self
):
warnings
.
filters
[:]
=
self
.
original_warning_filters
Products
.
__path__
=
[
d
for
d
in
Products
.
__path__
if
os
.
path
.
exists
(
d
)]
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
)
try
:
conf
,
handler
=
ZConfig
.
loadConfigFile
(
schema
,
sio
)
finally
:
os
.
rmdir
(
TEMPPRODUCTS
)
os
.
rmdir
(
TEMPNAME
)
self
.
assertEqual
(
conf
.
instancehome
,
TEMPNAME
)
return
conf
,
handler
if
sys
.
version_info
<
(
2
,
7
):
def
test_behavior
(
self
):
conf
,
handler
=
self
.
load_config_text
(
"""
\
instancehome <<INSTANCE_HOME>>
<warnfilter>
action error
message .*test.*
category Zope2.Startup.tests.test_warnfilter.TestSchemaWarning
module .*test_warnfilter.*
lineno 0
</warnfilter>
<warnfilter>
action error
message .*test.*
</warnfilter>
"""
)
self
.
assertEqual
(
len
(
conf
.
warnfilters
),
2
)
self
.
assertRaises
(
TestSchemaWarning
,
self
.
_dowarning1
)
self
.
assertRaises
(
UserWarning
,
self
.
_dowarning2
)
def
_dowarning1
(
self
):
warnings
.
warn
(
'This is only a test.'
,
TestSchemaWarning
)
def
_dowarning2
(
self
):
warnings
.
warn
(
'This is another test.'
)
def
test_warn_action
(
self
):
self
.
assertRaises
(
ZConfig
.
ConfigurationSyntaxError
,
self
.
_badwarnaction
)
def
_badwarnaction
(
self
):
conf
,
handler
=
self
.
load_config_text
(
"""
\
instancehome <<INSTANCE_HOME>>
<warnfilter>
action wontwork
category Zope2.Startup.tests.test_schema.TestSchemaWarning
</warnfilter>
"""
)
def
test_warn_category
(
self
):
self
.
assertRaises
(
ZConfig
.
ConfigurationSyntaxError
,
self
.
_badwarncategory
)
def
_badwarncategory
(
self
):
conf
,
handler
=
self
.
load_config_text
(
"""
\
instancehome <<INSTANCE_HOME>>
<warnfilter>
action error
category A.Module.That.Doesnt.Exist
</warnfilter>
"""
)
src/App/config.py
View file @
95d7a661
...
...
@@ -14,6 +14,7 @@
_config
=
None
def
getConfiguration
():
"""Return the global Zope configuration object.
...
...
@@ -25,6 +26,7 @@ def getConfiguration():
setConfiguration
(
DefaultConfiguration
())
return
_config
def
setConfiguration
(
cfg
):
"""Set the global configuration object.
...
...
@@ -54,6 +56,7 @@ def setConfiguration(cfg):
Globals
.
DevelopmentMode
=
cfg
.
debug_mode
class
DefaultConfiguration
:
"""
This configuration should be used effectively only during unit tests
...
...
@@ -64,12 +67,8 @@ class DefaultConfiguration:
self
.
instancehome
=
FindHomes
.
INSTANCE_HOME
self
.
dbtab
=
None
self
.
debug_mode
=
True
self
.
enable_product_installation
=
False
self
.
locale
=
None
# ZServer.HTTPServer
self
.
http_header_max_length
=
8196
# VerboseSecurity
self
.
skip_ownership_checking
=
False
self
.
skip_authentication_checking
=
False
src/OFS/tests/testAcquisition.py
View file @
95d7a661
...
...
@@ -21,9 +21,6 @@ import unittest
from
Testing.makerequest
import
makerequest
import
Zope2
Zope2
.
startup
()
from
OFS.SimpleItem
import
SimpleItem
from
AccessControl
import
ClassSecurityInfo
from
AccessControl.class_init
import
InitializeClass
...
...
@@ -33,6 +30,9 @@ from AccessControl.Permissions import view_management_screens
from
AccessControl.ImplPython
import
guarded_getattr
as
guarded_getattr_py
from
AccessControl.ImplC
import
guarded_getattr
as
guarded_getattr_c
import
Zope2
Zope2
.
startup_wsgi
()
class
AllowedItem
(
SimpleItem
):
id
=
'allowed'
...
...
src/OFS/tests/testCopySupportEvents.py
View file @
95d7a661
...
...
@@ -15,7 +15,7 @@ from OFS.SimpleItem import SimpleItem
from
Testing.makerequest
import
makerequest
from
Zope2.App
import
zcml
Zope2
.
startup
()
Zope2
.
startup
_wsgi
()
class
EventLogger
(
object
):
...
...
src/OFS/tests/testCopySupportHooks.py
View file @
95d7a661
...
...
@@ -16,7 +16,7 @@ from OFS.Folder import Folder
from
Zope2.App
import
zcml
Zope2
.
startup
()
Zope2
.
startup
_wsgi
()
class
EventLogger
(
object
):
...
...
src/OFS/tests/testFileAndImage.py
View file @
95d7a661
...
...
@@ -35,7 +35,7 @@ except:
imagedata
=
os
.
path
.
join
(
here
,
'test.gif'
)
filedata
=
os
.
path
.
join
(
here
,
'test.gif'
)
Zope2
.
startup
()
Zope2
.
startup
_wsgi
()
def
makeConnection
():
...
...
src/OFS/tests/testHistory.py
View file @
95d7a661
import
unittest
import
Zope2
Zope2
.
startup
()
import
os
import
shutil
import
time
import
transaction
import
tempfile
import
unittest
import
transaction
import
ZODB
from
ZODB.FileStorage
import
FileStorage
from
OFS.Application
import
Application
from
OFS.History
import
Historical
from
OFS.SimpleItem
import
SimpleItem
from
ZODB.FileStorage
import
FileStorage
import
Zope2
Zope2
.
startup_wsgi
()
class
HistoryItem
(
SimpleItem
,
Historical
):
...
...
src/Testing/ZopeTestCase/ZopeLite.py
View file @
95d7a661
...
...
@@ -88,6 +88,7 @@ _configure_client_cache()
_exec
(
'import Zope2'
)
import
Zope2
import
Zope2.Startup.run
_exec
(
'import ZODB'
)
import
ZODB
_write
(
'.'
)
...
...
@@ -214,7 +215,7 @@ installProduct('OFSP', 1)
app
=
Zope2
.
app
debug
=
Zope2
.
debug
DB
=
Zope2
.
DB
configure
=
Zope2
.
configure
configure
=
Zope2
.
Startup
.
run
.
configure_wsgi
def
startup
():
pass
Zope
=
Zope2
active
=
_patched
...
...
src/ZPublisher/tests/testPostTraversal.py
View file @
95d7a661
...
...
@@ -5,7 +5,7 @@ from ZPublisher.BaseRequest import BaseRequest
from
ZPublisher.HTTPResponse
import
HTTPResponse
import
Zope2
Zope2
.
startup
()
Zope2
.
startup
_wsgi
()
pt_simple_was_run
=
0
...
...
src/Zope2/Startup/__init__.py
View file @
95d7a661
...
...
@@ -14,27 +14,18 @@
from
__future__
import
absolute_import
import
sys
from
zope.deferredimport
import
deprecated
# BBB Zope 5.0
deprecated
(
'Please import from ZServer.Zope2.Startup.starter'
,
get_starter
=
'ZServer.Zope2.Startup.starter:get_starter'
,
UnixZopeStarter
=
'ZServer.Zope2.Startup.starter:UnixZopeStarter'
,
WindowsZopeStarter
=
'ZServer.Zope2.Startup.starter:WindowsZopeStarter'
,
ZopeStarter
=
'ZServer.Zope2.Startup.starter:ZopeStarter'
,
)
def
get_starter
(
wsgi
=
False
):
if
wsgi
:
from
Zope2.Startup.starter
import
WSGIStarter
return
WSGIStarter
()
else
:
if
sys
.
platform
[:
3
].
lower
()
==
"win"
:
from
ZServer.Zope2.Startup.starter
import
WindowsZopeStarter
return
WindowsZopeStarter
()
else
:
from
ZServer.Zope2.Startup.starter
import
UnixZopeStarter
return
UnixZopeStarter
()
def
get_wsgi_starter
():
from
Zope2.Startup.starter
import
WSGIStarter
return
WSGIStarter
()
src/Zope2/Startup/datatypes.py
View file @
95d7a661
...
...
@@ -18,9 +18,23 @@ import os
from
UserDict
import
UserDict
import
traceback
from
ZConfig.components.logger
import
logger
from
ZODB.config
import
ZODBDatabase
from
zope.deferredimport
import
deprecated
# BBB Zope 5.0
_prefix
=
'ZServer.Zope2.Startup.datatypes:'
deprecated
(
'Please import from ZServer.Zope2.Startup.datatypes.'
,
cgi_environment
=
_prefix
+
'cgi_environment'
,
LoggerFactory
=
_prefix
+
'LoggerFactory'
,
dns_resolver
=
_prefix
+
'dns_resolver'
,
python_dotted_path
=
_prefix
+
'python_dotted_path'
,
zdaemonEnvironDict
=
_prefix
+
'zdaemonEnvironDict'
,
root_config
=
_prefix
+
'root_config'
,
minimalClassFactory
=
_prefix
+
'minimalClassFactory'
,
)
def
security_policy_implementation
(
value
):
value
=
value
.
upper
()
...
...
@@ -39,31 +53,10 @@ def datetime_format(value):
return
value
def
cgi_
environment
(
section
):
def
environment
(
section
):
return
section
.
environ
class
LoggerFactory
(
logger
.
LoggerFactory
):
"""
A factory used to create loggers while delaying actual logger
instance construction. We need to do this because we may want to
reference a logger before actually instantiating it (for example,
to allow the app time to set an effective user). An instance of
this wrapper is a callable which, when called, returns a logger
object.
"""
def
__init__
(
self
,
section
):
section
.
name
=
section
.
getSectionName
()
section
.
propagate
=
False
logger
.
LoggerFactory
.
__init__
(
self
,
section
)
def
dns_resolver
(
hostname
):
# DNS resolver
from
ZServer.medusa
import
resolver
return
resolver
.
caching_resolver
(
hostname
)
def
mount_point
(
value
):
# mount-point definition
if
not
value
:
...
...
@@ -98,14 +91,7 @@ def importable_name(name):
name
,
IO
.
getvalue
()))
def
python_dotted_path
(
name
):
# A datatype that ensures that a dotted path name can be resolved but
# returns the name instead of the object
ob
=
importable_name
(
name
)
# NOQA - will fail in course
return
name
class
zdaemonEnvironDict
(
UserDict
):
class
ZDaemonEnvironDict
(
UserDict
):
# zdaemon 2 expects to use a 'mapping' attribute of the environ object.
@
property
...
...
@@ -113,24 +99,14 @@ class zdaemonEnvironDict(UserDict):
return
self
.
data
def
root_config
(
section
):
def
root_
wsgi_
config
(
section
):
from
ZConfig
import
ConfigurationError
from
ZConfig.matcher
import
SectionValue
if
section
.
environment
is
None
:
section
.
environment
=
zdaemonEnvironDict
()
if
hasattr
(
section
,
'cgi_environment'
):
if
section
.
cgi_environment
is
None
:
section
.
cgi_environment
=
zdaemonEnvironDict
()
section
.
environment
=
ZDaemonEnvironDict
()
if
section
.
clienthome
is
None
:
section
.
clienthome
=
os
.
path
.
join
(
section
.
instancehome
,
"var"
)
if
hasattr
(
section
,
'pid_filename'
):
if
section
.
pid_filename
is
None
:
section
.
pid_filename
=
os
.
path
.
join
(
section
.
clienthome
,
'Z2.pid'
)
if
hasattr
(
section
,
'lock_filename'
):
if
section
.
lock_filename
is
None
:
section
.
lock_filename
=
os
.
path
.
join
(
section
.
clienthome
,
'Z2.lock'
)
if
not
section
.
databases
:
section
.
databases
=
[]
...
...
@@ -294,24 +270,8 @@ class DBTab:
return
name
def
minimalClassFactory
(
jar
,
module
,
name
,
_silly
=
(
'__doc__'
,),
_globals
=
{}):
"""Minimal class factory.
If any class is not found, this class factory will propagate
the exception to the application, unlike the other class factories.
def
simpleClassFactory
(
jar
,
module
,
name
,
_silly
=
(
'__doc__'
,),
_globals
=
{}):
"""Class factory.
"""
m
=
__import__
(
module
,
_globals
,
_globals
,
_silly
)
return
getattr
(
m
,
name
)
def
simpleClassFactory
(
jar
,
module
,
name
,
_silly
=
(
'__doc__'
,),
_globals
=
{}):
"""Class factory.
"""
import
OFS.Uninstalled
try
:
m
=
__import__
(
module
,
_globals
,
_globals
,
_silly
)
return
getattr
(
m
,
name
)
except
:
return
OFS
.
Uninstalled
.
Broken
(
jar
,
None
,
(
module
,
name
))
src/Zope2/Startup/handlers.py
View file @
95d7a661
...
...
@@ -14,13 +14,29 @@
import
os
import
re
import
sys
from
socket
import
gethostbyaddr
try
:
from
ZServer.Zope2.Startup
import
config
except
ImportError
:
config
=
None
from
zope.deferredimport
import
deprecated
# BBB Zope 5.0
_prefix
=
'ZServer.Zope2.Startup.handlers:'
deprecated
(
'Please import from ZServer.Zope2.Startup.handlers.'
,
handleConfig
=
_prefix
+
'handleConfig'
,
root_handler
=
_prefix
+
'root_handler'
,
maximum_number_of_session_objects
=
(
_prefix
+
'maximum_number_of_session_objects'
),
session_add_notify_script_path
=
(
_prefix
+
'session_add_notify_script_path'
),
session_delete_notify_script_path
=
(
_prefix
+
'session_delete_notify_script_path'
),
session_timeout_minutes
=
_prefix
+
'session_timeout_minutes'
,
large_file_threshold
=
_prefix
+
'large_file_threshold'
,
max_listen_sockets
=
_prefix
+
'max_listen_sockets'
,
cgi_maxlen
=
_prefix
+
'cgi_maxlen'
,
http_header_max_length
=
_prefix
+
'http_header_max_length'
,
enable_ms_public_header
=
_prefix
+
'enable_ms_public_header'
,
)
def
_setenv
(
name
,
value
):
...
...
@@ -51,108 +67,21 @@ def automatically_quote_dtml_request_data(value):
return
value
def
maximum_number_of_session_objects
(
value
):
default
=
1000
value
not
in
(
None
,
default
)
and
_setenv
(
'ZSESSION_OBJECT_LIMIT'
,
value
)
return
value
def
session_add_notify_script_path
(
value
):
value
is
not
None
and
_setenv
(
'ZSESSION_ADD_NOTIFY'
,
value
)
return
value
def
session_delete_notify_script_path
(
value
):
value
is
not
None
and
_setenv
(
'ZSESSION_DEL_NOTIFY'
,
value
)
return
value
def
session_timeout_minutes
(
value
):
default
=
20
value
not
in
(
None
,
default
)
and
_setenv
(
'ZSESSION_TIMEOUT_MINS'
,
value
)
return
value
def
large_file_threshold
(
value
):
if
config
:
config
.
ZSERVER_LARGE_FILE_THRESHOLD
=
value
def
http_realm
(
value
):
value
is
not
None
and
_setenv
(
'Z_REALM'
,
value
)
return
value
def
max_listen_sockets
(
value
):
if
config
:
config
.
ZSERVER_CONNECTION_LIMIT
=
value
def
cgi_maxlen
(
value
):
import
cgi
cgi
.
maxlen
=
value
def
http_header_max_length
(
value
):
return
value
def
enable_ms_public_header
(
value
):
if
config
:
config
.
ZSERVER_ENABLE_MS_PUBLIC_HEADER
=
value
def
root_handler
(
cfg
):
def
root_wsgi_handler
(
cfg
):
# Set environment variables
for
k
,
v
in
cfg
.
environment
.
items
():
os
.
environ
[
k
]
=
v
if
hasattr
(
cfg
,
'path'
):
# Add directories to the pythonpath
instancelib
=
os
.
path
.
join
(
cfg
.
instancehome
,
'lib'
,
'python'
)
if
instancelib
not
in
cfg
.
path
:
if
os
.
path
.
isdir
(
instancelib
):
cfg
.
path
.
append
(
instancelib
)
path
=
cfg
.
path
[:]
path
.
reverse
()
for
dir
in
path
:
sys
.
path
.
insert
(
0
,
dir
)
if
hasattr
(
cfg
,
'products'
):
# Add any product directories not already in Products.__path__.
# Directories are added in the order they are mentioned
instanceprod
=
os
.
path
.
join
(
cfg
.
instancehome
,
'Products'
)
if
instanceprod
not
in
cfg
.
products
:
if
os
.
path
.
isdir
(
instanceprod
):
cfg
.
products
.
append
(
instanceprod
)
import
Products
L
=
[]
for
d
in
cfg
.
products
+
Products
.
__path__
:
if
d
not
in
L
:
L
.
append
(
d
)
Products
.
__path__
[:]
=
L
if
hasattr
(
cfg
,
'servers'
):
# if no servers are defined, create default servers
if
not
cfg
.
servers
:
cfg
.
servers
=
[]
# prepare servers:
for
factory
in
cfg
.
servers
:
factory
.
prepare
(
cfg
.
ip_address
or
''
,
cfg
.
dns_resolver
,
"Zope2"
,
cfg
.
cgi_environment
,
cfg
.
port_base
)
# set up trusted proxies
if
cfg
.
trusted_proxies
:
mapped
=
[]
for
name
in
cfg
.
trusted_proxies
:
mapped
.
extend
(
_name_to_ips
(
name
))
if
config
:
config
.
TRUSTED_PROXIES
=
tuple
(
mapped
)
from
ZPublisher
import
HTTPRequest
HTTPRequest
.
trusted_proxies
=
tuple
(
mapped
)
...
...
@@ -163,14 +92,6 @@ def root_handler(cfg):
HTTPRequest
.
retry_max_count
=
cfg
.
max_conflict_retries
def
handleConfig
(
cfg
,
multihandler
):
handlers
=
{}
for
name
,
value
in
globals
().
items
():
if
not
name
.
startswith
(
'_'
):
handlers
[
name
]
=
value
return
multihandler
(
handlers
)
def
_name_to_ips
(
host
,
_is_ip
=
re
.
compile
(
r'(\
d+
\.){3}'
).
match
):
"""Map a name *host* to the sequence of its ip addresses.
...
...
@@ -181,3 +102,11 @@ def _name_to_ips(host, _is_ip=re.compile(r'(\d+\.){3}').match):
if
_is_ip
(
host
):
return
[
host
]
return
gethostbyaddr
(
host
)[
2
]
def
handleWSGIConfig
(
cfg
,
multihandler
):
handlers
=
{}
for
name
,
value
in
globals
().
items
():
if
not
name
.
startswith
(
'_'
):
handlers
[
name
]
=
value
return
multihandler
(
handlers
)
src/Zope2/Startup/options.py
View file @
95d7a661
...
...
@@ -11,16 +11,6 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
The Zope run script.
Usage: runzope [-C URL][-h] [options]
Options:
-C/--configure URL -- configuration file or URL
-X -- overwrite config file settings, e.g. -X "debug-mode=on"
-h/--help -- print this usage message and exit
"""
import
os
import
xml.sax
...
...
@@ -28,6 +18,14 @@ import xml.sax
from
ZConfig.loader
import
SchemaLoader
from
ZConfig.schema
import
SchemaParser
from
zdaemon.zdoptions
import
ZDOptions
from
zope.deferredimport
import
deprecated
# BBB Zope 5.0
_prefix
=
'ZServer.Zope2.Startup.options:'
deprecated
(
'Please import from ZServer.Zope2.Startup.options.'
,
ZopeOptions
=
_prefix
+
'ZopeOptions'
,
)
class
ConditionalSchemaParser
(
SchemaParser
):
...
...
@@ -50,13 +48,12 @@ class ConditionalSchemaParser(SchemaParser):
SchemaParser
.
start_import
(
self
,
attrs
)
class
ZopeOptions
(
ZDOptions
):
# Provide help message, without indentation.
__doc__
=
__doc__
class
ZopeWSGIOptions
(
ZDOptions
):
"""zdaemon based ZopeWSGIOptions to parse a ZConfig schema.
"""
schemadir
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
schemafile
=
'
zope
schema.xml'
schemafile
=
'
wsgi
schema.xml'
def
load_schema
(
self
):
if
self
.
schema
is
None
:
...
...
src/Zope2/Startup/run.py
View file @
95d7a661
...
...
@@ -17,36 +17,40 @@ from zope.deferredimport import deprecated
# BBB Zope 5.0
deprecated
(
'Please import from ZServer.Zope2.Startup.run'
,
_setconfig
=
'ZServer.Zope2.Startup.run:_setconfig'
,
configure
=
'ZServer.Zope2.Startup.run:configure'
,
run
=
'ZServer.Zope2.Startup.run:run'
,
)
def
configure
(
configfile
):
""" Provide an API which allows scripts like zopectl to configure
Zope before attempting to do 'app = Zope2.app(). Should be used as
follows: from Zope2.Startup.run import configure;
configure('/path/to/configfile'); import Zope2; app = Zope2.app() """
def
configure_wsgi
(
configfile
):
""" Provide an API which allows scripts to configure Zope
before attempting to do 'app = Zope2.app(). Should be used as
follows: from Zope2.Startup.run import configure_wsgi;
configure_wsgi('/path/to/configfile');
import Zope2; app = Zope2.app()
"""
import
Zope2.Startup
starter
=
Zope2
.
Startup
.
get_
starter
(
wsgi
=
True
)
opts
=
_setconfig
(
configfile
)
starter
=
Zope2
.
Startup
.
get_
wsgi_starter
(
)
opts
=
_set
_wsgi_
config
(
configfile
)
starter
.
setConfiguration
(
opts
.
configroot
)
starter
.
setupSecurityOptions
()
return
starter
def
_setconfig
(
configfile
=
None
):
""" Configure a Zope instance based on Zope
Options. Optionally
accept a configfile argument (string path) in order to specify
where the configuration file exists. """
def
_set
_wsgi_
config
(
configfile
=
None
):
""" Configure a Zope instance based on Zope
WSGIOptions.
Optionally accept a configfile argument (string path) in order
to specify
where the configuration file exists. """
from
Zope2.Startup
import
options
,
handlers
opts
=
options
.
ZopeOptions
()
opts
=
options
.
Zope
WSGI
Options
()
if
configfile
:
opts
.
configfile
=
configfile
opts
.
realize
(
raise_getopt_errs
=
0
)
else
:
opts
.
realize
()
handlers
.
handleConfig
(
opts
.
configroot
,
opts
.
confighandlers
)
handlers
.
handle
WSGI
Config
(
opts
.
configroot
,
opts
.
confighandlers
)
import
App.config
App
.
config
.
setConfiguration
(
opts
.
configroot
)
return
opts
...
...
@@ -54,17 +58,15 @@ def _setconfig(configfile=None):
def
make_wsgi_app
(
global_config
,
zope_conf
):
from
App.config
import
setConfiguration
from
Zope2.Startup
import
get_starter
from
Zope2.Startup.handlers
import
handleConfig
from
Zope2.Startup.options
import
ZopeOptions
from
Zope2.Startup
import
get_
wsgi_
starter
from
Zope2.Startup.handlers
import
handle
WSGI
Config
from
Zope2.Startup.options
import
Zope
WSGI
Options
from
ZPublisher.WSGIPublisher
import
publish_module
starter
=
get_
starter
(
wsgi
=
True
)
opts
=
ZopeOptions
()
starter
=
get_
wsgi_starter
(
)
opts
=
Zope
WSGI
Options
()
opts
.
configfile
=
zope_conf
if
opts
.
schemafile
==
'zopeschema.xml'
:
opts
.
schemafile
=
'wsgischema.xml'
opts
.
realize
(
args
=
(),
progname
=
'Zope2WSGI'
,
raise_getopt_errs
=
False
)
handleConfig
(
opts
.
configroot
,
opts
.
confighandlers
)
handle
WSGI
Config
(
opts
.
configroot
,
opts
.
confighandlers
)
setConfiguration
(
opts
.
configroot
)
starter
.
setConfiguration
(
opts
.
configroot
)
starter
.
prepare
()
...
...
src/Zope2/Startup/starter.py
View file @
95d7a661
...
...
@@ -99,7 +99,7 @@ class WSGIStarter(object):
def
startZope
(
self
):
# Import Zope
import
Zope2
Zope2
.
startup
()
Zope2
.
startup
_wsgi
()
def
_name_to_ips
(
host
,
_is_ip
=
re
.
compile
(
r'(\
d+
\.){3}'
).
match
):
...
...
src/Zope2/Startup/tests/test_schema.py
View file @
95d7a661
...
...
@@ -19,7 +19,7 @@ import unittest
import
ZConfig
from
Zope2.Startup.options
import
ZopeOptions
from
Zope2.Startup.options
import
Zope
WSGI
Options
_SCHEMA
=
{}
TEMPNAME
=
tempfile
.
mktemp
()
...
...
@@ -29,7 +29,7 @@ TEMPVAR = os.path.join(TEMPNAME, "var")
def
getSchema
(
schemafile
):
global
_SCHEMA
if
schemafile
not
in
_SCHEMA
:
opts
=
ZopeOptions
()
opts
=
Zope
WSGI
Options
()
opts
.
schemafile
=
schemafile
opts
.
load_schema
()
_SCHEMA
[
schemafile
]
=
opts
.
schema
...
...
src/Zope2/Startup/tests/test_starter.py
View file @
95d7a661
...
...
@@ -21,8 +21,8 @@ import unittest
import
ZConfig
from
Zope2.Startup
import
get_starter
from
Zope2.Startup.options
import
ZopeOptions
from
Zope2.Startup
import
get_
wsgi_
starter
from
Zope2.Startup.options
import
Zope
WSGI
Options
_SCHEMA
=
None
...
...
@@ -30,7 +30,7 @@ _SCHEMA = None
def
getSchema
(
schemafile
):
global
_SCHEMA
if
_SCHEMA
is
None
:
opts
=
ZopeOptions
()
opts
=
Zope
WSGI
Options
()
opts
.
schemafile
=
schemafile
opts
.
load_schema
()
_SCHEMA
=
opts
.
schema
...
...
@@ -50,7 +50,7 @@ class WSGIStarterTestCase(unittest.TestCase):
shutil
.
rmtree
(
self
.
TEMPNAME
)
def
get_starter
(
self
,
conf
):
starter
=
get_
starter
(
wsgi
=
True
)
starter
=
get_
wsgi_starter
(
)
starter
.
setConfiguration
(
conf
)
return
starter
...
...
src/Zope2/Startup/wsgischema.xml
View file @
95d7a661
<schema
prefix=
"Zope2.Startup.datatypes"
datatype=
".root_config"
handler=
"root_handler"
>
datatype=
".root_
wsgi_
config"
handler=
"root_
wsgi_
handler"
>
<!-- type definitions -->
<import
package=
"ZConfig.components.logger"
file=
"handlers.xml"
/>
<import
package=
"ZConfig.components.logger"
file=
"eventlog.xml"
/>
<import
package=
"ZODB"
/>
<sectiontype
name=
"logger"
datatype=
".LoggerFactory"
>
<description>
This "logger" type only applies to access and request ("trace")
logging; event logging is handled by the "logging" package in
the Python standard library. The loghandler type used here is
provided by the "ZConfig.components.logger" package.
</description>
<key
name=
"level"
datatype=
"ZConfig.components.logger.datatypes.logging_level"
default=
"info"
/>
<multisection
name=
"*"
type=
"ZConfig.logger.handler"
attribute=
"handlers"
required=
"yes"
/>
</sectiontype>
<sectiontype
name=
"environment"
datatype=
".
cgi_
environment"
datatype=
".environment"
keytype=
"identifier"
>
<description>
A section which allows you to define simple key-value pairs which
...
...
@@ -271,43 +253,6 @@
<metadefault>
off
</metadefault>
</key>
<section
type=
"eventlog"
name=
"*"
attribute=
"eventlog"
>
<description>
Describes what level of log output is desired and where it
should be written.
</description>
</section>
<section
type=
"logger"
name=
"access"
>
<description>
Describes the logging performed to capture the 'access' log,
which typically captures per-request data in common or combined
log format.
</description>
</section>
<section
type=
"logger"
name=
"trace"
>
<description>
Describes the logging performed to capture the 'trace' log,
which typically captures detailed per-request data useful for
Zope debugging.
</description>
</section>
<key
name=
"conflict-error-log-level"
datatype=
"ZConfig.components.logger.datatypes.logging_level"
default=
"info"
>
<description>
Specifies at which level conflict errors are logged. Conflict
errors, when occurring in small numbers, are a normal part of the
Zope optimistic transaction conflict resolution algorithms. They
are retried automatically a few times, and are therefore usually
not visible by the user. You can specify 'notset' if you don't
want them logged, or use any other logger level.
</description>
<metadefault>
info
</metadefault>
</key>
<multisection
type=
"ZODB.Database"
name=
"+"
attribute=
"databases"
>
<description>
Zope ZODB databases must have a name, and they are required to be
...
...
src/Zope2/Startup/zopeschema.xml
deleted
100644 → 0
View file @
519ca223
This diff is collapsed.
Click to expand it.
src/Zope2/__init__.py
View file @
95d7a661
...
...
@@ -15,42 +15,53 @@
import
os
from
Zope2.Startup.run
import
configure
from
zope.deferredimport
import
deprecated
# BBB Zope 5.0
deprecated
(
'Please import from ZServer.Zope2.'
,
startup
=
'ZServer.Zope2:startup'
,
_configure
=
'ZServer.Zope2:_configure'
,
)
deprecated
(
'Please import from ZServer.Zope2.Startup.run.'
,
configure
=
'ZServer.Zope2.Startup.run:configure'
,
)
_began_startup
=
0
def
startup
():
def
startup
_wsgi
():
"""Initialize the Zope Package and provide a published module"""
global
_began_startup
if
_began_startup
:
# Already began (and maybe finished) startup, so don't run again
return
_began_startup
=
1
_configure
()
_configure
_wsgi
()
from
Zope2.App.startup
import
startup
as
_startup
_startup
()
def
app
(
*
args
,
**
kw
):
"""Utility for scripts to open a connection to the database"""
startup
()
startup
_wsgi
()
return
bobo_application
(
*
args
,
**
kw
)
def
debug
(
*
args
,
**
kw
):
"""Utility to try a Zope request using the interactive interpreter"""
startup
()
startup
_wsgi
()
import
ZPublisher
return
ZPublisher
.
test
(
'Zope2'
,
*
args
,
**
kw
)
def
_configure
():
# Load configuration file from (optional) environment variable
# Also see http://zope.org/Collectors/Zope/1233
def
_configure_wsgi
():
from
Zope2.Startup.run
import
configure_wsgi
configfile
=
os
.
environ
.
get
(
'ZOPE_CONFIG'
)
if
configfile
is
not
None
:
configure
(
configfile
)
configure
_wsgi
(
configfile
)
# Zope2.App.startup.startup() sets the following variables in this module.
...
...
src/Zope2/utilities/finder.py
View file @
95d7a661
...
...
@@ -30,20 +30,20 @@ class ZopeFinder(object):
from
Zope2.Startup
import
options
,
handlers
import
App.config
import
Zope2
opts
=
options
.
ZopeOptions
()
opts
=
options
.
Zope
WSGI
Options
()
opts
.
configfile
=
config_file
opts
.
realize
(
args
=
[],
doc
=
""
,
raise_getopt_errs
=
0
)
handlers
.
handleConfig
(
opts
.
configroot
,
opts
.
confighandlers
)
handlers
.
handle
WSGI
Config
(
opts
.
configroot
,
opts
.
confighandlers
)
App
.
config
.
setConfiguration
(
opts
.
configroot
)
app
=
Zope2
.
app
()
return
app
def
get_zope_conf
(
self
):
# the default config file path is assumed to live in
# $instance_home/etc/
zope
.conf, and the console scripts that use this
# $instance_home/etc/
wsgi
.conf, and the console scripts that use this
# are assumed to live in $instance_home/bin; override if the
# environ contains "ZOPE_CONF".
ihome
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
os
.
path
.
dirname
(
self
.
cmd
)))
default_config_file
=
os
.
path
.
join
(
ihome
,
'etc'
,
'
zope
.conf'
)
default_config_file
=
os
.
path
.
join
(
ihome
,
'etc'
,
'
wsgi
.conf'
)
zope_conf
=
os
.
environ
.
get
(
'ZOPE_CONF'
,
default_config_file
)
return
zope_conf
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment