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('< > & "')
'< > & "'
### 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
Metadata
Release files for Webext 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| Webext-0.0.1.tar.gz | 15.1 kB | Without provenance | Details for Webext-0.0.1.tar.gz |
Release files / Webext-0.0.1.tar.gz
| Download URL | Webext-0.0.1.tar.gz |
|---|---|
| Size | 15.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6e9cdba615f2b63d789035b4b3db1209ba4a271a576a858c5c1a6a9e0808c1e8
|
|
BLAKE2b-256 checksum How to use checksums |
f284705e30745034f4f76b95fd0c5c6142d381fed945c7d97171fb9b79b9beb4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for Webext 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.