kodi-plugin-routing icon indicating copy to clipboard operation
kodi-plugin-routing copied to clipboard

Convert Values Retrieved from URLs

Open da3dsoul opened this issue 5 years ago • 9 comments

It took a bit to debug and find this. I pass False to url_for, and it give the proper result. Then in the method that gets called, I get str('False').

if 'False':
    # this is too true for False

This doesn't need to convert fancy things, but simple int, bool, and maybe float would save a lot of annoying work sanitizing a parameter that could easily be checked for param.isnumeric() or param.lower() == 'true'.

da3dsoul avatar Mar 04 '19 07:03 da3dsoul

I might just PR this myself, but if someone does it first, then cool.

da3dsoul avatar Mar 04 '19 07:03 da3dsoul

#10 implements this

da3dsoul avatar Mar 07 '19 07:03 da3dsoul

I am not a big fan of this automatic conversion. It also breaks existing uses.

dagwieers avatar Aug 31 '19 22:08 dagwieers

You need to ask it to do this. It defaults to False. I didn't do anything that would be a breaking change

da3dsoul avatar Aug 31 '19 22:08 da3dsoul

plugin = routing.Plugin('some base url', convert_args=True)

da3dsoul avatar Aug 31 '19 22:08 da3dsoul

Still no fan ;-)

dagwieers avatar Aug 31 '19 22:08 dagwieers

The argument for this is that when you use routing systems, you want it to give back what you put in. Python's type...fun...makes checking your expected types even more annoying. This simple feature saves a lot of heartache and frustration just from knowing that if you give it a number, it'll give you a number back.

da3dsoul avatar Sep 10 '19 07:09 da3dsoul

To further discuss this, as it seems at least @dagwieers doesn't like it, I'm thinking that optional strict typing in the URL may be a solution.

Similar to how we have paths, essentially, you apply a modifier to enforce both matching a specific type and automatically converting back to the desired type. This will allow simple types, such as int, float, etc, but also models to be serialized and deserialized. I wouldn't suggest anything more complicated than

{ "Name": "Dave", "Dead":True }

but it could help with passing simple models without a lot of effort trying to convert back and forth, as mentioned in #7

da3dsoul avatar Jan 11 '20 17:01 da3dsoul

With object persistence, theoretically it could build a small cache, then the Object is saved to the cache and referenced by a one-time ID to be retrieved on the next call. This method wouldn't work for communication with a script, which is another issue, but it could allow for much cleaner URLs while allowing more automagical persistence for devs that depend on this project. That in itself may be beyond the scope of this project, as well, though.

da3dsoul avatar Jan 11 '20 17:01 da3dsoul