Python 3.2 and html.escape function

G

Gerald Britton

I see that Python 3.2 includes a new module -- html -- with a single
function -- escape. I would like to know how this function differs
from xml.sax.saxutils.escape and, if there is no difference (or only a
minor one), what the need is for this new module and its lone function
 
S

Steven D'Aprano

I see that Python 3.2 includes a new module -- html -- with a single
function -- escape. I would like to know how this function differs from
xml.sax.saxutils.escape and, if there is no difference (or only a minor
one), what the need is for this new module and its lone function

Unless the html API has changed radically since Python 3.2a, I believe
you are mistaken.

[steve@sylar ~]$ python3.2
Python 3.2a1 (r32a1:83318, Aug 12 2010, 02:17:22)
[GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
which gives me the following information:



Help on package html:

NAME
html - # This directory is a Python package.

FILE
/usr/local/lib/python3.2/html/__init__.py

MODULE DOCS
http://docs.python.org/library/html

PACKAGE CONTENTS
entities
parser



So html is not a module, but a package that includes two sub-modules,
entities and parser. I see no sign of anything called "escape" in either
the top level html package, or either of the sub-modules, and the word
"escape" only appears twice in the whole package, both times as
"unescape":


[steve@sylar ~]$ cd /usr/local/lib/python3.2/html/
[steve@sylar html]$ ls
entities.py __init__.py parser.py __pycache__
[steve@sylar html]$ grep -i escape *.py
parser.py: attrvalue = self.unescape(attrvalue)
parser.py: def unescape(self, s):


So I don't know what you are looking at, but I don't believe it is the
standard html package in the Python standard library. Perhaps you have
accidentally shadowed it with your own html module? Try this:
'/usr/local/lib/python3.2/html/__init__.py'
 
P

Peter Otten

Steven said:
Unless the html API has changed radically since Python 3.2a, I believe
you are mistaken.

Adding a function is not /that/ radical, and it has happened, see

http://docs.python.org/dev/py3k/library/html.html

The check-in message that is linked there claims that html.escape() is
supposed to replace cgi.escape()

Side note: there has been a discussion whether it's a good idea to put a
function into a package, see

http://mail.python.org/pipermail/python-dev/2011-January/107635.html
 
R

Rafe Kettler

I see that Python 3.2 includes a new module -- html -- with a single
function -- escape.  I would like to know how this function differs
from xml.sax.saxutils.escape and, if there is no difference (or only a
minor one), what the need is for this new module and its lone function

I believe that they're trying to organize a new top-level package
called html that will, at some point, contain all HTML functionality.
It's sort of similar to what they're doing with the concurrent package.
 
M

Martin v. Loewis

Well, I just learned something, thank you. I was under the mistaken
impression that adding new functionality after the first alpha release
was not permitted by the Python devs.

It's the first beta release after which no new functionality could be added.

Regards,
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top