Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
synnefo
Commits
e7c56937
Commit
e7c56937
authored
Dec 09, 2013
by
Sofia Papagiannaki
Browse files
pithos: Simplify code for applying listing limits
Use a decorator instead
parent
46786557
Changes
1
Hide whitespace changes
Inline
Side-by-side
snf-pithos-backend/pithos/backends/modular.py
View file @
e7c56937
...
...
@@ -164,6 +164,17 @@ def debug_method(func):
return
wrapper
def
list_method
(
func
):
@
wraps
(
func
)
def
wrapper
(
self
,
*
args
,
**
kw
):
marker
=
kw
.
get
(
'marker'
)
limit
=
kw
.
get
(
'limit'
)
result
=
func
(
self
,
*
args
,
**
kw
)
start
,
limit
=
self
.
_list_limits
(
result
,
marker
,
limit
)
return
result
[
start
:
start
+
limit
]
return
wrapper
class
ModularBackend
(
BaseBackend
):
"""A modular backend.
...
...
@@ -333,12 +344,11 @@ class ModularBackend(BaseBackend):
@
debug_method
@
backend_method
@
list_method
def
list_accounts
(
self
,
user
,
marker
=
None
,
limit
=
10000
):
"""Return a list of accounts the user can access."""
allowed
=
self
.
_allowed_accounts
(
user
)
start
,
limit
=
self
.
_list_limits
(
allowed
,
marker
,
limit
)
return
allowed
[
start
:
start
+
limit
]
return
self
.
_allowed_accounts
(
user
)
def
_get_account_quotas
(
self
,
account
):
"""Get account usage from astakos."""
...
...
@@ -490,6 +500,7 @@ class ModularBackend(BaseBackend):
@
debug_method
@
backend_method
@
list_method
def
list_containers
(
self
,
user
,
account
,
marker
=
None
,
limit
=
10000
,
shared
=
False
,
until
=
None
,
public
=
False
):
"""Return a list of containers existing under an account."""
...
...
@@ -497,9 +508,7 @@ class ModularBackend(BaseBackend):
if
user
!=
account
:
if
until
or
account
not
in
self
.
_allowed_accounts
(
user
):
raise
NotAllowedError
allowed
=
self
.
_allowed_containers
(
user
,
account
)
start
,
limit
=
self
.
_list_limits
(
allowed
,
marker
,
limit
)
return
allowed
[
start
:
start
+
limit
]
return
self
.
_allowed_containers
(
user
,
account
)
if
shared
or
public
:
allowed
=
set
()
if
shared
:
...
...
@@ -508,15 +517,10 @@ class ModularBackend(BaseBackend):
if
public
:
allowed
.
update
([
x
[
0
].
split
(
'/'
,
2
)[
1
]
for
x
in
self
.
permissions
.
public_list
(
account
)])
allowed
=
sorted
(
allowed
)
start
,
limit
=
self
.
_list_limits
(
allowed
,
marker
,
limit
)
return
allowed
[
start
:
start
+
limit
]
return
sorted
(
allowed
)
node
=
self
.
node
.
node_lookup
(
account
)
containers
=
[
x
[
0
]
for
x
in
self
.
_list_object_properties
(
return
[
x
[
0
]
for
x
in
self
.
_list_object_properties
(
node
,
account
,
''
,
'/'
,
marker
,
limit
,
False
,
None
,
[],
until
)]
start
,
limit
=
self
.
_list_limits
(
[
x
[
0
]
for
x
in
containers
],
marker
,
limit
)
return
containers
[
start
:
start
+
limit
]
@
debug_method
@
backend_method
...
...
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