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
cea2d056
Commit
cea2d056
authored
Sep 04, 2016
by
Hanno Schlichting
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplified `ZPublisher.WSGIPublisher.get_module_info` contract.
parent
f86588ef
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
23 additions
and
98 deletions
+23
-98
CHANGES.rst
CHANGES.rst
+2
-0
src/ZPublisher/WSGIPublisher.py
src/ZPublisher/WSGIPublisher.py
+13
-51
src/ZPublisher/tests/test_WSGIPublisher.py
src/ZPublisher/tests/test_WSGIPublisher.py
+3
-20
src/ZPublisher/tests/test_pubevents.py
src/ZPublisher/tests/test_pubevents.py
+0
-13
src/Zope2/App/startup.py
src/Zope2/App/startup.py
+0
-3
src/Zope2/__init__.py
src/Zope2/__init__.py
+5
-11
No files found.
CHANGES.rst
View file @
cea2d056
...
...
@@ -31,6 +31,8 @@ Features Added
Restructuring
+++++++++++++
- Simplified `ZPublisher.WSGIPublisher.get_module_info` contract.
- Add new `ZPublisher.utils.recordMetaData` function and use default
`transaction.manager` as the transaction manager.
...
...
src/ZPublisher/WSGIPublisher.py
View file @
cea2d056
...
...
@@ -100,27 +100,10 @@ def get_module_info(module_name='Zope2'):
return
info
with
_MODULE_LOCK
:
g
=
globals
()
module
=
__import__
(
module_name
,
g
,
g
,
(
'__doc__'
,))
# Let the app specify a realm
realm
=
module_name
if
_DEFAULT_REALM
is
not
None
:
realm
=
_DEFAULT_REALM
module
=
__import__
(
module_name
)
app
=
getattr
(
module
,
'bobo_application'
,
module
)
bobo_before
=
getattr
(
module
,
'__bobo_before__'
,
None
)
bobo_after
=
getattr
(
module
,
'__bobo_after__'
,
None
)
error_hook
=
getattr
(
module
,
'zpublisher_exception_hook'
,
None
)
validated_hook
=
getattr
(
module
,
'zpublisher_validated_hook'
,
validate_user
)
transactions_manager
=
getattr
(
module
,
'zpublisher_transactions_manager'
,
transaction
.
manager
)
info
=
(
bobo_before
,
bobo_after
,
app
,
realm
,
_DEFAULT_DEBUG_MODE
,
error_hook
,
validated_hook
,
transactions_manager
)
_MODULES
[
module_name
]
=
info
realm
=
_DEFAULT_REALM
if
_DEFAULT_REALM
is
not
None
else
module_name
_MODULES
[
module_name
]
=
info
=
(
app
,
realm
,
_DEFAULT_DEBUG_MODE
)
return
info
...
...
@@ -206,7 +189,7 @@ class WSGIResponse(HTTPResponse):
@
contextmanager
def
transaction_pubevents
(
tm
,
request
):
def
transaction_pubevents
(
request
,
tm
=
transaction
.
manager
):
ok_exception
=
None
try
:
setDefaultSkin
(
request
)
...
...
@@ -239,21 +222,11 @@ def transaction_pubevents(tm, request):
def
publish
(
request
,
module_info
):
(
bobo_before
,
bobo_after
,
obj
,
realm
,
debug_mode
,
err_hook
,
validated_hook
,
transactions_manager
)
=
module_info
obj
,
realm
,
debug_mode
=
module_info
request
.
processInputs
()
response
=
request
.
response
if
bobo_after
is
not
None
:
response
.
after_list
+=
(
bobo_after
,)
if
debug_mode
:
response
.
debug_mode
=
debug_mode
...
...
@@ -261,15 +234,13 @@ def publish(request, module_info):
response
.
realm
=
realm
noSecurityManager
()
if
bobo_before
is
not
None
:
bobo_before
()
# Get the path list.
# According to RFC1738 a trailing space in the path is valid.
path
=
request
.
get
(
'PATH_INFO'
)
request
[
'PARENTS'
]
=
[
obj
]
obj
=
request
.
traverse
(
path
,
validated_hook
=
validate
d_hook
)
obj
=
request
.
traverse
(
path
,
validated_hook
=
validate
_user
)
notify
(
pubevents
.
PubAfterTraversal
(
request
))
recordMetaData
(
obj
,
request
)
...
...
@@ -294,31 +265,22 @@ def publish_module(environ, start_response,
_response_factory
=
WSGIResponse
,
_request
=
None
,
_request_factory
=
WSGIRequest
,
_module_name
=
'Zope2'
,
):
module_info
=
get_module_info
(
_module_name
)
transactions_manager
=
module_info
[
7
]
_module_name
=
'Zope2'
):
status
=
200
with
closing
(
StringIO
())
as
stdout
,
closing
(
StringIO
())
as
stderr
:
if
_response
is
None
:
response
=
_response_factory
(
stdout
=
stdout
,
stderr
=
stderr
)
else
:
response
=
_response
response
=
(
_response
if
_response
is
not
None
else
_response_factory
(
stdout
=
stdout
,
stderr
=
stderr
))
response
.
_http_version
=
environ
[
'SERVER_PROTOCOL'
].
split
(
'/'
)[
1
]
response
.
_server_version
=
environ
.
get
(
'SERVER_SOFTWARE'
)
if
_request
is
None
:
request
=
_request_factory
(
environ
[
'wsgi.input'
],
environ
,
response
)
else
:
request
=
_request
request
=
(
_request
if
_request
is
not
None
else
_request_factory
(
environ
[
'wsgi.input'
],
environ
,
response
))
with
closing
(
request
)
as
request
:
try
:
with
transaction_pubevents
(
transactions_manager
,
request
):
response
=
_publish
(
request
,
module_info
)
with
transaction_pubevents
(
request
):
response
=
_publish
(
request
,
get_module_info
(
_module_name
)
)
except
Unauthorized
:
response
.
_unauthorized
()
except
HTTPRedirection
as
exc
:
...
...
src/ZPublisher/tests/test_WSGIPublisher.py
View file @
cea2d056
...
...
@@ -155,47 +155,30 @@ class TestPublish(unittest.TestCase):
def
test_wo_REMOTE_USER
(
self
):
request
=
DummyRequest
(
PATH_INFO
=
'/'
)
response
=
request
.
response
=
DummyResponse
()
_before
=
DummyCallable
()
_after
=
object
()
_object
=
DummyCallable
()
_object
.
_result
=
'RESULT'
request
.
_traverse_to
=
_object
_realm
=
'TESTING'
_debug_mode
=
True
_err_hook
=
DummyCallable
()
_validated_hook
=
object
()
_tm
=
transaction
.
manager
module_info
=
(
_before
,
_after
,
_object
,
_realm
,
_debug_mode
,
_err_hook
,
_validated_hook
,
_tm
)
returned
=
self
.
_callFUT
(
request
,
module_info
)
returned
=
self
.
_callFUT
(
request
,
(
_object
,
_realm
,
_debug_mode
))
self
.
assertTrue
(
returned
is
response
)
self
.
assertTrue
(
request
.
_processedInputs
)
self
.
assertEqual
(
response
.
after_list
,
(
_after
,))
self
.
assertTrue
(
response
.
debug_mode
)
self
.
assertEqual
(
response
.
realm
,
'TESTING'
)
self
.
assertEqual
(
_before
.
_called_with
,
((),
{}))
self
.
assertEqual
(
request
[
'PARENTS'
],
[
_object
])
self
.
assertEqual
(
request
.
_traversed
,
(
'/'
,
None
,
_validated_hook
))
self
.
assertEqual
(
request
.
_traversed
[:
2
],
(
'/'
,
None
))
self
.
assertEqual
(
_object
.
_called_with
,
((),
{}))
self
.
assertEqual
(
response
.
_body
,
'RESULT'
)
self
.
assertEqual
(
_err_hook
.
_called_with
,
None
)
def
test_w_REMOTE_USER
(
self
):
request
=
DummyRequest
(
PATH_INFO
=
'/'
,
REMOTE_USER
=
'phred'
)
response
=
request
.
response
=
DummyResponse
()
_before
=
DummyCallable
()
_after
=
object
()
_object
=
DummyCallable
()
_object
.
_result
=
'RESULT'
request
.
_traverse_to
=
_object
_realm
=
'TESTING'
_debug_mode
=
True
_err_hook
=
DummyCallable
()
_validated_hook
=
object
()
_tm
=
transaction
.
manager
module_info
=
(
_before
,
_after
,
_object
,
_realm
,
_debug_mode
,
_err_hook
,
_validated_hook
,
_tm
)
self
.
_callFUT
(
request
,
module_info
)
self
.
_callFUT
(
request
,
(
_object
,
_realm
,
_debug_mode
))
self
.
assertEqual
(
response
.
realm
,
None
)
...
...
src/ZPublisher/tests/test_pubevents.py
View file @
cea2d056
...
...
@@ -17,7 +17,6 @@ from ZPublisher.interfaces import (
IPubAfterTraversal
,
IPubBeforeCommit
,
IPubBeforeStreaming
,
)
from
ZPublisher
import
Retry
from
ZPublisher.WSGIPublisher
import
publish_module
from
ZPublisher.WSGIPublisher
import
WSGIResponse
...
...
@@ -202,17 +201,5 @@ class _Request(BaseRequest):
# override to get rid of the 'EndRequestEvent' notification
pass
# define things necessary for publication
bobo_application
=
_Application
()
def
zpublisher_exception_hook
(
parent
,
request
,
*
unused
):
action
=
request
.
action
if
action
==
'fail_return'
:
return
0
if
action
==
'fail_exception'
:
raise
Exception
()
if
action
==
'conflict'
:
raise
Retry
()
raise
ValueError
(
'unknown action: %s'
%
action
)
src/Zope2/App/startup.py
View file @
cea2d056
...
...
@@ -20,7 +20,6 @@ from time import asctime
import
AccessControl.User
from
AccessControl.SecurityManagement
import
newSecurityManager
from
AccessControl.SecurityManagement
import
noSecurityManager
import
transaction
import
ZODB
from
zope.deferredimport
import
deprecated
from
zope.event
import
notify
...
...
@@ -152,5 +151,3 @@ def startup():
startup_time
=
asctime
()
notify
(
DatabaseOpenedWithRoot
(
DB
))
Zope2
.
zpublisher_transactions_manager
=
transaction
.
manager
src/Zope2/__init__.py
View file @
cea2d056
...
...
@@ -31,6 +31,11 @@ deprecated(
_began_startup
=
0
# Zope2.App.startup.startup() sets the following variables in this module.
bobo_application
=
None
DB
=
None
opened
=
[]
def
startup_wsgi
():
"""Initialize the Zope Package and provide a published module"""
...
...
@@ -62,14 +67,3 @@ def _configure_wsgi():
configfile
=
os
.
environ
.
get
(
'ZOPE_CONFIG'
)
if
configfile
is
not
None
:
configure_wsgi
(
configfile
)
# Zope2.App.startup.startup() sets the following variables in this module.
DB
=
None
opened
=
[]
bobo_application
=
None
zpublisher_transactions_manager
=
None
zpublisher_validated_hook
=
None
zpublisher_exception_hook
=
None
__bobo_after__
=
None
__bobo_before__
=
None
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