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
d612b6ea
Commit
d612b6ea
authored
Apr 04, 2005
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
For instances of persistent classes, save a class-module/clas-name
tuple if the class has a non-empty module string.
parent
ad1b7691
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
9 deletions
+25
-9
lib/python/ZODB/serialize.py
lib/python/ZODB/serialize.py
+25
-9
No files found.
lib/python/ZODB/serialize.py
View file @
d612b6ea
...
...
@@ -141,10 +141,10 @@ class BaseObjectWriter:
>>> jar = DummyJar()
>>> writer = BaseObjectWriter(jar)
Normally, object references include the oid and a cached
reference to the class. Having the class
available allows
fast creation of the ghost, avoiding requiring an additional
database lookup.
Normally, object references include the oid and a cached
named
reference to the class. Having the class
information
available allows fast creation of the ghost, avoiding
requiring an additional
database lookup.
>>> bob = P('bob')
>>> oid, cls = writer.persistent_id(bob)
...
...
@@ -276,8 +276,16 @@ class BaseObjectWriter:
# It's possible that __getnewargs__ is degenerate and
# returns (), but we don't want to have to deghostify
# the object to find out.
# Note that this has the odd effect that, if the class has
# __getnewargs__ of its own, we'll lose the optimization
# of caching the class info.
return
oid
# Note that we never get here for persistent classes.
# We'll use driect refs for normal classes.
return
oid
,
klass
def
serialize
(
self
,
obj
):
...
...
@@ -285,13 +293,19 @@ class BaseObjectWriter:
# We don't want to be fooled by proxies.
klass
=
type
(
obj
)
# We want to serialize persistent classes by name if they have
# a non-None non-empty module so as not to have a direct
# ref. This is important when copying. We probably want to
# revisit this in the future.
if
(
isinstance
(
getattr
(
klass
,
'_p_oid'
,
0
),
_oidtypes
)
and
klass
.
__module__
):
klass
=
klass
.
__module__
,
klass
.
__name__
newargs
=
getattr
(
obj
,
"__getnewargs__"
,
None
)
if
newargs
is
None
:
meta
=
klass
else
:
meta
=
klass
,
newargs
()
if
newargs
is
not
None
:
newargs
=
newargs
()
return
self
.
_dump
(
meta
,
obj
.
__getstate__
())
return
self
.
_dump
(
(
klass
,
newargs
)
,
obj
.
__getstate__
())
def
_dump
(
self
,
classmeta
,
state
):
# To reuse the existing cStringIO object, we must reset
...
...
@@ -304,6 +318,8 @@ class BaseObjectWriter:
self
.
_file
.
truncate
()
return
self
.
_file
.
getvalue
()
_oidtypes
=
str
,
type
(
None
)
class
ObjectWriter
(
BaseObjectWriter
):
def
__init__
(
self
,
obj
):
...
...
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