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
8c87524d
Commit
8c87524d
authored
Jun 27, 2010
by
Godefroid Chapelle
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
LP #143531: Fix broken object so they give access to their state.
merge branch gotcha-LP143531
parent
2752d75b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
25 deletions
+48
-25
doc/CHANGES.rst
doc/CHANGES.rst
+2
-0
src/OFS/Uninstalled.py
src/OFS/Uninstalled.py
+4
-7
src/OFS/tests/test_Uninstalled.py
src/OFS/tests/test_Uninstalled.py
+42
-18
No files found.
doc/CHANGES.rst
View file @
8c87524d
...
...
@@ -11,6 +11,8 @@ http://docs.zope.org/zope2/releases/.
Bugs Fixed
++++++++++
- LP #143531: Fix broken object so they give access to their state.
- LP #578326: Issue a warning if someone specifies a non-public permission
attribute in the browser:view directive. This attribute has never been
supported in Zope 2.
...
...
src/OFS/Uninstalled.py
View file @
8c87524d
...
...
@@ -22,12 +22,14 @@ from Acquisition import Explicit
from
App.special_dtml
import
DTMLFile
from
OFS.SimpleItem
import
Item
from
Persistence
import
Overridable
from
ZODB.broken
import
Broken
as
ZODB_Broken
from
ZODB.broken
import
persistentBroken
broken_klasses
=
{}
broken_klasses_lock
=
allocate_lock
()
LOG
=
getLogger
(
'OFS.Uninstalled'
)
class
BrokenClass
(
Explicit
,
Item
,
Overridable
):
class
BrokenClass
(
ZODB_Broken
,
Explicit
,
Item
,
Overridable
):
_p_changed
=
0
meta_type
=
'Broken Because Product is Gone'
icon
=
'p_/broken'
...
...
@@ -37,12 +39,6 @@ class BrokenClass(Explicit, Item, Overridable):
manage_page_header
=
Acquired
manage_page_footer
=
Acquired
def
__getstate__
(
self
):
raise
SystemError
,
(
"""This object was originally created by a product that
is no longer installed. It cannot be updated.
(%s)"""
%
repr
(
self
))
def
__getattr__
(
self
,
name
):
if
name
[:
3
]
==
'_p_'
:
return
BrokenClass
.
inheritedAttribute
(
'__getattr__'
)(
self
,
name
)
...
...
@@ -74,6 +70,7 @@ def Broken(self, oid, pair):
klass
.
info
=
(
'This object
\
'
s class was %s in module %s.'
%
(
klass
.
__name__
,
klass
.
__module__
))
klass
=
persistentBroken
(
klass
)
LOG
.
warning
(
'Could not import class %s '
'from module %s'
%
(
`klass.__name__`
,
`klass.__module__`
))
finally
:
...
...
src/OFS/tests/test_Uninstalled.py
View file @
8c87524d
...
...
@@ -13,6 +13,13 @@
##############################################################################
import
unittest
from
OFS.SimpleItem
import
SimpleItem
from
Testing.ZopeTestCase
import
base
class
ToBreak
(
SimpleItem
):
pass
class
TestsOfBroken
(
unittest
.
TestCase
):
"""Tests for the factory for "broken" classes.
...
...
@@ -77,24 +84,8 @@ class TestsOfBroken(unittest.TestCase):
self
.
assertEqual
(
klass
.
__module__
,
'Products.MyProduct.MyClass'
)
self
.
assertEqual
(
klass
.
product_name
,
'MyProduct'
)
def
test_Broken_instance___getstate___raises_useful_exception
(
self
):
# see http://www.zope.org/Collectors/Zope/2157
from
OFS.Uninstalled
import
Broken
from
OFS.Uninstalled
import
BrokenClass
OID
=
'
\
x01
'
*
8
inst
=
Broken
(
self
,
OID
,
(
'Products.MyProduct.MyClass'
,
'MyClass'
))
try
:
dict
=
inst
.
__getstate__
()
except
SystemError
,
e
:
self
.
failUnless
(
'MyClass'
in
str
(
e
),
str
(
e
))
else
:
self
.
fail
(
"'__getstate__' didn't raise SystemError!"
)
def
test_Broken_instance___getattr___allows_persistence_attrs
(
self
):
from
OFS.Uninstalled
import
Broken
from
OFS.Uninstalled
import
BrokenClass
OID
=
'
\
x01
'
*
8
PERSISTENCE_ATTRS
=
[
"_p_changed"
,
"_p_jar"
,
...
...
@@ -119,14 +110,47 @@ class TestsOfBroken(unittest.TestCase):
for
meth_name
in
PERSISTENCE_METHODS
:
meth
=
getattr
(
inst
,
meth_name
)
# doesn't raise
class
TestsIntegratedBroken
(
base
.
TestCase
):
def
test_Broken_instance___getstate___gives_access_to_its_state
(
self
):
from
Acquisition
import
aq_base
from
OFS.Uninstalled
import
BrokenClass
from
OFS.tests
import
test_Uninstalled
import
transaction
# store an instance
tr
=
ToBreak
()
tr
.
id
=
'tr'
self
.
app
.
_setObject
(
'tr'
,
tr
)
# commit to allow access in another connection
transaction
.
commit
()
# remove class from namespace to ensure broken object
del
test_Uninstalled
.
ToBreak
# get new connection that will give access to broken object
app
=
base
.
app
()
inst
=
aq_base
(
app
.
tr
)
self
.
failUnless
(
isinstance
(
inst
,
BrokenClass
))
state
=
inst
.
__getstate__
()
self
.
assertEqual
(
state
,
{
'id'
:
'tr'
})
# cleanup
app
.
manage_delObjects
(
'tr'
)
transaction
.
commit
()
# check that object is not left over
app
=
base
.
app
()
self
.
failIf
(
'tr'
in
app
.
objectIds
())
def
test_suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
TestsOfBroken
))
suite
.
addTest
(
unittest
.
makeSuite
(
TestsOfBroken
))
suite
.
addTest
(
unittest
.
makeSuite
(
TestsIntegratedBroken
))
return
suite
def
main
():
unittest
.
main
(
defaultTest
=
'test_suite'
)
if
__name__
==
'__main__'
:
main
()
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