Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
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
Xueyun Qian
erp5
Commits
c14a6339
Commit
c14a6339
authored
Aug 01, 2011
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
HBTreeFolder2: implement equivalent to BTreeFolder2._tree.iteritems
parent
84a277f6
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
4 deletions
+67
-4
product/ERP5Type/Core/Folder.py
product/ERP5Type/Core/Folder.py
+4
-4
product/HBTreeFolder2/HBTreeFolder2.py
product/HBTreeFolder2/HBTreeFolder2.py
+34
-0
product/HBTreeFolder2/tests/testHBTreeFolder2.py
product/HBTreeFolder2/tests/testHBTreeFolder2.py
+29
-0
No files found.
product/ERP5Type/Core/Folder.py
View file @
c14a6339
...
...
@@ -1616,10 +1616,10 @@ for source_klass, destination_klass in \
# special meanings in Python or Zope, and lead to strange errors
# when set to an unexpected value. In fact, __implemented__ should not
# be set this way, otherwise Zope crashes.
method_id_list
=
[
x
for
x
in
source_klass
.
__dict__
.
iterkeys
()
if
not
x
.
startswith
(
'__'
)
and
callable
(
getattr
(
source_klass
,
x
))]
for
method_id
in
method_id_list
:
if
not
hasattr
(
destination_klass
,
method_id
):
for
method_id
in
source_klass
.
__dict__
:
if
(
method_id
[:
2
]
!=
'__'
and
method_id
[:
7
]
!=
'_htree_'
and
callable
(
getattr
(
source_klass
,
method_id
))
and
not
hasattr
(
destination_klass
,
method_id
)
):
setattr
(
destination_klass
,
method_id
,
NotImplementedClass
(
method_id
))
# Zope 2.7 required to have methodId__roles__ defined
# to know the security ot the method
...
...
product/HBTreeFolder2/HBTreeFolder2.py
View file @
c14a6339
...
...
@@ -358,6 +358,40 @@ class HBTreeFolder2Base (Persistent):
return
0
return
1
def
_htree_iteritems
(
self
,
min
=
None
):
# BUG: Due to bad design of HBTreeFolder2, buckets other than the root
# one must not contain both buckets & leafs. Otherwise, this method
# fails.
h
=
self
.
_htree
recurse_stack
=
[]
try
:
for
sub_id
in
min
and
self
.
hashId
(
min
)
or
(
''
,):
if
recurse_stack
:
i
.
next
()
if
type
(
h
)
is
not
OOBTree
:
break
id
+=
H_SEPARATOR
+
sub_id
if
type
(
h
.
itervalues
().
next
())
is
not
OOBTree
:
sub_id
=
id
else
:
id
=
sub_id
i
=
h
.
iteritems
(
sub_id
)
recurse_stack
.
append
(
i
)
h
=
h
[
sub_id
]
except
(
KeyError
,
StopIteration
):
pass
while
recurse_stack
:
i
=
recurse_stack
.
pop
()
try
:
while
1
:
id
,
h
=
i
.
next
()
if
type
(
h
)
is
OOBTree
:
recurse_stack
.
append
(
i
)
i
=
h
.
iteritems
()
else
:
yield
id
,
h
except
StopIteration
:
pass
security
.
declareProtected
(
access_contents_information
,
'treeIds'
)
...
...
product/HBTreeFolder2/tests/testHBTreeFolder2.py
View file @
c14a6339
...
...
@@ -12,6 +12,7 @@
#
##############################################################################
import
random
import
unittest
import
ZODB
import
Testing
...
...
@@ -194,6 +195,34 @@ class HBTreeFolder2Tests(unittest.TestCase):
key
.
value
=
'a'
self
.
f
.
manage_cleanup
()
def
testIterItems
(
self
):
h
=
HBTreeFolder2
()
id_list
=
[
'a-b'
,
'a-cd'
,
'b'
,
'd-a-b'
,
'd-c-d'
,
'd-f-a'
,
'e-cd'
,
'e-f'
,
'f'
]
for
i
in
id_list
:
h
.
_setOb
(
i
,
tuple
(
i
))
while
1
:
for
min
in
(
None
,
'a'
,
'a-a'
,
'a-b'
,
'a-b-a'
,
'a-c'
,
'a-cd'
,
'a-cde'
,
'a-d'
,
'aa'
,
'b'
,
'b-c-d'
,
'c'
,
'd'
):
if
min
:
m
=
min
.
split
(
'-'
)
for
i
,
id
in
enumerate
(
id_list
):
if
m
<=
id
.
split
(
'-'
):
break
else
:
i
=
0
expected
=
[(
i
,
tuple
(
i
))
for
i
in
id_list
[
i
:]]
self
.
assertEqual
(
expected
,
list
(
h
.
_htree_iteritems
(
min
)))
if
not
id_list
:
break
i
=
random
.
choice
(
id_list
)
id_list
.
remove
(
i
)
h
.
_delOb
(
i
)
class
TrojanKey
:
"""Pretends to be a consistent, immutable, humble citizen...
...
...
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