Webext

C extension module for escape_html()
Download

Webext Ranking & Summary

Advertisement

  • Rating:
  • License:
  • MIT/X Consortium Lic...
  • Price:
  • FREE
  • Publisher Name:
  • Makoto Kuwata
  • Publisher web site:
  • http://www.kuwata-lab.com/erubis/

Webext Tags


Webext Description

C extension module for escape_html() Webext is a Python library to provide very fast 'escape_html()' function. It is implemented as C extension and it runs much faster than pure Python code such as 'cgi.escape()'.Installationtar xzf Webext-0.0.1.tar.gzcd Webext-0.0.1sudo python setup.py installFunctionsWebext provides following functions: * webext.escape_html() o escapes HTML special characters (< > & "). o converts unicode into str with 'utf8' encoding. o converts None into empty string (= ''). * webext.escape() o alias to webext.escape_html() * webext.to_str() o converts argument into str (same as str()) o converts unicode into str with 'utf8' encoding. o converts None into empty string (= ''). * webext.get_encoding() o returns default encoding for escape_html() and to_str() o default value is 'utf8' * webext.set_encoding(arg) o sets default encoding for escape_html() and to_str()Example### import escape_html() and to_str()>>> from webext import escape_html, to_str### escape_html() escapes html special characters>>> escape_html('< > & "')'< > & "'### to_str() and escape_html() convert unicode into str with 'utf8' encoding>>> to_str(u'\u65e5\u672c\u8a9e')'\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e'>>> escape_html(u'\u65e5\u672c\u8a9e')'\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e'### to_str() and escape_html() convert None into empty string### (this is more desirable than str() for web application)>>> to_str(None)''>>> escape_html(None)''Using with TenjinTenjin is a very fast template engine implemented in pure Python. You can make Tenjin much faster by using Webext.import tenjinfrom tenjin.helpers import *from webext import to_str, escape # use webext's to_str() and escape() instead of tenjin'sengine = tenjin.Engine()context = { 'items': }print engine.render('example.pyhtml', context)Tenjin's benchmark now supports Webext. The following is an example of benchmark result on Mac OS X 10.6, Intel Core Duo 2GHz, Tenjin 0.9.0. This shows that Webext boosts Tenjin especially html escaping.## without html escaping$ python bench.py -n 10000 tenjin tenjin-webextimport tenjin ... done. (0.001740 sec)import webext ... done. (0.000466 sec)*** loading context data (file=bench_context.py)...*** start benchmark*** ntimes=10000 utime stime total realtenjin 3.8100 0.0400 3.8500 3.8584tenjin-webext 2.5000 0.0300 2.5300 2.5367## with html escaping$ python bench.py -e -n 10000 tenjin tenjin-webextimport tenjin ... done. (0.001580 sec)import webext ... done. (0.000459 sec)*** loading context data (file=bench_context.py)...*** start benchmark*** ntimes=10000 utime stime total realtenjin 7.2100 0.0500 7.2600 7.2935tenjin-webext 2.9800 0.0400 3.0200 3.0476 Requirements: · Python


Webext Related Software