Wednesday, 15 December 2004
I’m thinking about whether it would be a good idea to have a media type for Python source files, call it “text/python.”
The main benefit that I see to doing this is the definition of a fragment identifier syntax; i.e., what the bit after the ‘#’ refers to. This would allow URIs to point to specific functions and classes in Python source files, which would be very useful when documenting code.
It would also allow some cool import tricks (if I read PEP 302 correctly, this is possible now, and will soon be pretty easy to enable), such as;
import "http://www.mnot.net/sw/sparta/sparta.py" as sparta
import "http://www.mnot.net/sw/sparta/sparta.py#ThingFactory" as ThingFactory
Some client-side persistent caching could make this a really nice way to distribute software, if properly thought out. It’s also one more step towards Webizing Python.
There are also some smaller, but nice, benefits, like being able to use the media type, rather than content sniffing, for syntax colouring, dispatching to Python editors straight off the Web, and being able to specify the encoding of the source in a way that’s well-aligned with the method that Python already defines.
Thoughts? I’m considering writing an Internet-Draft and/or a PEP, but wanted to get some informal feedback first.