Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
ZODB
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
ZODB
Commits
e3613765
Commit
e3613765
authored
Aug 24, 2005
by
Tim Peters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Gave PersistentMapping an __iter__ method.
Also gave it some tests (it was woefully untested).
parent
595ab70f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
87 additions
and
0 deletions
+87
-0
NEWS.txt
NEWS.txt
+11
-0
src/ZODB/tests/testPersistentMapping.py
src/ZODB/tests/testPersistentMapping.py
+68
-0
src/persistent/mapping.py
src/persistent/mapping.py
+8
-0
No files found.
NEWS.txt
View file @
e3613765
...
@@ -17,6 +17,17 @@ Savepoints
...
@@ -17,6 +17,17 @@ Savepoints
happen, and stopped happening for subtransaction commits too. Making a
happen, and stopped happening for subtransaction commits too. Making a
savepoint (or doing a subtransaction commit) does invoke cache gc now.
savepoint (or doing a subtransaction commit) does invoke cache gc now.
PersistentMapping
-----------------
- (3.4.2a1) The ``PersistentMapping`` class has an ``__iter__()`` method
now, so that objects of this type work well with Python's iteration
protocol. For example, if ``x`` is a ``PersistentMapping`` (or
Python dictionary, or BTree, or ``PersistentDict``, ...), then
``for key in x:`` iterates over the keys of ``x``, ``list(x)`` creates
a list containing ``x``'s keys, ``iter(x)`` creates an iterator for
``x``'s keys, and so on.
What's new in ZODB3 3.4.1?
What's new in ZODB3 3.4.1?
==========================
==========================
...
...
src/ZODB/tests/testPersistentMapping.py
View file @
e3613765
...
@@ -95,6 +95,74 @@ class PMTests(unittest.TestCase):
...
@@ -95,6 +95,74 @@ class PMTests(unittest.TestCase):
self
.
assert_
(
oldPath
is
newPath
)
self
.
assert_
(
oldPath
is
newPath
)
def
checkBasicOps
(
self
):
from
persistent.mapping
import
PersistentMapping
m
=
PersistentMapping
({
'x'
:
1
},
a
=
2
,
b
=
3
)
m
[
'name'
]
=
'bob'
self
.
assertEqual
(
m
[
'name'
],
"bob"
)
self
.
assertEqual
(
m
.
get
(
'name'
,
42
),
"bob"
)
self
.
assert_
(
'name'
in
m
)
try
:
m
[
'fred'
]
except
KeyError
:
pass
else
:
self
.
fail
(
"expected KeyError"
)
self
.
assert_
(
'fred'
not
in
m
)
self
.
assertEqual
(
m
.
get
(
'fred'
),
None
)
self
.
assertEqual
(
m
.
get
(
'fred'
,
42
),
42
)
keys
=
m
.
keys
()
keys
.
sort
()
self
.
assertEqual
(
keys
,
[
'a'
,
'b'
,
'name'
,
'x'
])
values
=
m
.
values
()
values
.
sort
()
self
.
assertEqual
(
values
,
[
1
,
2
,
3
,
'bob'
])
items
=
m
.
items
()
items
.
sort
()
self
.
assertEqual
(
items
,
[(
'a'
,
2
),
(
'b'
,
3
),
(
'name'
,
'bob'
),
(
'x'
,
1
)])
keys
=
list
(
m
.
iterkeys
())
keys
.
sort
()
self
.
assertEqual
(
keys
,
[
'a'
,
'b'
,
'name'
,
'x'
])
values
=
list
(
m
.
itervalues
())
values
.
sort
()
self
.
assertEqual
(
values
,
[
1
,
2
,
3
,
'bob'
])
items
=
list
(
m
.
iteritems
())
items
.
sort
()
self
.
assertEqual
(
items
,
[(
'a'
,
2
),
(
'b'
,
3
),
(
'name'
,
'bob'
),
(
'x'
,
1
)])
# PersistentMapping didn't have an __iter__ method before ZODB 3.4.2.
# Check that it plays well now with the Python iteration protocol.
def
checkIteration
(
self
):
from
persistent.mapping
import
PersistentMapping
m
=
PersistentMapping
({
'x'
:
1
},
a
=
2
,
b
=
3
)
m
[
'name'
]
=
'bob'
def
check
(
keylist
):
keylist
.
sort
()
self
.
assertEqual
(
keylist
,
[
'a'
,
'b'
,
'name'
,
'x'
])
check
(
list
(
m
))
check
([
key
for
key
in
m
])
i
=
iter
(
m
)
keylist
=
[]
while
1
:
try
:
key
=
i
.
next
()
except
StopIteration
:
break
keylist
.
append
(
key
)
check
(
keylist
)
def
find_global
(
modulename
,
classname
):
def
find_global
(
modulename
,
classname
):
"""Helper for this test suite to get special PersistentMapping"""
"""Helper for this test suite to get special PersistentMapping"""
...
...
src/persistent/mapping.py
View file @
e3613765
...
@@ -75,6 +75,14 @@ class PersistentMapping(UserDict, persistent.Persistent):
...
@@ -75,6 +75,14 @@ class PersistentMapping(UserDict, persistent.Persistent):
self
.
_p_changed
=
1
self
.
_p_changed
=
1
return
self
.
__super_popitem
()
return
self
.
__super_popitem
()
# __iter__ was added in ZODB 3.4.2, but should have been added long
# before. We could inherit from Python's IterableUserDict instead
# (which just adds __iter__ to Python's UserDict), but that class isn't
# documented, and it would add another level of lookup for all the
# other methods.
def
__iter__
(
self
):
return
iter
(
self
.
data
)
# If the internal representation of PersistentMapping changes,
# If the internal representation of PersistentMapping changes,
# it causes compatibility problems for pickles generated by
# it causes compatibility problems for pickles generated by
# different versions of the code. Compatibility works in both
# different versions of the code. Compatibility works in both
...
...
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