This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!
Project Description

Webext is a 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()’.

Installation

$ tar xzf Webext-0.0.1.tar.gz
$ cd Webext-0.0.1
$ sudo python setup.py install

Functions

Webext provides following functions:

  • webext.escape_html()
    • escapes HTML special characters (< > & “).
    • converts unicode into str with ‘utf8’ encoding.
    • converts None into empty string (= ”).
  • webext.escape()
    • alias to webext.escape_html()
  • webext.to_str()
    • converts argument into str (same as str())
    • converts unicode into str with ‘utf8’ encoding.
    • converts None into empty string (= ”).
  • webext.get_encoding()
    • returns default encoding for escape_html() and to_str()
    • default value is ‘utf8’
  • webext.set_encoding(arg)
    • 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('< > & "')
'&lt; &gt; &amp; &quot;'

### 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 Tenjin

Tenjin is a very fast template engine implemented in pure Python. You can make Tenjin much faster by using Webext.

import tenjin
from tenjin.helpers import *
from webext import to_str, escape    # use webext's to_str() and escape() instead of tenjin's
engine = tenjin.Engine()
context = { 'items': ['<AAA>', 'B&B', '"CCC"'] }
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-
webext
import 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      real
tenjin                             3.8100    0.0400    3.8500    3.8584
tenjin-webext                      2.5000    0.0300    2.5300    2.5367

## with html escaping
$ python bench.py -e -n 10000 tenjin tenj
in-webext
import 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      real
tenjin                             7.2100    0.0500    7.2600    7.2935
tenjin-webext                      2.9800    0.0400    3.0200    3.0476
Release History

Release History

0.0.1

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
Webext-0.0.1.tar.gz (15.1 kB) Copy SHA256 Checksum SHA256 Source Jul 19, 2010

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting