phabricator: ensure that the return of urlopener.open() is closed
authorMatt Harbison <matt_harbison@yahoo.com>
Sat, 29 Dec 2018 01:51:02 -0500
changeset 41080 9d35ae3d9999
parent 41079 88d813cd9acd
child 41081 13f50ea8ac3b
phabricator: ensure that the return of urlopener.open() is closed No problem observed, just an oversight noticed while reading documentation.
hgext/phabricator.py
--- a/hgext/phabricator.py	Thu Dec 20 09:59:16 2018 +0100
+++ b/hgext/phabricator.py	Sat Dec 29 01:51:02 2018 -0500
@@ -41,6 +41,7 @@
 
 from __future__ import absolute_import
 
+import contextlib
 import itertools
 import json
 import operator
@@ -214,7 +215,8 @@
     else:
         urlopener = urlmod.opener(repo.ui, authinfo)
         request = util.urlreq.request(url, data=data)
-        body = urlopener.open(request).read()
+        with contextlib.closing(urlopener.open(request)) as rsp:
+            body = rsp.read()
     repo.ui.debug(b'Conduit Response: %s\n' % body)
     parsed = json.loads(body)
     if parsed.get(r'error_code'):