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
a1f87de3
Commit
a1f87de3
authored
Jul 22, 2016
by
Hanno Schlichting
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Try to maintain more pubevents parity in WSGIPublisher.
Based on
https://gist.github.com/optilude/1548061
.
parent
2cd17f64
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
24 deletions
+38
-24
src/ZPublisher/Publish.py
src/ZPublisher/Publish.py
+10
-14
src/ZPublisher/WSGIPublisher.py
src/ZPublisher/WSGIPublisher.py
+28
-10
No files found.
src/ZPublisher/Publish.py
View file @
a1f87de3
...
@@ -26,12 +26,7 @@ from zope.security.management import newInteraction, endInteraction
...
@@ -26,12 +26,7 @@ from zope.security.management import newInteraction, endInteraction
from
.mapply
import
mapply
from
.mapply
import
mapply
from
.maybe_lock
import
allocate_lock
from
.maybe_lock
import
allocate_lock
from
.pubevents
import
PubAfterTraversal
from
ZPublisher
import
pubevents
from
.pubevents
import
PubBeforeAbort
from
.pubevents
import
PubBeforeCommit
from
.pubevents
import
PubFailure
from
.pubevents
import
PubStart
from
.pubevents
import
PubSuccess
from
.Request
import
Request
from
.Request
import
Request
from
.Response
import
Response
from
.Response
import
Response
...
@@ -87,7 +82,7 @@ def publish(request, module_name, after_list, debug=0,
...
@@ -87,7 +82,7 @@ def publish(request, module_name, after_list, debug=0,
response
=
None
response
=
None
try
:
try
:
notify
(
PubStart
(
request
))
notify
(
pubevents
.
PubStart
(
request
))
# TODO pass request here once BaseRequest implements IParticipation
# TODO pass request here once BaseRequest implements IParticipation
newInteraction
()
newInteraction
()
...
@@ -135,7 +130,7 @@ def publish(request, module_name, after_list, debug=0,
...
@@ -135,7 +130,7 @@ def publish(request, module_name, after_list, debug=0,
if
IBrowserPage
.
providedBy
(
object
):
if
IBrowserPage
.
providedBy
(
object
):
request
.
postProcessInputs
()
request
.
postProcessInputs
()
notify
(
PubAfterTraversal
(
request
))
notify
(
pubevents
.
PubAfterTraversal
(
request
))
if
transactions_manager
:
if
transactions_manager
:
transactions_manager
.
recordMetaData
(
object
,
request
)
transactions_manager
.
recordMetaData
(
object
,
request
)
...
@@ -149,13 +144,13 @@ def publish(request, module_name, after_list, debug=0,
...
@@ -149,13 +144,13 @@ def publish(request, module_name, after_list, debug=0,
if
result
is
not
response
:
if
result
is
not
response
:
response
.
setBody
(
result
)
response
.
setBody
(
result
)
notify
(
PubBeforeCommit
(
request
))
notify
(
pubevents
.
PubBeforeCommit
(
request
))
if
transactions_manager
:
if
transactions_manager
:
transactions_manager
.
commit
()
transactions_manager
.
commit
()
endInteraction
()
endInteraction
()
notify
(
PubSuccess
(
request
))
notify
(
pubevents
.
PubSuccess
(
request
))
return
response
return
response
except
:
except
:
...
@@ -197,13 +192,14 @@ def publish(request, module_name, after_list, debug=0,
...
@@ -197,13 +192,14 @@ def publish(request, module_name, after_list, debug=0,
# Note: 'abort's can fail. Nevertheless, we want end request handling
# Note: 'abort's can fail. Nevertheless, we want end request handling
try
:
try
:
try
:
try
:
notify
(
PubBeforeAbort
(
request
,
exc_info
,
retry
))
notify
(
pubevents
.
PubBeforeAbort
(
request
,
exc_info
,
retry
))
finally
:
finally
:
if
transactions_manager
:
if
transactions_manager
:
transactions_manager
.
abort
()
transactions_manager
.
abort
()
finally
:
finally
:
endInteraction
()
endInteraction
()
notify
(
PubFailure
(
request
,
exc_info
,
retry
))
notify
(
pubevents
.
PubFailure
(
request
,
exc_info
,
retry
))
# Only reachable if Retry is raised and request supports retry.
# Only reachable if Retry is raised and request supports retry.
newrequest
=
request
.
retry
()
newrequest
=
request
.
retry
()
...
@@ -221,13 +217,13 @@ def publish(request, module_name, after_list, debug=0,
...
@@ -221,13 +217,13 @@ def publish(request, module_name, after_list, debug=0,
# Note: 'abort's can fail. Nevertheless, we want end request handling
# Note: 'abort's can fail. Nevertheless, we want end request handling
try
:
try
:
try
:
try
:
notify
(
PubBeforeAbort
(
request
,
exc_info
,
False
))
notify
(
pubevents
.
PubBeforeAbort
(
request
,
exc_info
,
False
))
finally
:
finally
:
if
transactions_manager
:
if
transactions_manager
:
transactions_manager
.
abort
()
transactions_manager
.
abort
()
finally
:
finally
:
endInteraction
()
endInteraction
()
notify
(
PubFailure
(
request
,
exc_info
,
False
))
notify
(
pubevents
.
PubFailure
(
request
,
exc_info
,
False
))
raise
raise
def
publish_module_standard
(
module_name
,
def
publish_module_standard
(
module_name
,
...
...
src/ZPublisher/WSGIPublisher.py
View file @
a1f87de3
...
@@ -13,6 +13,7 @@
...
@@ -13,6 +13,7 @@
""" Python Object Publisher -- Publish Python objects on web servers
""" Python Object Publisher -- Publish Python objects on web servers
"""
"""
from
cStringIO
import
StringIO
from
cStringIO
import
StringIO
import
sys
import
time
import
time
import
transaction
import
transaction
...
@@ -26,12 +27,11 @@ from ZServer.medusa.http_date import build_http_date
...
@@ -26,12 +27,11 @@ from ZServer.medusa.http_date import build_http_date
from
ZPublisher.HTTPRequest
import
HTTPRequest
from
ZPublisher.HTTPRequest
import
HTTPRequest
from
ZPublisher.HTTPResponse
import
HTTPResponse
from
ZPublisher.HTTPResponse
import
HTTPResponse
from
ZPublisher.mapply
import
mapply
from
ZPublisher.mapply
import
mapply
from
ZPublisher
.pubevents
import
PubBeforeStreaming
from
ZPublisher
import
pubevents
from
ZPublisher.Publish
import
call_object
from
ZPublisher.Publish
import
call_object
from
ZPublisher.Publish
import
dont_publish_class
from
ZPublisher.Publish
import
dont_publish_class
from
ZPublisher.Publish
import
get_module_info
from
ZPublisher.Publish
import
get_module_info
from
ZPublisher.Publish
import
missing_name
from
ZPublisher.Publish
import
missing_name
from
ZPublisher.pubevents
import
PubStart
,
PubBeforeCommit
,
PubAfterTraversal
from
ZPublisher.Iterators
import
IUnboundStreamIterator
,
IStreamIterator
from
ZPublisher.Iterators
import
IUnboundStreamIterator
,
IStreamIterator
_NOW
=
None
# overwrite for testing
_NOW
=
None
# overwrite for testing
...
@@ -99,7 +99,7 @@ class WSGIResponse(HTTPResponse):
...
@@ -99,7 +99,7 @@ class WSGIResponse(HTTPResponse):
computation of a response to proceed.
computation of a response to proceed.
"""
"""
if
not
self
.
_streaming
:
if
not
self
.
_streaming
:
notify
(
PubBeforeStreaming
(
self
))
notify
(
pubevents
.
PubBeforeStreaming
(
self
))
self
.
_streaming
=
1
self
.
_streaming
=
1
self
.
stdout
.
flush
()
self
.
stdout
.
flush
()
...
@@ -139,7 +139,7 @@ def publish(request, module_name,
...
@@ -139,7 +139,7 @@ def publish(request, module_name,
transactions_manager
,
transactions_manager
,
)
=
_get_module_info
(
module_name
)
)
=
_get_module_info
(
module_name
)
notify
(
PubStart
(
request
))
notify
(
pubevents
.
PubStart
(
request
))
newInteraction
()
newInteraction
()
try
:
try
:
request
.
processInputs
()
request
.
processInputs
()
...
@@ -163,7 +163,7 @@ def publish(request, module_name,
...
@@ -163,7 +163,7 @@ def publish(request, module_name,
request
[
'PARENTS'
]
=
[
object
]
request
[
'PARENTS'
]
=
[
object
]
object
=
request
.
traverse
(
path
,
validated_hook
=
validated_hook
)
object
=
request
.
traverse
(
path
,
validated_hook
=
validated_hook
)
notify
(
PubAfterTraversal
(
request
))
notify
(
pubevents
.
PubAfterTraversal
(
request
))
if
transactions_manager
:
if
transactions_manager
:
transactions_manager
.
recordMetaData
(
object
,
request
)
transactions_manager
.
recordMetaData
(
object
,
request
)
...
@@ -181,10 +181,11 @@ def publish(request, module_name,
...
@@ -181,10 +181,11 @@ def publish(request, module_name,
if
result
is
not
response
:
if
result
is
not
response
:
response
.
setBody
(
result
)
response
.
setBody
(
result
)
notify
(
pubevents
.
PubBeforeCommit
(
request
))
finally
:
finally
:
endInteraction
()
endInteraction
()
notify
(
PubBeforeCommit
(
request
))
return
response
return
response
...
@@ -209,10 +210,14 @@ class _RequestCloserForTransaction(object):
...
@@ -209,10 +210,14 @@ class _RequestCloserForTransaction(object):
def
afterCompletion
(
self
,
txn
):
def
afterCompletion
(
self
,
txn
):
request
=
self
.
requests
.
pop
(
txn
,
None
)
request
=
self
.
requests
.
pop
(
txn
,
None
)
if
request
is
not
None
:
if
request
is
not
None
:
if
txn
.
status
==
'Committed'
:
notify
(
pubevents
.
PubSuccess
(
request
))
request
.
close
()
request
.
close
()
_request_closer_for_repoze_tm
=
_RequestCloserForTransaction
()
_request_closer_for_repoze_tm
=
_RequestCloserForTransaction
()
def
publish_module
(
environ
,
start_response
,
def
publish_module
(
environ
,
start_response
,
_publish
=
publish
,
# only for testing
_publish
=
publish
,
# only for testing
_response_factory
=
WSGIResponse
,
# only for testing
_response_factory
=
WSGIResponse
,
# only for testing
...
@@ -235,9 +240,22 @@ def publish_module(environ, start_response,
...
@@ -235,9 +240,22 @@ def publish_module(environ, start_response,
setDefaultSkin
(
request
)
setDefaultSkin
(
request
)
try
:
try
:
try
:
response
=
_publish
(
request
,
'Zope2'
)
response
=
_publish
(
request
,
'Zope2'
)
except
Unauthorized
as
v
:
except
Exception
:
try
:
exc_info
=
sys
.
exc_info
()
notify
(
pubevents
.
PubBeforeAbort
(
request
,
exc_info
,
request
.
supports_retry
()))
# This should really be after transaction abort
notify
(
pubevents
.
PubFailure
(
request
,
exc_info
,
request
.
supports_retry
()))
finally
:
del
exc_info
raise
except
Unauthorized
:
response
.
_unauthorized
()
response
.
_unauthorized
()
except
Redirect
as
v
:
except
Redirect
as
v
:
response
.
redirect
(
v
)
response
.
redirect
(
v
)
...
@@ -257,7 +275,7 @@ def publish_module(environ, start_response,
...
@@ -257,7 +275,7 @@ def publish_module(environ, start_response,
result
=
(
stdout
.
getvalue
(),
response
.
body
)
result
=
(
stdout
.
getvalue
(),
response
.
body
)
if
'repoze.tm.active'
not
in
environ
:
if
'repoze.tm.active'
not
in
environ
:
request
.
close
()
# this aborts the transa
tion!
request
.
close
()
# this aborts the transac
tion!
stdout
.
close
()
stdout
.
close
()
...
...
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