Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Paste
P1043
python function colors
Active
Public
Actions
Authored by
vlorentz
on May 17 2021, 1:43 PM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Flag For Later
Tags
None
Subscribers
None
def
get
(
self
,
obj_id
):
"""Retrieve blob's content if found.
"""
hex_obj_id
=
self
.
_internal_id
(
obj_id
)
client
=
self
.
get_blob_client
(
hex_obj_id
)
try
:
download
=
client
.
download_blob
()
except
ResourceNotFoundError
:
raise
ObjNotFoundError
(
obj_id
)
from
None
else
:
data
=
download
.
content_as_bytes
()
decompressor
=
decompressors
[
self
.
compression
]()
ret
=
decompressor
.
decompress
(
data
)
if
decompressor
.
unused_data
:
raise
Error
(
"Corrupt object
%s
: trailing data found"
%
hex_obj_id
)
return
ret
async
def
_get_async
(
self
,
obj_id
,
container_clients
):
"""Like ``get(obj_id)``, but asynchronous"""
hex_obj_id
=
self
.
_internal_id
(
obj_id
)
client
=
self
.
get_async_blob_client
(
hex_obj_id
,
container_clients
)
try
:
download
=
await
client
.
download_blob
()
except
ResourceNotFoundError
:
raise
ObjNotFoundError
(
obj_id
)
from
None
else
:
data
=
await
download
.
content_as_bytes
()
decompressor
=
decompressors
[
self
.
compression
]()
ret
=
decompressor
.
decompress
(
data
)
if
decompressor
.
unused_data
:
raise
Error
(
"Corrupt object
%s
: trailing data found"
%
hex_obj_id
)
return
ret
Event Timeline
vlorentz
created this paste.
May 17 2021, 1:43 PM
2021-05-17 13:43:04 (UTC+2)
Log In to Comment