[PATCH 1 of 3] phabricator: ensure that the return of urlopener.open() is closed

Matt Harbison mharbison72 at gmail.com
Mon Dec 31 03:55:07 UTC 2018


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1546066262 18000
#      Sat Dec 29 01:51:02 2018 -0500
# Node ID a567c612e90996a1a6410c0400634447405df996
# Parent  88d813cd9acd56490fdac2c0b8e66c5231c63d88
phabricator: ensure that the return of urlopener.open() is closed

No problem observed, just an oversight noticed while reading documentation.

diff --git a/hgext/phabricator.py b/hgext/phabricator.py
--- a/hgext/phabricator.py
+++ b/hgext/phabricator.py
@@ -41,6 +41,7 @@ Config::
 
 from __future__ import absolute_import
 
+import contextlib
 import itertools
 import json
 import operator
@@ -214,7 +215,8 @@ def callconduit(repo, name, params):
     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'):


More information about the Mercurial-devel mailing list