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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Romain Courteaud
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
Hide 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 @@
...
@@ -12,9 +12,9 @@
#
#
##############################################################################
##############################################################################
import
sys
import
operator
,
sys
from
cgi
import
escape
from
cgi
import
escape
from
itertools
import
chain
,
islice
from
itertools
import
chain
,
i
map
,
i
slice
from
urllib
import
quote
from
urllib
import
quote
from
random
import
randint
from
random
import
randint
from
types
import
StringType
from
types
import
StringType
...
@@ -71,22 +71,27 @@ class ExhaustedUniqueIdsError (Exception):
...
@@ -71,22 +71,27 @@ class ExhaustedUniqueIdsError (Exception):
class
HBTreeObjectIds
(
object
):
class
HBTreeObjectIds
(
object
):
_index
=
float
(
'inf'
)
_index
=
float
(
'inf'
)
_items
=
tuple
def
__init__
(
self
,
tree
,
base_id
=
_marker
):
def
__init__
(
self
,
tree
,
base_id
=
_marker
):
self
.
_tree
=
tree
if
base_id
is
_marker
:
if
base_id
is
_marker
:
tree_id_list
=
tree
.
getTreeIdList
()
self
.
_count
=
tree
.
_count
self
.
_count
=
tree
.
_count
else
:
self
.
_items
=
tree
.
_htree_iteritems
tree_id_list
=
base_id
,
return
check
=
tree
.
_checkObjectId
h
=
tree
.
_htree
self
.
_keys
=
lambda
:
(
x
for
base_id
in
tree_id_list
if
base_id
:
for
x
in
(
tree
.
_htree
if
base_id
is
None
else
try
:
tree
.
_getTree
(
base_id
)).
keys
()
for
sub_id
in
tree
.
hashId
(
base_id
):
if
check
((
base_id
,
x
)))
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
):
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
self
.
_count
=
lambda
:
count
return
count
return
count
...
@@ -94,7 +99,9 @@ class HBTreeObjectIds(object):
...
@@ -94,7 +99,9 @@ class HBTreeObjectIds(object):
return
self
.
_count
()
return
self
.
_count
()
def
__iter__
(
self
):
def
__iter__
(
self
):
return
self
.
_keys
()
return
imap
(
self
.
_item_result
,
self
.
_items
())
_item_result
=
operator
.
itemgetter
(
0
)
def
__getitem__
(
self
,
item
):
def
__getitem__
(
self
,
item
):
if
isinstance
(
item
,
slice
):
if
isinstance
(
item
,
slice
):
...
@@ -104,39 +111,35 @@ class HBTreeObjectIds(object):
...
@@ -104,39 +111,35 @@ class HBTreeObjectIds(object):
i
=
self
.
_index
i
=
self
.
_index
self
.
_index
=
item
+
1
self
.
_index
=
item
+
1
i
=
item
-
i
i
=
item
-
i
if
i
<
0
:
self
.
_iitems
=
items
=
self
.
_items
()
i
=
islice
(
items
,
item
,
None
)
elif
i
:
i
=
islice
(
self
.
_iitems
,
i
,
None
)
else
:
i
=
self
.
_iitems
try
:
try
:
if
i
<
0
:
return
self
.
_item_result
(
next
(
i
))
self
.
_ikeys
=
keys
=
self
.
_keys
()
return
islice
(
keys
,
item
,
None
).
next
()
return
(
islice
(
self
.
_ikeys
,
i
,
None
)
if
i
else
self
.
_ikeys
).
next
()
except
StopIteration
:
except
StopIteration
:
del
self
.
_index
,
self
.
_i
key
s
del
self
.
_index
,
self
.
_i
item
s
raise
IndexError
raise
IndexError
ContainerAssertions
[
HBTreeObjectIds
]
=
1
ContainerAssertions
[
HBTreeObjectIds
]
=
1
class
HBTreeObjectItems
(
HBTreeObjectIds
):
class
HBTreeObjectItems
(
HBTreeObjectIds
):
def
__i
ter__
(
self
):
def
__i
nit__
(
self
,
tree
,
base_id
=
_marker
):
getOb
=
self
.
_tree
.
_getOb
HBTreeObjectIds
.
__init__
(
self
,
tree
,
base_id
)
return
((
x
,
getOb
(
x
))
for
x
in
self
.
_keys
(
))
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
ContainerAssertions
[
HBTreeObjectItems
]
=
1
class
HBTreeObjectValues
(
HBTreeObjectIds
):
class
HBTreeObjectValues
(
HBTreeObjectIds
):
def
__i
ter__
(
self
):
def
__i
nit__
(
self
,
tree
,
base_id
=
_marker
):
getOb
=
self
.
_tree
.
_getOb
HBTreeObjectIds
.
__init__
(
self
,
tree
,
base_id
)
return
(
getOb
(
x
)
for
x
in
self
.
_keys
()
)
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
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