Tornado – Escape – URLs


Like that for JSON strings, Tornado also provides methods for escaping and unescaping URLs. Not just that, it also exports some methods to play with URLs.

Let’s see the behavior with the example below

1. tornado.escape.linkify(text) – creates a link for provided text

2. tornado.escape.linkify(text, shorten=Tue) – creates a link and shortens the URL

3. tornado.escape.linkify(text, require_protocol=True) – creates a link only if it includes a protocol like http or https or ftp

4. tornado.escape.linkify(text, permitted_protocols=[]) – creates a link only if URL belongs to permitted protocols list

5. tornado.escape.squeeze(value) – Removes all white spaces and replaces it with one white space

6. tornado.escape.url_escape(value) – Encodes the URL

7. tornado.escape.url_unescape(value,encoding=”) – Decodes given value from URL based on provided encoding

Output

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s