From fd8252e8b762677dc3d47fc28dd68685fef61f6a Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Thu, 17 Oct 2019 17:43:30 -0700 Subject: Py3 cleanup: Remove use of closing() with urlopen() (#145) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In Python 3, urlopen() can always be used as a context manager. Wrapping with closing() is not necessary. https://docs.python.org/3/library/urllib.request.html#urllib.request.urlopen > This function always returns an object which can work as a context > manager … --- examples/htmlStripper.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'examples/htmlStripper.py') diff --git a/examples/htmlStripper.py b/examples/htmlStripper.py index 18f3395..eb35c70 100644 --- a/examples/htmlStripper.py +++ b/examples/htmlStripper.py @@ -6,8 +6,8 @@ # # Copyright (c) 2006, 2016, Paul McGuire # -from contextlib import closing -import urllib.request, urllib.parse, urllib.error +import urllib.parse, urllib.error +from urllib.request import urlopen from pyparsing import (makeHTMLTags, commonHTMLEntity, replaceHTMLEntity, htmlComment, anyOpenTag, anyCloseTag, LineEnd, OneOrMore, replaceWith) @@ -17,7 +17,7 @@ commonHTMLEntity.setParseAction(replaceHTMLEntity) # get some HTML targetURL = "https://wiki.python.org/moin/PythonDecoratorLibrary" -with closing(urllib.request.urlopen( targetURL )) as targetPage: +with urlopen( targetURL ) as targetPage: targetHTML = targetPage.read().decode("UTF-8") # first pass, strip out tags and translate entities -- cgit v1.2.1