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

Missing scheme #14

Closed
prochac opened this issue Jul 27, 2020 · 3 comments
Closed

Missing scheme #14

prochac opened this issue Jul 27, 2020 · 3 comments

Comments

@prochac
Copy link

prochac commented Jul 27, 2020

Can't register another scheme without pull request
example: amqp:// and amqps://
really painful

@amcgregor
Copy link
Member

amcgregor commented Aug 1, 2020

You absolutely can, reference, using entry_points plugin discovery. Edited to add: though a PR to add such to the core library would be appreciated for HTTP-like ("URL") URI in common usage, especially if reference to the specification defining it can be provided. (Docstrings are great, and on GitHub creating a fork and issuing a PR from viewing a file you want changed is essentially three clicks and some typing.) Apologies for all the edits, apparently I'm retentive.

@prochac
Copy link
Author

prochac commented Aug 1, 2020

Thank, I learned more about Python. I found the schemas in the setup.py but didn't know how to edit during runtime.

@amcgregor
Copy link
Member

amcgregor commented Aug 1, 2020

… but didn't know how to edit during runtime.

Ah! That's generally not the best way to do this, as it can represent an "import time side-effect" (ref: common mistakes; same content from a possibly non-Medium-powered, but rather ugly site).

However, AL/№ 36: practicality beats purity. It's possible, but requires modifying an object within the URI package dynamically at runtime. This is the code that would provide the desired change:

from uri.scheme import URLScheme
from uri.part.scheme import SchemePart

SchemePart.registry['amqp'] = URLScheme('amqp')
SchemePart.registry['amqps'] = URLScheme('amqps')

The seeming duplication is due to the fact the generic URLScheme formatter needs to know what it is representing, and the registry itself needs to be able to look up this formatter by string name. Using entry_points plugins this is automated away. (The registry here is a cache or short-circuit, saving the need for repeated iterative querying of Python package metadata to go looking for plugins and instantiation of such on every use. Essentially a pool of singletons.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants