summaryrefslogtreecommitdiff
path: root/examples/urlExtractorNew.py
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2019-10-17 17:43:30 -0700
committerPaul McGuire <ptmcg@users.noreply.github.com>2019-10-17 19:43:30 -0500
commitfd8252e8b762677dc3d47fc28dd68685fef61f6a (patch)
treef589157e3990485020d1413601bcf58886372366 /examples/urlExtractorNew.py
parent4e1a557ed6886ac67eb08122b5081c6464b699a3 (diff)
downloadpyparsing-git-fd8252e8b762677dc3d47fc28dd68685fef61f6a.tar.gz
Py3 cleanup: Remove use of closing() with urlopen() (#145)
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 …
Diffstat (limited to 'examples/urlExtractorNew.py')
-rw-r--r--examples/urlExtractorNew.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/examples/urlExtractorNew.py b/examples/urlExtractorNew.py
index d876eea..795322a 100644
--- a/examples/urlExtractorNew.py
+++ b/examples/urlExtractorNew.py
@@ -1,8 +1,8 @@
# URL extractor
# Copyright 2004, Paul McGuire
from pyparsing import makeHTMLTags
-from contextlib import closing
-import urllib.request, urllib.parse, urllib.error
+import urllib.parse, urllib.error
+from urllib.request import urlopen
import pprint
# Define the pyparsing grammar for a URL, that is:
@@ -15,7 +15,7 @@ linkOpenTag, linkCloseTag = makeHTMLTags("a")
link = linkOpenTag + linkOpenTag.tag_body("body") + linkCloseTag.suppress()
# Go get some HTML with some links in it.
-with closing(urllib.request.urlopen("https://www.cnn.com/")) as serverListPage:
+with urlopen("https://www.cnn.com/") as serverListPage:
htmlText = serverListPage.read()
# scanString is a generator that loops through the input htmlText, and for each