5.3.3 draco.encode -- Common encodings

The module draco.encode defines a few string encodings that can be very helpful to to web developers. They are made available through the standard Python encodings framework. The following encodings are defined:

url
Url encoding. A string encoded with this encoding is suitable to be used in an url. Illegal and unsafe characters are expanded to "%xx" hexadecimal escape codes.

form
Form encoding. A string encoded with this encoding can be used as a GET style argument in an url. This encoding is the same as the url encoding, but in addition spaces are converted to plus (+) signs.

html
Html encoding. The characters <, > and & are replaced by their sgml entities (&lt;, &gt; and &amp; respectively). This encoding should be used when you are printing inside html.

attr
Html attribute encoding. This is same as the html encoding, but the double quote (") is replaced by &dquot;

The encodings are registered when this module is imported. Draco does this automatically when it starts up so you don't need to bother with this.

A fragment from a template which illustrates the html encoding:

<p> The status is: <%= status.encode('html') %>