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
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
Richard
erp5
Commits
5350c44d
Commit
5350c44d
authored
May 08, 2016
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
HBTreeFolder2: rewrite iterators to not depend on getTreeIdList()
parent
ead58323
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
33 deletions
+36
-33
product/HBTreeFolder2/HBTreeFolder2.py
product/HBTreeFolder2/HBTreeFolder2.py
+36
-33
No files found.
product/HBTreeFolder2/HBTreeFolder2.py
View file @
5350c44d
...
...
@@ -12,9 +12,9 @@
#
##############################################################################
import
sys
import
operator
,
sys
from
cgi
import
escape
from
itertools
import
chain
,
islice
from
itertools
import
chain
,
i
map
,
i
slice
from
urllib
import
quote
from
random
import
randint
from
types
import
StringType
...
...
@@ -71,22 +71,27 @@ class ExhaustedUniqueIdsError (Exception):
class
HBTreeObjectIds
(
object
):
_index
=
float
(
'inf'
)
_items
=
tuple
def
__init__
(
self
,
tree
,
base_id
=
_marker
):
self
.
_tree
=
tree
if
base_id
is
_marker
:
tree_id_list
=
tree
.
getTreeIdList
()
self
.
_count
=
tree
.
_count
else
:
tree_id_list
=
base_id
,
check
=
tree
.
_checkObjectId
self
.
_keys
=
lambda
:
(
x
for
base_id
in
tree_id_list
for
x
in
(
tree
.
_htree
if
base_id
is
None
else
tree
.
_getTree
(
base_id
)).
keys
()
if
check
((
base_id
,
x
)))
self
.
_items
=
tree
.
_htree_iteritems
return
h
=
tree
.
_htree
if
base_id
:
try
:
for
sub_id
in
tree
.
hashId
(
base_id
):
h
=
h
[
sub_id
]
if
type
(
h
)
is
not
OOBTree
:
return
except
KeyError
:
return
self
.
_items
=
lambda
:
(
i
for
i
in
h
.
iteritems
()
if
type
(
i
[
1
])
is
not
OOBTree
)
def
_count
(
self
):
count
=
sum
(
1
for
x
in
self
.
_
key
s
())
count
=
sum
(
1
for
x
in
self
.
_
item
s
())
self
.
_count
=
lambda
:
count
return
count
...
...
@@ -94,7 +99,9 @@ class HBTreeObjectIds(object):
return
self
.
_count
()
def
__iter__
(
self
):
return
self
.
_keys
()
return
imap
(
self
.
_item_result
,
self
.
_items
())
_item_result
=
operator
.
itemgetter
(
0
)
def
__getitem__
(
self
,
item
):
if
isinstance
(
item
,
slice
):
...
...
@@ -104,39 +111,35 @@ class HBTreeObjectIds(object):
i
=
self
.
_index
self
.
_index
=
item
+
1
i
=
item
-
i
try
:
if
i
<
0
:
self
.
_ikeys
=
keys
=
self
.
_keys
()
return
islice
(
keys
,
item
,
None
).
next
()
return
(
islice
(
self
.
_ikeys
,
i
,
None
)
if
i
else
self
.
_ikeys
).
next
()
self
.
_iitems
=
items
=
self
.
_items
()
i
=
islice
(
items
,
item
,
None
)
elif
i
:
i
=
islice
(
self
.
_iitems
,
i
,
None
)
else
:
i
=
self
.
_iitems
try
:
return
self
.
_item_result
(
next
(
i
))
except
StopIteration
:
del
self
.
_index
,
self
.
_i
key
s
del
self
.
_index
,
self
.
_i
item
s
raise
IndexError
ContainerAssertions
[
HBTreeObjectIds
]
=
1
class
HBTreeObjectItems
(
HBTreeObjectIds
):
def
__i
ter__
(
self
):
getOb
=
self
.
_tree
.
_getOb
return
((
x
,
getOb
(
x
))
for
x
in
self
.
_keys
(
))
def
__i
nit__
(
self
,
tree
,
base_id
=
_marker
):
HBTreeObjectIds
.
__init__
(
self
,
tree
,
base_id
)
self
.
_item_result
=
lambda
item
:
(
item
[
0
],
item
[
1
].
__of__
(
tree
))
def
__getitem__
(
self
,
item
):
if
isinstance
(
item
,
slice
):
return
map
(
self
.
__getitem__
,
xrange
(
*
item
.
indices
(
self
.
_count
())))
object_id
=
HBTreeObjectIds
.
__getitem__
(
self
,
item
)
return
object_id
,
self
.
_tree
.
_getOb
(
object_id
)
ContainerAssertions
[
HBTreeObjectItems
]
=
1
class
HBTreeObjectValues
(
HBTreeObjectIds
):
def
__i
ter__
(
self
):
getOb
=
self
.
_tree
.
_getOb
return
(
getOb
(
x
)
for
x
in
self
.
_keys
()
)
def
__i
nit__
(
self
,
tree
,
base_id
=
_marker
):
HBTreeObjectIds
.
__init__
(
self
,
tree
,
base_id
)
self
.
_item_result
=
lambda
item
:
item
[
1
].
__of__
(
tree
)
def
__getitem__
(
self
,
item
):
if
isinstance
(
item
,
slice
):
return
map
(
self
.
__getitem__
,
xrange
(
*
item
.
indices
(
self
.
_count
())))
return
self
.
_tree
.
_getOb
(
HBTreeObjectIds
.
__getitem__
(
self
,
item
))
ContainerAssertions
[
HBTreeObjectValues
]
=
1
...
...
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