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
4ad8ac12
Commit
4ad8ac12
authored
Mar 26, 2010
by
Martin Aspeli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge c105589 from 2.12 branch, adding IPubBeforeAbort event
parent
1b105b23
Changes
5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
643 additions
and
126 deletions
+643
-126
doc/CHANGES.rst
doc/CHANGES.rst
+591
-113
src/ZPublisher/Publish.py
src/ZPublisher/Publish.py
+8
-1
src/ZPublisher/interfaces.py
src/ZPublisher/interfaces.py
+8
-1
src/ZPublisher/pubevents.py
src/ZPublisher/pubevents.py
+8
-1
src/ZPublisher/tests/testpubevents.py
src/ZPublisher/tests/testpubevents.py
+28
-10
No files found.
doc/CHANGES.rst
View file @
4ad8ac12
This diff is collapsed.
Click to expand it.
src/ZPublisher/Publish.py
View file @
4ad8ac12
...
...
@@ -27,7 +27,7 @@ from zope.security.management import newInteraction, endInteraction
from
zope.event
import
notify
from
pubevents
import
PubStart
,
PubSuccess
,
PubFailure
,
\
PubBeforeCommit
,
PubAfterTraversal
PubBeforeCommit
,
PubAfterTraversal
,
PubBeforeAbort
class
Retry
(
Exception
):
"""Raise this to retry a request
...
...
@@ -173,8 +173,12 @@ def publish(request, module_name, after_list, debug=0,
)
retry
=
True
finally
:
# Note: 'abort's can fail. Nevertheless, we want end request handling
try
:
notify
(
PubBeforeAbort
(
request
,
exc_info
,
retry
))
if
transactions_manager
:
transactions_manager
.
abort
()
finally
:
...
...
@@ -196,6 +200,9 @@ def publish(request, module_name, after_list, debug=0,
else
:
# Note: 'abort's can fail. Nevertheless, we want end request handling
try
:
notify
(
PubBeforeAbort
(
request
,
exc_info
,
False
))
if
transactions_manager
:
transactions_manager
.
abort
()
finally
:
...
...
src/ZPublisher/interfaces.py
View file @
4ad8ac12
...
...
@@ -41,5 +41,12 @@ class IPubAfterTraversal(IPubEvent):
class
IPubBeforeCommit
(
IPubEvent
):
"""notified immediately before the transaction commit (i.e. after the main
request processing is finished.
request processing is finished
)
.
"""
class
IPubBeforeAbort
(
IPubEvent
):
"""notified immediately before the transaction abort (i.e. after the main
request processing is finished, and there was an error).
"""
exc_info
=
Attribute
(
'''The exception info as returned by 'sys.exc_info()'.'''
)
retry
=
Attribute
(
'Whether the request will be retried'
)
src/ZPublisher/pubevents.py
View file @
4ad8ac12
...
...
@@ -10,7 +10,7 @@ for detailed time related analysis, inline request monitoring.
from
zope.interface
import
implements
from
interfaces
import
IPubStart
,
IPubSuccess
,
IPubFailure
,
\
IPubAfterTraversal
,
IPubBeforeCommit
IPubAfterTraversal
,
IPubBeforeCommit
,
IPubBeforeAbort
class
_Base
(
object
):
"""PubEvent base class."""
...
...
@@ -42,3 +42,10 @@ class PubAfterTraversal(_Base):
class
PubBeforeCommit
(
_Base
):
"""notified immediately before the commit."""
implements
(
IPubBeforeCommit
)
class
PubBeforeAbort
(
_Base
):
"""notified immediately before an abort."""
implements
(
IPubBeforeAbort
)
def
__init__
(
self
,
request
,
exc_info
,
retry
):
self
.
request
,
self
.
exc_info
,
self
.
retry
=
request
,
exc_info
,
retry
src/ZPublisher/tests/testpubevents.py
View file @
4ad8ac12
...
...
@@ -8,7 +8,7 @@ from zope.event import subscribers
from
ZPublisher.Publish
import
publish
,
Retry
from
ZPublisher.BaseRequest
import
BaseRequest
from
ZPublisher.pubevents
import
PubStart
,
PubSuccess
,
PubFailure
,
\
PubAfterTraversal
,
PubBeforeCommit
PubAfterTraversal
,
PubBeforeCommit
,
PubBeforeAbort
from
ZPublisher.interfaces
import
\
IPubStart
,
IPubEnd
,
IPubSuccess
,
IPubFailure
,
\
IPubAfterTraversal
,
IPubBeforeCommit
...
...
@@ -74,40 +74,58 @@ class TestPubEvents(TestCase):
r
=
self
.
request
;
r
.
action
=
'fail_return'
publish
(
r
,
PUBMODULE
,
[
None
])
events
=
self
.
reporter
.
events
self
.
assertEqual
(
len
(
events
),
2
)
self
.
assertEqual
(
len
(
events
),
3
)
self
.
assert_
(
isinstance
(
events
[
0
],
PubStart
))
self
.
assertEqual
(
events
[
0
].
request
,
r
)
self
.
assert_
(
isinstance
(
events
[
1
],
Pub
Failure
))
self
.
assert_
(
isinstance
(
events
[
1
],
Pub
BeforeAbort
))
self
.
assertEqual
(
events
[
1
].
request
,
r
)
self
.
assertEqual
(
events
[
1
].
retry
,
False
)
self
.
assertEqual
(
len
(
events
[
1
].
exc_info
),
3
)
self
.
assert_
(
isinstance
(
events
[
2
],
PubFailure
))
self
.
assertEqual
(
events
[
2
].
request
,
r
)
self
.
assertEqual
(
events
[
2
].
retry
,
False
)
self
.
assertEqual
(
len
(
events
[
2
].
exc_info
),
3
)
def
testFailureException
(
self
):
r
=
self
.
request
;
r
.
action
=
'fail_exception'
self
.
assertRaises
(
Exception
,
publish
,
r
,
PUBMODULE
,
[
None
])
events
=
self
.
reporter
.
events
self
.
assertEqual
(
len
(
events
),
2
)
self
.
assertEqual
(
len
(
events
),
3
)
self
.
assert_
(
isinstance
(
events
[
0
],
PubStart
))
self
.
assertEqual
(
events
[
0
].
request
,
r
)
self
.
assert_
(
isinstance
(
events
[
1
],
Pub
Failure
))
self
.
assert_
(
isinstance
(
events
[
1
],
Pub
BeforeAbort
))
self
.
assertEqual
(
events
[
1
].
request
,
r
)
self
.
assertEqual
(
events
[
1
].
retry
,
False
)
self
.
assertEqual
(
len
(
events
[
1
].
exc_info
),
3
)
self
.
assert_
(
isinstance
(
events
[
2
],
PubFailure
))
self
.
assertEqual
(
events
[
2
].
request
,
r
)
self
.
assertEqual
(
events
[
2
].
retry
,
False
)
self
.
assertEqual
(
len
(
events
[
2
].
exc_info
),
3
)
def
testFailureConflict
(
self
):
r
=
self
.
request
;
r
.
action
=
'conflict'
publish
(
r
,
PUBMODULE
,
[
None
])
events
=
self
.
reporter
.
events
self
.
assertEqual
(
len
(
events
),
6
)
self
.
assertEqual
(
len
(
events
),
7
)
self
.
assert_
(
isinstance
(
events
[
0
],
PubStart
))
self
.
assertEqual
(
events
[
0
].
request
,
r
)
self
.
assert_
(
isinstance
(
events
[
1
],
PubFailure
))
self
.
assert_
(
isinstance
(
events
[
1
],
PubBeforeAbort
))
self
.
assertEqual
(
events
[
1
].
request
,
r
)
self
.
assertEqual
(
events
[
1
].
retry
,
True
)
self
.
assertEqual
(
len
(
events
[
1
].
exc_info
),
3
)
self
.
assert_
(
isinstance
(
events
[
1
].
exc_info
[
1
],
ConflictError
))
self
.
assert_
(
isinstance
(
events
[
2
],
PubStart
))
self
.
assert_
(
isinstance
(
events
[
5
],
PubSuccess
))
self
.
assert_
(
isinstance
(
events
[
2
],
PubFailure
))
self
.
assertEqual
(
events
[
2
].
request
,
r
)
self
.
assertEqual
(
events
[
2
].
retry
,
True
)
self
.
assertEqual
(
len
(
events
[
2
].
exc_info
),
3
)
self
.
assert_
(
isinstance
(
events
[
2
].
exc_info
[
1
],
ConflictError
))
self
.
assert_
(
isinstance
(
events
[
3
],
PubStart
))
self
.
assert_
(
isinstance
(
events
[
4
],
PubAfterTraversal
))
self
.
assert_
(
isinstance
(
events
[
5
],
PubBeforeCommit
))
self
.
assert_
(
isinstance
(
events
[
6
],
PubSuccess
))
# Auxiliaries
def
_succeed
():
...
...
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