Skip to content
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

gh-130283: update deprecated links and examples in urllib.request docs #130284

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Mr-Sunglasses
Copy link
Contributor

@Mr-Sunglasses Mr-Sunglasses commented Feb 18, 2025

@Mr-Sunglasses
Copy link
Contributor Author

@sobolevn PTAL

Comment on lines 1248 to 1249
>>> f = urllib.request.urlopen('http://www.python.org/')
>>> print(f.read(100).decode('utf-8'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
>>> f = urllib.request.urlopen('http://www.python.org/')
>>> print(f.read(100).decode('utf-8'))
>>> with urllib.request.urlopen('http://www.python.org/') as f:
... print(f.read(100).decode('utf-8'))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also use with?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sobolevn It is the example without using the context manager approach.


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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need small suggestion here, as https://www.w3.org/International/O-charset is deprecated by W3C, and it added these two suggestions in the page

You may want to try, instead, one of the following pages:
Handling character encodings in HTML and CSS (tutorial)
Declaring character encodings in HTML

I've added https://www.w3.org/International/questions/qa-html-encoding-declarations this one but we can add something other instead of this like

or any other.
I would love to know the thought's of the fellow dev's.

Comment on lines 1248 to 1249
>>> f = urllib.request.urlopen('http://www.python.org/')
>>> print(f.read(100).decode('utf-8'))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sobolevn It is the example without using the context manager approach.

"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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ref. @sobolevn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review docs Documentation in the Doc dir skip news
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

docs: fix deprecated or broken examples in urllib.request documentation.
2 participants