Skip to content

Commit

Permalink
Use context manager
Browse files Browse the repository at this point in the history
Co-authored-by: Nuwan Goonasekera <[email protected]>
  • Loading branch information
mvdbeek and nuwang committed Jun 18, 2024
1 parent 5e10f51 commit 0c00697
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions pulsar/client/transport/curl.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import contextlib
import io
import logging
import os.path
Expand Down Expand Up @@ -70,16 +71,13 @@ def post_file(url, path):
# wrap it in a better one.
message = NO_SUCH_FILE_MESSAGE % (path, url)
raise Exception(message)
try:
c = _new_curl_object_for_url(url)
with contextlib.closing(_new_curl_object_for_url(url)) as c:
c.setopt(c.HTTPPOST, [("file", (c.FORM_FILE, path.encode('ascii')))])
c.perform()
status_code = c.getinfo(HTTP_CODE)
if int(status_code) != 200:
message = POST_FAILED_MESSAGE % (url, status_code)
raise Exception(message)
finally:
c.close()


def get_size(url) -> int:
Expand Down

0 comments on commit 0c00697

Please sign in to comment.