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 authored Jun 18, 2024
1 parent 5e10f51 commit 715180a
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions pulsar/client/transport/curl.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,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 715180a

Please sign in to comment.