Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 570bc4c

Browse files
committed
Fix Issue 15922: make howto/urllib2.rst doctests pass.
Patch by Chris Jerdonek. Address Ezio's review comment.
1 parent 7903df4 commit 570bc4c

1 file changed

Lines changed: 14 additions & 15 deletions

File tree

Doc/howto/urllib2.rst

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ This is done as follows::
144144
>>> data['location'] = 'Northampton'
145145
>>> data['language'] = 'Python'
146146
>>> url_values = urllib.parse.urlencode(data)
147-
>>> print(url_values)
147+
>>> print(url_values) # The order may differ from below. #doctest: +SKIP
148148
name=Somebody+Here&language=Python&location=Northampton
149149
>>> url = 'http://www.example.com/example.cgi'
150150
>>> full_url = url + '?' + url_values
@@ -214,9 +214,9 @@ e.g. ::
214214

215215
>>> req = urllib.request.Request('http://www.pretend_server.org')
216216
>>> try: urllib.request.urlopen(req)
217-
>>> except urllib.error.URLError as e:
218-
>>> print(e.reason)
219-
>>>
217+
... except urllib.error.URLError as e:
218+
... print(e.reason) #doctest: +SKIP
219+
...
220220
(4, 'getaddrinfo failed')
221221

222222

@@ -322,18 +322,17 @@ geturl, and info, methods as returned by the ``urllib.response`` module::
322322

323323
>>> req = urllib.request.Request('http://www.python.org/fish.html')
324324
>>> try:
325-
>>> urllib.request.urlopen(req)
326-
>>> except urllib.error.HTTPError as e:
327-
>>> print(e.code)
328-
>>> print(e.read())
329-
>>>
325+
... urllib.request.urlopen(req)
326+
... except urllib.error.HTTPError as e:
327+
... print(e.code)
328+
... print(e.read()) #doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
329+
...
330330
404
331-
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
332-
"http://www.w3.org/TR/html4/loose.dtd">
333-
<?xml-stylesheet href="./css/ht2html.css"
334-
type="text/css"?>
335-
<html><head><title>Error 404: File Not Found</title>
336-
...... etc...
331+
b'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
332+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n\n\n<html
333+
...
334+
<title>Page Not Found</title>\n
335+
...
337336

338337
Wrapping it Up
339338
--------------

0 commit comments

Comments
 (0)