Skip to content

Commit 0c00697

Browse files
mvdbeeknuwang
andcommitted
Use context manager
Co-authored-by: Nuwan Goonasekera <[email protected]>
1 parent 5e10f51 commit 0c00697

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

pulsar/client/transport/curl.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import contextlib
12
import io
23
import logging
34
import os.path
@@ -70,16 +71,13 @@ def post_file(url, path):
7071
# wrap it in a better one.
7172
message = NO_SUCH_FILE_MESSAGE % (path, url)
7273
raise Exception(message)
73-
try:
74-
c = _new_curl_object_for_url(url)
74+
with contextlib.closing(_new_curl_object_for_url(url)) as c:
7575
c.setopt(c.HTTPPOST, [("file", (c.FORM_FILE, path.encode('ascii')))])
7676
c.perform()
7777
status_code = c.getinfo(HTTP_CODE)
7878
if int(status_code) != 200:
7979
message = POST_FAILED_MESSAGE % (url, status_code)
8080
raise Exception(message)
81-
finally:
82-
c.close()
8381

8482

8583
def get_size(url) -> int:

0 commit comments

Comments
 (0)