Open dmajda opened 6 years ago
URL('mqtt://whatever')
works.
The port is None
but you can replace it with your desired default on, say, creating a connection.
I'm open to extending DEFAULT_PORTS
though if there is an official document which states that scheme X corresponds to port N by default.
cat /etc/services
URL('mqtt://whatever')
works. The port isNone
but you can replace it with your desired default on, say, creating a connection.
I know, but it’s a mild annoyance. We have multiple services communicating over MQTT, which means we have to do this repeatedly in our codebase. (Or we could build a wrapper that would do that automatically, but it’s easy to forget one has to use it.)
Now we have cache_*
functions set that modifies the library's global state.
We can support something similar for default ports.
Please feel free to provide a pull request.
@asvetlov I'm planning on submitting a PR for this to add a few more defaults (eg, postgresql, amqp, etc). Do you have a preference on function names to manipulate the default URI schemes?
We are using YARL with
mqtt:
andmqtts:
URLs, for which default ports are not substituted. This means we have to do the substitution manually in our code. This is fragile and easy to forget.One possibility is to just add substitutions for these schemes (and possibly other common schemes) to YARL directly. This would be straightforward, but I can imagine it could also be a maintenance headache.
Another way would be allowing to extend the list of substitutions as part of the public API. That would allow anyone to add substitutions they need. Right now, this can already be done by modifying
yarl.DEFAULT_PORTS
, but this way is not documented and it also acts globally, meaning it would be bad e.g. for a library which uses YARL internally to do this. A parameter used when creating a URL would probably be a nicer solution.