Skip to content

gh-60055: Allow passing a Request instance for RobotParser URLs#103753

Merged
orsenthil merged 8 commits into
python:mainfrom
ephphatha:gh-60055
Jul 5, 2026
Merged

gh-60055: Allow passing a Request instance for RobotParser URLs#103753
orsenthil merged 8 commits into
python:mainfrom
ephphatha:gh-60055

Conversation

@ephphatha

@ephphatha ephphatha commented Apr 24, 2023

Copy link
Copy Markdown
Contributor

RobotParser only needs to know the type of the URL param in order to set the undocumented host and path properties, so when calling set_url use the pre-parsed attributes if given a Request object instance. Otherwise the only use of the url is when it is passed to urllib.request.urlopen which accepts either str or Request URLs.

Main driver for this change was to set the User-Agent header so #60055 seemed like the appropriate issue to link.

@ephphatha ephphatha requested a review from berkerpeksag as a code owner April 24, 2023 11:02
@bedevere-bot

Copy link
Copy Markdown

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@ghost

ghost commented Apr 24, 2023

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.
CLA signed

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 12, 2026
Comment thread Lib/test/test_robotparser.py Outdated
@orsenthil orsenthil force-pushed the gh-60055 branch 2 times, most recently from cf08d64 to 40444c2 Compare July 4, 2026 22:39
@read-the-docs-community

read-the-docs-community Bot commented Jul 4, 2026

Copy link
Copy Markdown

@orsenthil orsenthil left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The direction is fine, but I have more than a couple of remarks.

Comment thread Lib/urllib/robotparser.py Outdated
Comment thread Lib/urllib/robotparser.py Outdated
Comment thread Lib/urllib/robotparser.py Outdated
Comment thread Doc/library/urllib.robotparser.rst Outdated
This class provides methods to read, parse and answer questions about the
:file:`robots.txt` file at *url*.
:file:`robots.txt` file at *url* or a :class:`urllib.request.Request` object
with additional user-agent headers populated.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Add versionchanged.

Headers aren't limited to user-agent.

The wording in general could be improved.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I have simplified it :file:robots.txt file at url or a :class:urllib.request.Request object. Please suggest if it should be anything else.

Comment thread Doc/library/urllib.robotparser.rst Outdated
Comment thread Lib/test/test_robotparser.py Outdated
Comment thread Misc/NEWS.d/next/Library/2023-04-24-11-12-00.gh-issue-60055.UjP6aX.rst Outdated
@orsenthil

Copy link
Copy Markdown
Member

@serhiy-storchaka , I have addressed your review comments. Thank you for those.
Please take a look again.

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, besides few nitpicks.

Comment thread Doc/library/urllib.robotparser.rst Outdated
Comment thread Lib/urllib/robotparser.py
Comment thread Doc/library/urllib.robotparser.rst Outdated
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Comment thread Doc/library/urllib.robotparser.rst Outdated
@orsenthil orsenthil merged commit cdcf228 into python:main Jul 5, 2026
51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants