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
462dbb4e
Commit
462dbb4e
authored
Oct 10, 2008
by
Sidnei da Silva
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Provide a helper function to upgrade a string exception to a real exception.
parent
6a5dfc32
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
14 deletions
+42
-14
lib/python/DocumentTemplate/DT_Raise.py
lib/python/DocumentTemplate/DT_Raise.py
+10
-4
lib/python/OFS/SimpleItem.py
lib/python/OFS/SimpleItem.py
+4
-9
lib/python/zExceptions/__init__.py
lib/python/zExceptions/__init__.py
+28
-1
No files found.
lib/python/DocumentTemplate/DT_Raise.py
View file @
462dbb4e
...
...
@@ -26,8 +26,12 @@
__rcs_id__
=
'$Id$'
__version__
=
'$Revision: 1.13 $'
[
11
:
-
2
]
from
zExceptions
import
upgradeException
from
DT_Util
import
parse_params
,
name_param
,
render_blocks
,
str
class
InvalidErrorTypeExpression
(
Exception
):
pass
class
Raise
:
blockContinuations
=
()
name
=
'raise'
...
...
@@ -44,15 +48,17 @@ class Raise:
expr
=
self
.
expr
if
expr
is
None
:
t
=
self
.
__name__
if
t
[
-
5
:]
==
'Error'
and
__builtins__
.
has_key
(
t
):
t
=
__builtins__
[
t
]
else
:
try
:
t
=
expr
.
eval
(
md
)
except
:
t
=
'Invalid Error Type Expression'
except
:
t
=
InvalidErrorTypeExpression
try
:
v
=
render_blocks
(
self
.
section
,
md
)
except
:
v
=
'Invalid Error Value'
# String Exceptions are deprecated on Python 2.5 and
# plain won't work at all on Python 2.6. So try to upgrade it
# to a real exception.
t
,
v
=
upgradeException
(
t
,
v
)
raise
t
,
v
__call__
=
render
lib/python/OFS/SimpleItem.py
View file @
462dbb4e
...
...
@@ -36,7 +36,7 @@ from DocumentTemplate.html_quote import html_quote
from
DocumentTemplate.ustr
import
ustr
from
ExtensionClass
import
Base
from
webdav.Resource
import
Resource
from
zExceptions
import
Redirect
,
InternalError
from
zExceptions
import
Redirect
,
upgradeException
from
zExceptions.ExceptionFormatter
import
format_exception
from
zope.interface
import
implements
...
...
@@ -185,15 +185,10 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable,
error_name
=
'Unknown'
if
isinstance
(
error_type
,
basestring
):
# String Exceptions are deprecated on Python 2.5 and
# plain won't work at all on Python 2.6. So upgrade it
# to an InternalError exception but keep the original
# exception in the value.
# plain won't work at all on Python 2.6. So try to upgrade it
# to a real exception.
error_name
=
error_type
error_type
=
InternalError
error_value
=
(
error_name
,
error_value
)
warnings
.
warn
(
'String exceptions are deprecated starting '
'with Python 2.5 and will be removed in a '
'future release'
,
DeprecationWarning
)
error_type
,
error_value
=
upgradeException
(
error_type
,
error_value
)
else
:
if
hasattr
(
error_type
,
'__name__'
):
error_name
=
error_type
.
__name__
...
...
lib/python/zExceptions/__init__.py
View file @
462dbb4e
...
...
@@ -18,12 +18,13 @@ application-specific packages.
$Id$
"""
from
unauthorized
import
Unauthorized
import
warnings
from
zope.interface
import
implements
from
zope.interface.common.interfaces
import
IException
from
zope.publisher.interfaces
import
INotFound
from
zope.security.interfaces
import
IForbidden
from
zExceptions.unauthorized
import
Unauthorized
class
BadRequest
(
Exception
):
implements
(
IException
)
...
...
@@ -42,3 +43,29 @@ class MethodNotAllowed(Exception):
class
Redirect
(
Exception
):
pass
def
upgradeException
(
t
,
v
):
# If a string exception is found, convert it to an equivalent
# exception defined either in builtins or zExceptions. If none of
# that works, tehn convert it to an InternalError and keep the
# original exception name as part of the exception value.
import
zExceptions
if
not
isinstance
(
t
,
basestring
):
return
t
,
v
warnings
.
warn
(
'String exceptions are deprecated starting '
'with Python 2.5 and will be removed in a '
'future release'
,
DeprecationWarning
)
n
=
None
if
__builtins__
.
has_key
(
t
):
n
=
__builtins__
[
t
]
elif
hasattr
(
zExceptions
,
t
):
n
=
getattr
(
zExceptions
,
t
)
if
n
is
not
None
and
issubclass
(
n
,
Exception
):
t
=
n
else
:
v
=
t
,
v
t
=
InternalError
return
t
,
v
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