Skip to content

Commit

Permalink
docs(example): Avoid UnboundLocalError for get_object when exception (
Browse files Browse the repository at this point in the history
  • Loading branch information
100gle authored Oct 19, 2024
1 parent adca8ad commit adb2409
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
24 changes: 16 additions & 8 deletions examples/get_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,49 @@
)

# Get data of an object.
response = None
try:
response = client.get_object("my-bucket", "my-object")
# Read data from response.
finally:
response.close()
response.release_conn()
if response:
response.close()
response.release_conn()

# Get data of an object of version-ID.
response = None
try:
response = client.get_object(
"my-bucket", "my-object",
version_id="dfbd25b3-abec-4184-a4e8-5a35a5c1174d",
)
# Read data from response.
finally:
response.close()
response.release_conn()
if response:
response.close()
response.release_conn()

# Get data of an object from offset and length.
response = None
try:
response = client.get_object(
"my-bucket", "my-object", offset=512, length=1024,
)
# Read data from response.
finally:
response.close()
response.release_conn()
if response:
response.close()
response.release_conn()

# Get data of an SSE-C encrypted object.
response = None
try:
response = client.get_object(
"my-bucket", "my-object",
ssec=SseCustomerKey(b"32byteslongsecretkeymustprovided"),
)
# Read data from response.
finally:
response.close()
response.release_conn()
if response:
response.close()
response.release_conn()
24 changes: 16 additions & 8 deletions minio/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1187,44 +1187,52 @@ def get_object(
Example::
# Get data of an object.
response = None
try:
response = client.get_object("my-bucket", "my-object")
# Read data from response.
finally:
response.close()
response.release_conn()
if response:
response.close()
response.release_conn()
# Get data of an object of version-ID.
response = None
try:
response = client.get_object(
"my-bucket", "my-object",
version_id="dfbd25b3-abec-4184-a4e8-5a35a5c1174d",
)
# Read data from response.
finally:
response.close()
response.release_conn()
if response:
response.close()
response.release_conn()
# Get data of an object from offset and length.
response = None
try:
response = client.get_object(
"my-bucket", "my-object", offset=512, length=1024,
)
# Read data from response.
finally:
response.close()
response.release_conn()
if response:
response.close()
response.release_conn()
# Get data of an SSE-C encrypted object.
response = None
try:
response = client.get_object(
"my-bucket", "my-object",
ssec=SseCustomerKey(b"32byteslongsecretkeymustprovided"),
)
# Read data from response.
finally:
response.close()
response.release_conn()
if response:
response.close()
response.release_conn()
"""
check_bucket_name(bucket_name, s3_check=self._base_url.is_aws_host)
check_object_name(object_name)
Expand Down

0 comments on commit adb2409

Please sign in to comment.