Add functions to escape/unescape the "Exec" key
Submitted by Denilson Figueiredo de Sá
Assigned to Thomas Kluyver @takluyver
Description
The Exec key has quite some rules for escaping the value. 1 Since these escaping rules are part of the specification, it would be helpful to have escaping/unescaping functions in PyXDG module.
I'm suggesting three APIs:
- Passing a string/unicode to the escaping function will return a bytestring (or unicode?).
- Passing a list or tuple or sequence to the escaping function will return a bytestring (or unicode?) of each item from the sequence correctly escaped, and concatenated by spaces. So that escape(['/bin/foo', 'bar example']) would generate a valid Exec string that calls '/bin/foo' with 'bar example' as parameter.
- Passing a string/unicode to the unescaping function will return a list of strings. So, the behavior would be the exact opposite of the escaping.
As a bonus feature, the (un)escaping could happen automatically when getting/setting the Exec key.
Footnote: in my real-world use-case, I have an absolute path that contains both spaces and unicode characters, and I need to escape this path to write a ".desktop" file that will execute that path correctly.