Add BROWSERS dict and browsers= parameter to load()#230
Open
bwagner wants to merge 1 commit intoborisbabic:masterfrom
Open
Add BROWSERS dict and browsers= parameter to load()#230bwagner wants to merge 1 commit intoborisbabic:masterfrom
bwagner wants to merge 1 commit intoborisbabic:masterfrom
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Add
BROWSERSdict and browser subset support toload()Summary
Two small, purely additive changes that give consumers explicit control over
which browsers are involved — without breaking any existing code.
BROWSERSdict — a publicname → callablemapping built from theexisting (but function-only)
all_browserslist.browsersparameter onload()— lets callers pass a subset ofbrowsers rather than being forced into all-or-one.
Motivation
1. Enumerating supported browsers is currently fragile
Downstream tools that need a name → function mapping (e.g. for CLI
choices=,input validation, or dynamic dispatch) have to introspect the module:
This silently breaks when helper functions are added. As of the current
release,
open_dbus_connectionandunpadare already false-positives.all_browsersalready exists and is exported, but it's a list of callables —you can't look up a browser by name without scanning it.
2.
load()is all-or-nothingYou can call a specific browser function directly, or use
load()for all ofthem, but there's no way to say "firefox and chrome only". This matters when:
from
BrowserCookieErrors on absent onesChanges
browser_cookie3/__init__.pyAdd
BROWSERSimmediately afterall_browsers, and add it to__all__:Update
__all__:Add an optional
browsersparameter toload():Usage examples
Programmatic enumeration
CLI integration (argparse)
Subset loading
Backwards compatibility
all_browsersis unchanged.load()with no arguments behaves identically to before.BROWSERSis a new export; nothing is removed or renamed.Notes
BROWSERSstays in sync withall_browsersautomatically — no manualmaintenance needed when a new browser is added.
browsers=raises aKeyErrorfrom the dictlookup, which is clear enough; callers doing input validation via
choices=BROWSERSwill never reach it with an invalid value anyway.isinstance(b, str)branch inload()means callers who already holda function reference (e.g.
browser_cookie3.firefox) can pass it directly,consistent with how
all_browsersworks today.