-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-130283: update deprecated links and examples in urllib.request
docs
#130284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
picnixz
merged 7 commits into
python:main
from
Mr-Sunglasses:fix/deprecated-examples-urllib.request
Mar 23, 2025
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
061cba8
gh-130283: update deprecated links and examples in `urllib.request` docs
Mr-Sunglasses 48ce606
Merge branch 'main' into fix/deprecated-examples-urllib.request
Mr-Sunglasses 2b066f7
docs: fix the ". ::" sentences and merge them into "::" directly
Mr-Sunglasses 29c53e7
docs: Add the reference of HTML spec document and W3C document
Mr-Sunglasses 6eee248
Merge branch 'main' into fix/deprecated-examples-urllib.request
picnixz 0c4d55e
Apply suggestions from code review
picnixz 6c60d90
Update Doc/library/urllib.request.rst
picnixz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
gh-130283: update deprecated links and examples in
urllib.request
docs
- Loading branch information
commit 061cba8857b5bc5100c19707ccea089afa474b0c
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1219,20 +1219,16 @@ it. :: | |
>>> with urllib.request.urlopen('http://www.python.org/') as f: | ||
... print(f.read(300)) | ||
... | ||
b'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | ||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n\n\n<html | ||
xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n\n<head>\n | ||
<meta http-equiv="content-type" content="text/html; charset=utf-8" />\n | ||
<title>Python Programming ' | ||
b'<!doctype html>\n<!--[if lt IE 7]> <html class="no-js ie6 lt-ie7 lt-ie8 lt-ie9"> <![endif]-->\n<!--[if IE 7]> <html class="no-js ie7 lt-ie8 lt-ie9"> <![endif]-->\n<!--[if IE 8]> <html class="no-js ie8 lt-ie9"> | ||
|
||
Note that urlopen returns a bytes object. This is because there is no way | ||
for urlopen to automatically determine the encoding of the byte stream | ||
it receives from the HTTP server. In general, a program will decode | ||
the returned bytes object to string once it determines or guesses | ||
the appropriate encoding. | ||
|
||
The following W3C document, https://www.w3.org/International/O-charset\ , lists | ||
the various ways in which an (X)HTML or an XML document could have specified its | ||
The following W3C document, https://www.w3.org/International/questions/qa-html-encoding-declarations\ , lists | ||
the various ways in which an HTML document could have specified its | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. XML is still covered by the document but they explicitly don't say "XHTML".
picnixz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
encoding information. | ||
|
||
As the python.org website uses *utf-8* encoding as specified in its meta tag, we | ||
|
@@ -1241,17 +1237,19 @@ will use the same for decoding the bytes object. :: | |
>>> with urllib.request.urlopen('http://www.python.org/') as f: | ||
... print(f.read(100).decode('utf-8')) | ||
... | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | ||
"http://www.w3.org/TR/xhtml1/DTD/xhtm | ||
<!doctype html> | ||
<!--[if lt IE 7]> <html class="no-js ie6 lt-ie7 lt-ie8 lt-ie9"> <![endif]--> | ||
<!- | ||
|
||
It is also possible to achieve the same result without using the | ||
picnixz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
:term:`context manager` approach. :: | ||
|
||
>>> import urllib.request | ||
>>> f = urllib.request.urlopen('http://www.python.org/') | ||
>>> print(f.read(100).decode('utf-8')) | ||
picnixz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | ||
"http://www.w3.org/TR/xhtml1/DTD/xhtm | ||
<!doctype html> | ||
<!--[if lt IE 7]> <html class="no-js ie6 lt-ie7 lt-ie8 lt-ie9"> <![endif]--> | ||
<!-- | ||
|
||
In the following example, we are sending a data-stream to the stdin of a CGI | ||
and reading the data it returns to us. Note that this example will only work | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.