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

login
register
mail settings
Submitter Matt Harbison
Date Dec. 31, 2018, 3:55 a.m.
Message ID <a567c612e90996a1a641.1546228507@Envy>
Download mbox | patch
Permalink /patch/37400/
State Accepted
Headers show

Comments

Matt Harbison - Dec. 31, 2018, 3:55 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@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.
Pulkit Goyal - Dec. 31, 2018, 2:12 p.m.
On Mon, Dec 31, 2018 at 9:26 AM Matt Harbison <mharbison72@gmail.com> wrote:

> # HG changeset patch
> # User Matt Harbison <matt_harbison@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.
>

Queued the series, many thanks!

Patch

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'):