mirror of
https://github.com/python/cpython.git
synced 2025-10-04 14:15:45 +00:00
Fix Issue 15922: make howto/urllib2.rst doctests pass.
Patch by Chris Jerdonek. Address Ezio's review comment.
This commit is contained in:
commit
96df7da0ac
1 changed files with 14 additions and 15 deletions
|
@ -144,7 +144,7 @@ This is done as follows::
|
||||||
>>> data['location'] = 'Northampton'
|
>>> data['location'] = 'Northampton'
|
||||||
>>> data['language'] = 'Python'
|
>>> data['language'] = 'Python'
|
||||||
>>> url_values = urllib.parse.urlencode(data)
|
>>> url_values = urllib.parse.urlencode(data)
|
||||||
>>> print(url_values)
|
>>> print(url_values) # The order may differ from below. #doctest: +SKIP
|
||||||
name=Somebody+Here&language=Python&location=Northampton
|
name=Somebody+Here&language=Python&location=Northampton
|
||||||
>>> url = 'http://www.example.com/example.cgi'
|
>>> url = 'http://www.example.com/example.cgi'
|
||||||
>>> full_url = url + '?' + url_values
|
>>> full_url = url + '?' + url_values
|
||||||
|
@ -214,9 +214,9 @@ e.g. ::
|
||||||
|
|
||||||
>>> req = urllib.request.Request('http://www.pretend_server.org')
|
>>> req = urllib.request.Request('http://www.pretend_server.org')
|
||||||
>>> try: urllib.request.urlopen(req)
|
>>> try: urllib.request.urlopen(req)
|
||||||
>>> except urllib.error.URLError as e:
|
... except urllib.error.URLError as e:
|
||||||
>>> print(e.reason)
|
... print(e.reason) #doctest: +SKIP
|
||||||
>>>
|
...
|
||||||
(4, 'getaddrinfo failed')
|
(4, 'getaddrinfo failed')
|
||||||
|
|
||||||
|
|
||||||
|
@ -322,18 +322,17 @@ geturl, and info, methods as returned by the ``urllib.response`` module::
|
||||||
|
|
||||||
>>> req = urllib.request.Request('http://www.python.org/fish.html')
|
>>> req = urllib.request.Request('http://www.python.org/fish.html')
|
||||||
>>> try:
|
>>> try:
|
||||||
>>> urllib.request.urlopen(req)
|
... urllib.request.urlopen(req)
|
||||||
>>> except urllib.error.HTTPError as e:
|
... except urllib.error.HTTPError as e:
|
||||||
>>> print(e.code)
|
... print(e.code)
|
||||||
>>> print(e.read())
|
... print(e.read()) #doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
|
||||||
>>>
|
...
|
||||||
404
|
404
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
b'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||||
"http://www.w3.org/TR/html4/loose.dtd">
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n\n\n<html
|
||||||
<?xml-stylesheet href="./css/ht2html.css"
|
...
|
||||||
type="text/css"?>
|
<title>Page Not Found</title>\n
|
||||||
<html><head><title>Error 404: File Not Found</title>
|
...
|
||||||
...... etc...
|
|
||||||
|
|
||||||
Wrapping it Up
|
Wrapping it Up
|
||||||
--------------
|
--------------
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue